adopting strings correctly again, yikers

This commit is contained in:
jenzur 2019-03-10 19:19:33 +01:00
parent 7ab6c7ee0b
commit 43da2dd5d5

View File

@ -51,7 +51,7 @@ import java.util.logging.Logger;
*/
public class MYSQLDatahandler {
public static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(10, TimeUnit.MINUTES);
public static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(6, TimeUnit.MINUTES);
public static final long EXPIRE_TIME_IN_SECONDS1 = TimeUnit.SECONDS.convert(10, TimeUnit.HOURS);
public static MYSQLDatahandler instance = new MYSQLDatahandler();
private volatile boolean refreshMatrixFromDB;
@ -202,20 +202,21 @@ public class MYSQLDatahandler {
}
if (selectUpdate == -1 || selectUpdate + 1 == stringCachelocal.size()) {
int valueSize = stringCachelocal.size();
if (secondaryIterator >= valueSize) {
if (secondaryIterator + 1 >= valueSize) {
secondaryIterator = 0;
}
selectUpdate = secondaryIterator;
secondaryIterator++;
}
int beginindex = selectUpdate;
System.out.println("beginindex: " + beginindex + "\n");
ConcurrentMap<Integer, String> strIndexNavigator = new MapMaker().concurrencyLevel(2).makeMap();
String get = stringCachelocal.get(beginindex);
String get = stringCachelocal.getOrDefault(beginindex, null);
if (get == null) {
get = stringCachelocal.get(new Random().nextInt(stringCachelocal.size() - 1));
}
strIndexNavigator.put(0, get);
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
ConcurrentMap<Integer, ConcurrentMap<String, String>> strMap = new MapMaker().concurrencyLevel(2).makeMap();
strIndexNavigator.values().forEach((str) -> {
stringCachelocal.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
boolean present = false;
@ -237,27 +238,16 @@ public class MYSQLDatahandler {
}
}
}
if (!present) {
for (ConcurrentMap<String, String> strconcuritr : strMap.values()) {
String orDefault1 = strconcuritr.getOrDefault(str, null);
if (orDefault1 != null && orDefault1.equals(str1)) {
present = true;
break;
}
orDefault1 = strconcuritr.getOrDefault(str1, null);
if (orDefault1 != null && orDefault1.equals(str)) {
present = true;
break;
}
}
}
if (!present) {
SimilarityMatrix SMX = new SimilarityMatrix(str, str1);
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, SMX);
futures.put(futures.size() + 1, executor.submit(worker));
ConcurrentMap<String, String> strmapLocal = new MapMaker().concurrencyLevel(2).makeMap();
strmapLocal.put(str, str1);
strMap.put(strMap.size() + 1, strmapLocal);
LinkedHashMap<String, Double> orDefault1 = LHMSMXLocal.getOrDefault(str, null);
if (orDefault1 == null) {
orDefault1 = new LinkedHashMap<String, Double>();
}
orDefault1.put(str1, 0.0);
LHMSMXLocal.put(str, orDefault1);
}
});
});
@ -265,18 +255,19 @@ public class MYSQLDatahandler {
for (Future<SimilarityMatrix> future : futures.values()) {
System.out.println("counter: " + counter + "\n");
counter++;
SimilarityMatrix SMX = new SimilarityMatrix("", "");
try {
SimilarityMatrix SMX = future.get(20, TimeUnit.SECONDS);
SMX = future.get(20, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
Logger.getLogger(MYSQLDatahandler.class.getName()).log(Level.SEVERE, null, ex);
}
LinkedHashMap<String, Double> getFuture = lHMSMX.getOrDefault(SMX.getPrimaryString(), null);
if (getFuture == null) {
getFuture = new LinkedHashMap();
getFuture = new LinkedHashMap<String, Double>();
}
getFuture.put(SMX.getSecondaryString(), SMX.getDistance());
lHMSMX.put(SMX.getPrimaryString(), getFuture);
matrixUpdateList.put(matrixUpdateList.size() + 1, SMX);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
Logger.getLogger(MYSQLDatahandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
try {
if (!matrixUpdateList.isEmpty()) {
@ -603,10 +594,7 @@ public class MYSQLDatahandler {
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;
}
int intervalAprove = 450;
int intervalAprove = allStrings.values().size() / 10;
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";
@ -619,14 +607,15 @@ public class MYSQLDatahandler {
worker = new SentimentAnalyzerTest(str, str3, new SimilarityMatrix(str, str3));
futures.put(futures.size() + 1, executor.submit(worker));
int ij2 = 0;
if (allStrings.isEmpty()) {
allStrings = strmap;
}
for (String strValues : allStrings.values()) {
if (ij2 > intervalAprove) {
break;
}
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));
}
ij2++;
}
int counter = 0;
@ -635,7 +624,7 @@ public class MYSQLDatahandler {
try {
future.get(20, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
//System.out.println("counter timeouts: " + counter + "\n");
System.out.println("counter timeouts: " + counter + "\n");
counter++;
if (counter >= 10) {
calculationIssues = true;