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.CustomError;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -50,8 +51,8 @@ public class DataMapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getAllStrings() throws CustomError {
|
||||
List<String> str = new ArrayList();
|
||||
public static ConcurrentMap<Integer, String> getAllStrings() throws CustomError {
|
||||
ConcurrentMap<Integer, String> allStrings = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
@ -62,15 +63,17 @@ public class DataMapper {
|
||||
java.sql.ResultSet.CONCUR_READ_ONLY);
|
||||
l_pStatement.setFetchSize(Integer.MIN_VALUE);
|
||||
l_rsSearch = l_pStatement.executeQuery();
|
||||
int ij = 0;
|
||||
while (l_rsSearch.next()) {
|
||||
str.add(l_rsSearch.getString(1));
|
||||
allStrings.put(ij, l_rsSearch.getString(1));
|
||||
ij++;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
return str;
|
||||
return allStrings;
|
||||
}
|
||||
|
||||
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 {
|
||||
List<String> strlist;
|
||||
strlist = DataMapper.getAllStrings();
|
||||
LinkedHashMap<Integer, String> LHM = new LinkedHashMap();
|
||||
int i = 0;
|
||||
for (String str : strlist) {
|
||||
LHM.put(i, str);
|
||||
i++;
|
||||
}
|
||||
return LHM;
|
||||
return DataMapper.getAllStrings();
|
||||
}
|
||||
|
||||
public int getlHMSMXSize() {
|
||||
@ -288,9 +280,9 @@ public class MYSQLDatahandler {
|
||||
str = cutContent(str);
|
||||
str = filterContent(str);
|
||||
str = removeSlacks(str);
|
||||
str = verifyCalculationFitness(str);
|
||||
try {
|
||||
DataMapper.InsertMYSQLStrings(str);
|
||||
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(MYSQLDatahandler.class
|
||||
.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -497,6 +489,15 @@ public class MYSQLDatahandler {
|
||||
if (str1.contains("{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();
|
||||
if (str1.length() > 2 && (!str1.startsWith("!"))) {
|
||||
strlistreturn.put(strlistreturn.size() + 1, str1);
|
||||
@ -571,4 +572,59 @@ public class MYSQLDatahandler {
|
||||
}
|
||||
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,9 +45,11 @@ public class DiscordHandler {
|
||||
}).start();
|
||||
MYSQLDatahandler.shiftReduceParserInitiate();
|
||||
MYSQLDatahandler.instance.instantiateExecutor();
|
||||
while (MYSQLDatahandler.instance.getlHMSMXSize() / 2 < (MYSQLDatahandler.instance.getstringCacheSize()
|
||||
* MYSQLDatahandler.instance.getstringCacheSize()) - MYSQLDatahandler.instance.getstringCacheSize()) {
|
||||
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
||||
if (MYSQLDatahandler.instance.getlHMSMXSize() != 0 && MYSQLDatahandler.instance.getstringCacheSize() != 0) {
|
||||
while (MYSQLDatahandler.instance.getlHMSMXSize() / 2 < (MYSQLDatahandler.instance.getstringCacheSize()
|
||||
* MYSQLDatahandler.instance.getstringCacheSize()) - MYSQLDatahandler.instance.getstringCacheSize()) {
|
||||
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
||||
}
|
||||
}
|
||||
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
@ -84,14 +86,14 @@ public class DiscordHandler {
|
||||
}
|
||||
}
|
||||
MessageResponseHandler.getMessage(strresult);
|
||||
try {
|
||||
MYSQLDatahandler.instance.checkIfUpdateStrings();
|
||||
new Thread(() -> {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
MYSQLDatahandler.instance.checkIfUpdateStrings();
|
||||
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
||||
}).start();
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
if (event.getMessage().getMentionedUsers().contains(api.getYourself())
|
||||
|| event.getServerTextChannel().get().toString().contains("minor-test")) {
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user