adding calculation prequirements for accepting strings
This commit is contained in:
parent
05683ce4be
commit
66dae4e113
@ -7,6 +7,7 @@ package DataLayer;
|
|||||||
|
|
||||||
import FunctionLayer.SimilarityMatrix;
|
import FunctionLayer.SimilarityMatrix;
|
||||||
import FunctionLayer.CustomError;
|
import FunctionLayer.CustomError;
|
||||||
|
import com.google.common.collect.MapMaker;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -50,8 +51,8 @@ public class DataMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getAllStrings() throws CustomError {
|
public static ConcurrentMap<Integer, String> getAllStrings() throws CustomError {
|
||||||
List<String> str = new ArrayList();
|
ConcurrentMap<Integer, String> allStrings = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
Connection l_cCon = null;
|
Connection l_cCon = null;
|
||||||
PreparedStatement l_pStatement = null;
|
PreparedStatement l_pStatement = null;
|
||||||
ResultSet l_rsSearch = null;
|
ResultSet l_rsSearch = null;
|
||||||
@ -62,15 +63,17 @@ public class DataMapper {
|
|||||||
java.sql.ResultSet.CONCUR_READ_ONLY);
|
java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||||
l_pStatement.setFetchSize(Integer.MIN_VALUE);
|
l_pStatement.setFetchSize(Integer.MIN_VALUE);
|
||||||
l_rsSearch = l_pStatement.executeQuery();
|
l_rsSearch = l_pStatement.executeQuery();
|
||||||
|
int ij = 0;
|
||||||
while (l_rsSearch.next()) {
|
while (l_rsSearch.next()) {
|
||||||
str.add(l_rsSearch.getString(1));
|
allStrings.put(ij, l_rsSearch.getString(1));
|
||||||
|
ij++;
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||||
}
|
}
|
||||||
return str;
|
return allStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void InsertMYSQLStrings(ConcurrentMap<Integer, String> str) throws CustomError {
|
public static void InsertMYSQLStrings(ConcurrentMap<Integer, String> str) throws CustomError {
|
||||||
|
@ -152,15 +152,7 @@ public class MYSQLDatahandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Integer, String> getCache() throws SQLException, IOException, CustomError {
|
private Map<Integer, String> getCache() throws SQLException, IOException, CustomError {
|
||||||
List<String> strlist;
|
return DataMapper.getAllStrings();
|
||||||
strlist = DataMapper.getAllStrings();
|
|
||||||
LinkedHashMap<Integer, String> LHM = new LinkedHashMap();
|
|
||||||
int i = 0;
|
|
||||||
for (String str : strlist) {
|
|
||||||
LHM.put(i, str);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return LHM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getlHMSMXSize() {
|
public int getlHMSMXSize() {
|
||||||
@ -288,9 +280,9 @@ public class MYSQLDatahandler {
|
|||||||
str = cutContent(str);
|
str = cutContent(str);
|
||||||
str = filterContent(str);
|
str = filterContent(str);
|
||||||
str = removeSlacks(str);
|
str = removeSlacks(str);
|
||||||
|
str = verifyCalculationFitness(str);
|
||||||
try {
|
try {
|
||||||
DataMapper.InsertMYSQLStrings(str);
|
DataMapper.InsertMYSQLStrings(str);
|
||||||
|
|
||||||
} catch (CustomError ex) {
|
} catch (CustomError ex) {
|
||||||
Logger.getLogger(MYSQLDatahandler.class
|
Logger.getLogger(MYSQLDatahandler.class
|
||||||
.getName()).log(Level.SEVERE, null, ex);
|
.getName()).log(Level.SEVERE, null, ex);
|
||||||
@ -497,6 +489,15 @@ public class MYSQLDatahandler {
|
|||||||
if (str1.contains("{orangered}")) {
|
if (str1.contains("{orangered}")) {
|
||||||
str1 = str1.replace("{orangered}", " ");
|
str1 = str1.replace("{orangered}", " ");
|
||||||
}
|
}
|
||||||
|
if (str1.contains("{darkorchid}")) {
|
||||||
|
str1 = str1.replace("{darkorchid}", " ");
|
||||||
|
}
|
||||||
|
if (str1.contains("{pink}")) {
|
||||||
|
str1 = str1.replace("{pink}", " ");
|
||||||
|
}
|
||||||
|
if (str1.contains("{lightyellow}")) {
|
||||||
|
str1 = str1.replace("{lightyellow}", " ");
|
||||||
|
}
|
||||||
str1 = str1.trim();
|
str1 = str1.trim();
|
||||||
if (str1.length() > 2 && (!str1.startsWith("!"))) {
|
if (str1.length() > 2 && (!str1.startsWith("!"))) {
|
||||||
strlistreturn.put(strlistreturn.size() + 1, str1);
|
strlistreturn.put(strlistreturn.size() + 1, str1);
|
||||||
@ -571,4 +572,59 @@ public class MYSQLDatahandler {
|
|||||||
}
|
}
|
||||||
return strreturn;
|
return strreturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ConcurrentMap<Integer, String> verifyCalculationFitness(ConcurrentMap<Integer, String> strmap) {
|
||||||
|
ConcurrentMap<Integer, String> returnmap = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
|
ConcurrentMap<Integer, String> allStrings = stringCache;
|
||||||
|
if (allStrings.isEmpty()) {
|
||||||
|
return strmap;
|
||||||
|
}
|
||||||
|
ConcurrentMap<Integer, String> intervalMap = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
|
int hardcap = allStrings.size() > 450 ? 450 : allStrings.size();
|
||||||
|
int intvervalAprove = allStrings.size() > hardcap ? allStrings.size() - hardcap : allStrings.size();
|
||||||
|
int intervalAproveRand = new Random().nextInt(intvervalAprove);
|
||||||
|
int ij = 0;
|
||||||
|
while (ij < hardcap) {
|
||||||
|
intervalMap.put(ij, allStrings.get(intervalAproveRand + ij));
|
||||||
|
ij++;
|
||||||
|
}
|
||||||
|
String str1 = "and to revise the questions and materials and such";
|
||||||
|
String str2 = "as William said earlier. Visiting your dentist once or twice a year is enough";
|
||||||
|
String str3 = "At least, you have more time to prepare then";
|
||||||
|
for (String str : strmap.values()) {
|
||||||
|
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
|
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, new SimilarityMatrix(str, str1));
|
||||||
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
|
worker = new SentimentAnalyzerTest(str, str2, new SimilarityMatrix(str, str2));
|
||||||
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
|
worker = new SentimentAnalyzerTest(str, str3, new SimilarityMatrix(str, str3));
|
||||||
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
|
for (String strValues : intervalMap.values()) {
|
||||||
|
if (!strValues.equals(str1) && !strValues.equals(str2) && !strValues.equals(str3)) {
|
||||||
|
worker = new SentimentAnalyzerTest(str, strValues, new SimilarityMatrix(str, strValues));
|
||||||
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int counter = 0;
|
||||||
|
int ijCounter = 0;
|
||||||
|
boolean calculationIssues = false;
|
||||||
|
for (Future<SimilarityMatrix> future : futures.values()) {
|
||||||
|
System.out.println("futures size: " + futures.size() + "\nijCounter: " + ijCounter + "\n");
|
||||||
|
try {
|
||||||
|
future.get(20, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
|
||||||
|
System.out.println("counter: " + counter + "\n");
|
||||||
|
counter++;
|
||||||
|
if (counter >= 10) {
|
||||||
|
calculationIssues = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!calculationIssues) {
|
||||||
|
returnmap.put(returnmap.size() + 1, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,12 @@ public class DiscordHandler {
|
|||||||
}).start();
|
}).start();
|
||||||
MYSQLDatahandler.shiftReduceParserInitiate();
|
MYSQLDatahandler.shiftReduceParserInitiate();
|
||||||
MYSQLDatahandler.instance.instantiateExecutor();
|
MYSQLDatahandler.instance.instantiateExecutor();
|
||||||
|
if (MYSQLDatahandler.instance.getlHMSMXSize() != 0 && MYSQLDatahandler.instance.getstringCacheSize() != 0) {
|
||||||
while (MYSQLDatahandler.instance.getlHMSMXSize() / 2 < (MYSQLDatahandler.instance.getstringCacheSize()
|
while (MYSQLDatahandler.instance.getlHMSMXSize() / 2 < (MYSQLDatahandler.instance.getstringCacheSize()
|
||||||
* MYSQLDatahandler.instance.getstringCacheSize()) - MYSQLDatahandler.instance.getstringCacheSize()) {
|
* MYSQLDatahandler.instance.getstringCacheSize()) - MYSQLDatahandler.instance.getstringCacheSize()) {
|
||||||
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||||
api.addMessageCreateListener(event -> {
|
api.addMessageCreateListener(event -> {
|
||||||
@ -84,14 +86,14 @@ public class DiscordHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MessageResponseHandler.getMessage(strresult);
|
MessageResponseHandler.getMessage(strresult);
|
||||||
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
MYSQLDatahandler.instance.checkIfUpdateStrings();
|
MYSQLDatahandler.instance.checkIfUpdateStrings();
|
||||||
new Thread(() -> {
|
|
||||||
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
||||||
}).start();
|
|
||||||
} catch (CustomError ex) {
|
} catch (CustomError ex) {
|
||||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
if (event.getMessage().getMentionedUsers().contains(api.getYourself())
|
if (event.getMessage().getMentionedUsers().contains(api.getYourself())
|
||||||
|| event.getServerTextChannel().get().toString().contains("minor-test")) {
|
|| event.getServerTextChannel().get().toString().contains("minor-test")) {
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user