|
|
|
@@ -67,8 +67,7 @@ public class Datahandler {
|
|
|
|
|
private static Annotation strAnnoSentiment;
|
|
|
|
|
private static Annotation strAnnoJMWE;
|
|
|
|
|
private static CoreDocument coreDoc;
|
|
|
|
|
private static final ConcurrentMap<Integer, String> stringCache = new MapMaker().concurrencyLevel(2).makeMap();
|
|
|
|
|
private static int RelationCounter = 0;
|
|
|
|
|
private static final ConcurrentMap<Integer, String> stringCache = new MapMaker().concurrencyLevel(6).makeMap();
|
|
|
|
|
private static ConcurrentMap<String, Annotation> pipelineAnnotationCache;
|
|
|
|
|
private static ConcurrentMap<String, Annotation> pipelineSentimentAnnotationCache;
|
|
|
|
|
private static ConcurrentMap<String, Annotation> jmweAnnotationCache;
|
|
|
|
@@ -221,7 +220,7 @@ public class Datahandler {
|
|
|
|
|
hlStatsMessages.put(str, hlStatsMessages.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int capacity = 500;
|
|
|
|
|
int capacity = 1250;
|
|
|
|
|
hlStatsMessages.keySet().forEach(str -> {
|
|
|
|
|
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
|
|
|
|
|
String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null);
|
|
|
|
@@ -271,29 +270,16 @@ public class Datahandler {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ConcurrentMap<Integer, String> futuresReturnOverallEvaluation(List<SimilarityMatrix> similarityMatrixes,
|
|
|
|
|
ConcurrentMap<Integer, String> strmapreturn) {
|
|
|
|
|
private ConcurrentMap<Integer, String> futuresReturnOverallEvaluation(List<SimilarityMatrix> similarityMatrixes) {
|
|
|
|
|
ConcurrentMap<Integer, String> strmapreturn = new MapMaker().concurrencyLevel(6).makeMap();
|
|
|
|
|
if (!similarityMatrixes.isEmpty()) {
|
|
|
|
|
String newPrimary = similarityMatrixes.get(0).getPrimaryString();
|
|
|
|
|
int evaluationCap = 50000;
|
|
|
|
|
boolean hitCap = false;
|
|
|
|
|
int evaluationCap = 500;
|
|
|
|
|
int iterator = 0;
|
|
|
|
|
for (SimilarityMatrix SMX : similarityMatrixes) {
|
|
|
|
|
if (!newPrimary.equals(SMX.getPrimaryString())) {
|
|
|
|
|
newPrimary = SMX.getPrimaryString();
|
|
|
|
|
final Double scoreRelationNewMsgToRecentMsg = SMX.getDistance();
|
|
|
|
|
if (scoreRelationNewMsgToRecentMsg > evaluationCap) {
|
|
|
|
|
strmapreturn = addSMXToMapReturn(strmapreturn, SMX);
|
|
|
|
|
hitCap = false;
|
|
|
|
|
}
|
|
|
|
|
if (!hitCap) {
|
|
|
|
|
final Double scoreRelationNewMsgToRecentMsg = SMX.getDistance();
|
|
|
|
|
RelationCounter += scoreRelationNewMsgToRecentMsg > 500 ? scoreRelationNewMsgToRecentMsg * 2 : scoreRelationNewMsgToRecentMsg;
|
|
|
|
|
if (RelationCounter > evaluationCap) {
|
|
|
|
|
strmapreturn = addSMXToMapReturn(strmapreturn, SMX);
|
|
|
|
|
hitCap = true;
|
|
|
|
|
} else if (RelationCounter < evaluationCap * -1) {
|
|
|
|
|
addSMXToMapReturn(strmapreturn, SMX);
|
|
|
|
|
hitCap = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//System.out.println("similarityMatrixes size: " + similarityMatrixes.size() + "\niterator: " + iterator);
|
|
|
|
|
iterator++;
|
|
|
|
@@ -303,26 +289,23 @@ public class Datahandler {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ConcurrentMap<Integer, String> addSMXToMapReturn(ConcurrentMap<Integer, String> strmapreturn, SimilarityMatrix SMX) {
|
|
|
|
|
//System.out.println("RelationCounter cap: " + RelationCounter);
|
|
|
|
|
boolean related = RelationCounter > 500;
|
|
|
|
|
if (related) {
|
|
|
|
|
if (!strmapreturn.containsValue(SMX.getPrimaryString())) {
|
|
|
|
|
strmapreturn.put(strmapreturn.size(), SMX.getPrimaryString());
|
|
|
|
|
String transmittedStr = SMX.getSecondaryString();
|
|
|
|
|
SentimentValueCache cacheValue1 = SMX.getCacheValue1();
|
|
|
|
|
SentimentValueCache cacheValue2 = SMX.getCacheValue2();
|
|
|
|
|
if (cacheValue1 != null && !sentimentCachingMap.keySet().contains(SMX.getPrimaryString())) {
|
|
|
|
|
sentimentCachingMap.put(SMX.getPrimaryString(), SMX.getCacheValue1());
|
|
|
|
|
sentimentCachingMap.put(SMX.getSecondaryString(), SMX.getCacheValue1());
|
|
|
|
|
}
|
|
|
|
|
if (cacheValue2 != null && !sentimentCachingMap.keySet().contains(transmittedStr)) {
|
|
|
|
|
sentimentCachingMap.put(transmittedStr, SMX.getCacheValue2());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RelationCounter = 0;
|
|
|
|
|
return strmapreturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<SimilarityMatrix> StrComparringNoSentenceRelationMap(
|
|
|
|
|
ConcurrentMap<Integer, String> strCacheLocal, String str, ConcurrentMap<String, Annotation> localJMWEMap,
|
|
|
|
|
ConcurrentMap<Integer, String> strCacheLocal, Collection<String> str, ConcurrentMap<String, Annotation> localJMWEMap,
|
|
|
|
|
ConcurrentMap<String, Annotation> localPipelineAnnotation, ConcurrentMap<String, Annotation> localPipelineSentimentAnnotation,
|
|
|
|
|
ConcurrentMap<String, CoreDocument> localCoreDocumentMap, CompletionService<SimilarityMatrix> ecs, int index) {
|
|
|
|
|
int prefix_size = 125;
|
|
|
|
@@ -342,35 +325,40 @@ public class Datahandler {
|
|
|
|
|
iterated++;
|
|
|
|
|
}
|
|
|
|
|
for (String str1 : randomIterationComparision) {
|
|
|
|
|
if (!str.equals(str1)) {
|
|
|
|
|
SimilarityMatrix SMXInit = new SimilarityMatrix(str, str1);
|
|
|
|
|
SentimentValueCache sentimentCacheStr1 = sentimentCachingMap.getOrDefault(str1, null);
|
|
|
|
|
Callable<SimilarityMatrix> worker;
|
|
|
|
|
if (stringCache.size() < prefix_size) {
|
|
|
|
|
worker = new SentimentAnalyzerTest(str, str1, SMXInit,
|
|
|
|
|
localJMWEMap.get(str), localJMWEMap.get(str1), localPipelineAnnotation.get(str),
|
|
|
|
|
localPipelineAnnotation.get(str1), localPipelineSentimentAnnotation.get(str),
|
|
|
|
|
localPipelineSentimentAnnotation.get(str1), localCoreDocumentMap.get(str), localCoreDocumentMap.get(str1), sentimentCacheStr, sentimentCacheStr1);
|
|
|
|
|
} else {
|
|
|
|
|
worker = new SentimentAnalyzerTest(str, str1, SMXInit,
|
|
|
|
|
localJMWEMap.get(str), jmweAnnotationCache.get(str1), localPipelineAnnotation.get(str),
|
|
|
|
|
pipelineAnnotationCache.get(str1), localPipelineSentimentAnnotation.get(str),
|
|
|
|
|
pipelineSentimentAnnotationCache.get(str1), localCoreDocumentMap.get(str), coreDocumentAnnotationCache.get(str1), sentimentCacheStr, sentimentCacheStr1);
|
|
|
|
|
for (String str2 : str) {
|
|
|
|
|
if (!str2.equals(str1)) {
|
|
|
|
|
SimilarityMatrix SMXInit = new SimilarityMatrix(str2, str1);
|
|
|
|
|
SentimentValueCache sentimentCacheStr1 = sentimentCachingMap.getOrDefault(str1, null);
|
|
|
|
|
Callable<SimilarityMatrix> worker;
|
|
|
|
|
if (stringCache.size() < prefix_size) {
|
|
|
|
|
worker = new SentimentAnalyzerTest(str2, str1, SMXInit,
|
|
|
|
|
localJMWEMap.get(str), localJMWEMap.get(str1), localPipelineAnnotation.get(str),
|
|
|
|
|
localPipelineAnnotation.get(str1), localPipelineSentimentAnnotation.get(str),
|
|
|
|
|
localPipelineSentimentAnnotation.get(str1), localCoreDocumentMap.get(str), localCoreDocumentMap.get(str1), sentimentCacheStr, sentimentCacheStr1);
|
|
|
|
|
} else {
|
|
|
|
|
worker = new SentimentAnalyzerTest(str2, str1, SMXInit,
|
|
|
|
|
localJMWEMap.get(str), jmweAnnotationCache.get(str1), localPipelineAnnotation.get(str),
|
|
|
|
|
pipelineAnnotationCache.get(str1), localPipelineSentimentAnnotation.get(str),
|
|
|
|
|
pipelineSentimentAnnotationCache.get(str1), localCoreDocumentMap.get(str), coreDocumentAnnotationCache.get(str1), sentimentCacheStr, sentimentCacheStr1);
|
|
|
|
|
}
|
|
|
|
|
ecs.submit(worker);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
ecs.submit(worker);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < index; i++) {
|
|
|
|
|
try {
|
|
|
|
|
Future<SimilarityMatrix> take = ecs.take();
|
|
|
|
|
SimilarityMatrix smx = take.get();
|
|
|
|
|
smxReturnList.add(smx);
|
|
|
|
|
if (smx != null && !smxReturnList.contains(smx)) {
|
|
|
|
|
smxReturnList.add(smx);
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException | ExecutionException ex) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
index = 0;
|
|
|
|
|
System.out.println("smxReturnList size: " + smxReturnList.size());
|
|
|
|
|
return smxReturnList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -378,21 +366,17 @@ public class Datahandler {
|
|
|
|
|
ConcurrentMap<Integer, String> strCacheLocal, ConcurrentMap<String, Annotation> localJMWEMap,
|
|
|
|
|
ConcurrentMap<String, Annotation> localPipelineAnnotation, ConcurrentMap<String, Annotation> localPipelineSentimentAnnotation,
|
|
|
|
|
ConcurrentMap<String, CoreDocument> localCoreDocumentMap) {
|
|
|
|
|
ConcurrentMap<Integer, String> strmapreturn = new MapMaker().concurrencyLevel(6).makeMap();
|
|
|
|
|
List<SimilarityMatrix> strSenseRelationMap = new ArrayList();
|
|
|
|
|
ExecutorService threadPool = Executors.newCachedThreadPool();
|
|
|
|
|
CompletionService<SimilarityMatrix> ecs = new ExecutorCompletionService<>(threadPool);
|
|
|
|
|
int index = 0;
|
|
|
|
|
strmap.values().forEach(str -> {
|
|
|
|
|
List<SimilarityMatrix> localNoSentenceRelationList = StrComparringNoSentenceRelationMap(strCacheLocal, str,
|
|
|
|
|
localJMWEMap, localPipelineAnnotation, localPipelineSentimentAnnotation, localCoreDocumentMap, ecs, index);
|
|
|
|
|
for (SimilarityMatrix SMX : localNoSentenceRelationList) {
|
|
|
|
|
strSenseRelationMap.add(SMX);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//System.out.println("strmap siuze: " + strmap.size());
|
|
|
|
|
List<SimilarityMatrix> StrComparringNoSentenceRelationMap = StrComparringNoSentenceRelationMap(strCacheLocal, strmap.values(),
|
|
|
|
|
localJMWEMap, localPipelineAnnotation, localPipelineSentimentAnnotation, localCoreDocumentMap, ecs, index);
|
|
|
|
|
threadPool.shutdown();
|
|
|
|
|
Collections.sort(strSenseRelationMap, (e1, e2) -> e1.getPrimaryString().compareTo(e2.getPrimaryString()));
|
|
|
|
|
strmapreturn = futuresReturnOverallEvaluation(strSenseRelationMap, strmapreturn);
|
|
|
|
|
//System.out.println("StrComparringNoSentenceRelationMap size: " + StrComparringNoSentenceRelationMap.size());
|
|
|
|
|
Collections.sort(StrComparringNoSentenceRelationMap, (e1, e2) -> e1.getPrimaryString().compareTo(e2.getPrimaryString()));
|
|
|
|
|
ConcurrentMap<Integer, String> strmapreturn = futuresReturnOverallEvaluation(StrComparringNoSentenceRelationMap);
|
|
|
|
|
//System.out.println("strmapreturn size: " + strmapreturn.size());
|
|
|
|
|
return strmapreturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -408,13 +392,15 @@ public class Datahandler {
|
|
|
|
|
public synchronized void checkIfUpdateStrings(boolean hlStatsMsg) throws CustomError {
|
|
|
|
|
if (stopwatch.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS || !stopwatch.isRunning()) {
|
|
|
|
|
ConcurrentMap<Integer, String> str = MessageResponseHandler.getStr();
|
|
|
|
|
System.out.println("str size: " + str.size());
|
|
|
|
|
str = cutContent(str, hlStatsMsg);
|
|
|
|
|
str = filterContent(str);
|
|
|
|
|
str = removeSlacks(str);
|
|
|
|
|
//System.out.println("finished removeSlacks \n" + str.size() + "\n");
|
|
|
|
|
str = removeNonSensicalStrings(str);
|
|
|
|
|
System.out.println("removeNonSensicalStrings str size POST: " + str.size() + "\n");
|
|
|
|
|
str = annotationCacheUpdate(str);
|
|
|
|
|
//System.out.println("annotationCacheUpdate str size POST: " + str.size() + "\n");
|
|
|
|
|
System.out.println("annotationCacheUpdate str size POST: " + str.size() + "\n");
|
|
|
|
|
ConcurrentMap<Integer, String> strf = str;
|
|
|
|
|
if (!stringCache.isEmpty()) {
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|