adopting strings correctly again, yikers
This commit is contained in:
parent
7ab6c7ee0b
commit
43da2dd5d5
@ -51,7 +51,7 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class MYSQLDatahandler {
|
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 final long EXPIRE_TIME_IN_SECONDS1 = TimeUnit.SECONDS.convert(10, TimeUnit.HOURS);
|
||||||
public static MYSQLDatahandler instance = new MYSQLDatahandler();
|
public static MYSQLDatahandler instance = new MYSQLDatahandler();
|
||||||
private volatile boolean refreshMatrixFromDB;
|
private volatile boolean refreshMatrixFromDB;
|
||||||
@ -202,20 +202,21 @@ public class MYSQLDatahandler {
|
|||||||
}
|
}
|
||||||
if (selectUpdate == -1 || selectUpdate + 1 == stringCachelocal.size()) {
|
if (selectUpdate == -1 || selectUpdate + 1 == stringCachelocal.size()) {
|
||||||
int valueSize = stringCachelocal.size();
|
int valueSize = stringCachelocal.size();
|
||||||
if (secondaryIterator >= valueSize) {
|
if (secondaryIterator + 1 >= valueSize) {
|
||||||
secondaryIterator = 0;
|
secondaryIterator = 0;
|
||||||
}
|
}
|
||||||
selectUpdate = secondaryIterator;
|
selectUpdate = secondaryIterator;
|
||||||
secondaryIterator++;
|
secondaryIterator++;
|
||||||
}
|
}
|
||||||
int beginindex = selectUpdate;
|
int beginindex = selectUpdate;
|
||||||
System.out.println("beginindex: " + beginindex + "\n");
|
|
||||||
ConcurrentMap<Integer, String> strIndexNavigator = new MapMaker().concurrencyLevel(2).makeMap();
|
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);
|
strIndexNavigator.put(0, get);
|
||||||
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = 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) -> {
|
strIndexNavigator.values().forEach((str) -> {
|
||||||
stringCachelocal.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
|
stringCachelocal.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
|
||||||
boolean present = false;
|
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) {
|
if (!present) {
|
||||||
SimilarityMatrix SMX = new SimilarityMatrix(str, str1);
|
SimilarityMatrix SMX = new SimilarityMatrix(str, str1);
|
||||||
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, SMX);
|
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, SMX);
|
||||||
futures.put(futures.size() + 1, executor.submit(worker));
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
ConcurrentMap<String, String> strmapLocal = new MapMaker().concurrencyLevel(2).makeMap();
|
LinkedHashMap<String, Double> orDefault1 = LHMSMXLocal.getOrDefault(str, null);
|
||||||
strmapLocal.put(str, str1);
|
if (orDefault1 == null) {
|
||||||
strMap.put(strMap.size() + 1, strmapLocal);
|
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()) {
|
for (Future<SimilarityMatrix> future : futures.values()) {
|
||||||
System.out.println("counter: " + counter + "\n");
|
System.out.println("counter: " + counter + "\n");
|
||||||
counter++;
|
counter++;
|
||||||
|
SimilarityMatrix SMX = new SimilarityMatrix("", "");
|
||||||
try {
|
try {
|
||||||
SimilarityMatrix SMX = future.get(20, TimeUnit.SECONDS);
|
SMX = future.get(20, TimeUnit.SECONDS);
|
||||||
LinkedHashMap<String, Double> getFuture = lHMSMX.getOrDefault(SMX.getPrimaryString(), null);
|
|
||||||
if (getFuture == null) {
|
|
||||||
getFuture = new LinkedHashMap();
|
|
||||||
}
|
|
||||||
getFuture.put(SMX.getSecondaryString(), SMX.getDistance());
|
|
||||||
lHMSMX.put(SMX.getPrimaryString(), getFuture);
|
|
||||||
matrixUpdateList.put(matrixUpdateList.size() + 1, SMX);
|
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
|
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
|
||||||
Logger.getLogger(MYSQLDatahandler.class.getName()).log(Level.SEVERE, null, 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<String, Double>();
|
||||||
|
}
|
||||||
|
getFuture.put(SMX.getSecondaryString(), SMX.getDistance());
|
||||||
|
lHMSMX.put(SMX.getPrimaryString(), getFuture);
|
||||||
|
matrixUpdateList.put(matrixUpdateList.size() + 1, SMX);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!matrixUpdateList.isEmpty()) {
|
if (!matrixUpdateList.isEmpty()) {
|
||||||
@ -603,10 +594,7 @@ public class MYSQLDatahandler {
|
|||||||
private ConcurrentMap<Integer, String> verifyCalculationFitness(ConcurrentMap<Integer, String> strmap) {
|
private ConcurrentMap<Integer, String> verifyCalculationFitness(ConcurrentMap<Integer, String> strmap) {
|
||||||
ConcurrentMap<Integer, String> returnmap = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, String> returnmap = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ConcurrentMap<Integer, String> allStrings = stringCache;
|
ConcurrentMap<Integer, String> allStrings = stringCache;
|
||||||
if (allStrings.isEmpty()) {
|
int intervalAprove = allStrings.values().size() / 10;
|
||||||
return strmap;
|
|
||||||
}
|
|
||||||
int intervalAprove = 450;
|
|
||||||
String str1 = "and to revise the questions and materials and such";
|
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 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";
|
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));
|
worker = new SentimentAnalyzerTest(str, str3, new SimilarityMatrix(str, str3));
|
||||||
futures.put(futures.size() + 1, executor.submit(worker));
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
int ij2 = 0;
|
int ij2 = 0;
|
||||||
|
if (allStrings.isEmpty()) {
|
||||||
|
allStrings = strmap;
|
||||||
|
}
|
||||||
for (String strValues : allStrings.values()) {
|
for (String strValues : allStrings.values()) {
|
||||||
if (ij2 > intervalAprove) {
|
if (ij2 > intervalAprove) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!strValues.equals(str1) && !strValues.equals(str2) && !strValues.equals(str3)) {
|
worker = new SentimentAnalyzerTest(str, strValues, new SimilarityMatrix(str, strValues));
|
||||||
worker = new SentimentAnalyzerTest(str, strValues, new SimilarityMatrix(str, strValues));
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
futures.put(futures.size() + 1, executor.submit(worker));
|
|
||||||
}
|
|
||||||
ij2++;
|
ij2++;
|
||||||
}
|
}
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
@ -635,7 +624,7 @@ public class MYSQLDatahandler {
|
|||||||
try {
|
try {
|
||||||
future.get(20, TimeUnit.SECONDS);
|
future.get(20, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
|
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
|
||||||
//System.out.println("counter timeouts: " + counter + "\n");
|
System.out.println("counter timeouts: " + counter + "\n");
|
||||||
counter++;
|
counter++;
|
||||||
if (counter >= 10) {
|
if (counter >= 10) {
|
||||||
calculationIssues = true;
|
calculationIssues = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user