adding calculation prequirements for accepting strings

This commit is contained in:
jenzur
2019-03-07 18:39:40 +01:00
parent 05683ce4be
commit 66dae4e113
4 changed files with 85 additions and 24 deletions
@@ -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;
}
}