un-parallelising some functions, changing futures retriever, moving some thresholds and logic around

This commit is contained in:
jenzur
2020-03-07 18:40:59 +01:00
parent 6d4ab15107
commit ac56f386a3
9 changed files with 455 additions and 321 deletions
@@ -1250,136 +1250,257 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
SentimentValueCache cacheSentimentLocal2 = null;
int counter1;
int counter2;
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = initializeCacheSetup(str, cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = initializeCacheSetup(str1, cacheSentimentLocal2);
}
counter1 = cacheSentiment1 == null ? cacheSentimentLocal1.getCounter() : cacheSentiment1.getCounter();
counter2 = cacheSentiment2 == null ? cacheSentimentLocal2.getCounter() : cacheSentiment2.getCounter();
final int overValue = (counter1 >= counter2 ? counter1 - counter2 : counter2 - counter1) * 32;
score -= overValue;
if (cacheSentiment1 == null) {
ConcurrentMap<Integer, String> retrieveTGWListIndex = retrieveTGWListIndex(cacheSentimentLocal1.getTaggedwordlist());
for (String str : retrieveTGWListIndex.values()) {
cacheSentimentLocal1.addTgwlistIndex(str);
try {
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = initializeCacheSetup(str, cacheSentimentLocal1);
}
}
if (cacheSentiment2 == null) {
ConcurrentMap<Integer, String> retrieveTGWListIndex = retrieveTGWListIndex(cacheSentimentLocal2.getTaggedwordlist());
for (String str : retrieveTGWListIndex.values()) {
cacheSentimentLocal2.addTgwlistIndex(str);
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = initializeCacheSetup(str1, cacheSentimentLocal2);
}
} catch (Exception ex) {
}
score = tgwListScoreIncrementer(score, cacheSentiment1 == null
? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2);
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = GrammaticStructureSetup(cacheSentimentLocal1, pipelineAnnotation1);
try {
counter1 = cacheSentiment1 == null ? cacheSentimentLocal1.getCounter() : cacheSentiment1.getCounter();
counter2 = cacheSentiment2 == null ? cacheSentimentLocal2.getCounter() : cacheSentiment2.getCounter();
final int overValue = (counter1 >= counter2 ? counter1 - counter2 : counter2 - counter1) * 32;
score -= overValue;
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = GrammaticStructureSetup(cacheSentimentLocal2, pipelineAnnotation2);
try {
if (cacheSentiment1 == null) {
ConcurrentMap<Integer, String> retrieveTGWListIndex = retrieveTGWListIndex(cacheSentimentLocal1.getTaggedwordlist());
for (String str : retrieveTGWListIndex.values()) {
cacheSentimentLocal1.addTgwlistIndex(str);
}
}
if (cacheSentiment2 == null) {
ConcurrentMap<Integer, String> retrieveTGWListIndex = retrieveTGWListIndex(cacheSentimentLocal2.getTaggedwordlist());
for (String str : retrieveTGWListIndex.values()) {
cacheSentimentLocal2.addTgwlistIndex(str);
}
}
} catch (Exception ex) {
}
ConcurrentMap<Integer, Tree> sentenceConstituencyParseList2 = cacheSentiment2 == null
? cacheSentimentLocal2.getSentenceConstituencyParseList() : cacheSentiment2.getSentenceConstituencyParseList();
ConcurrentMap<Integer, Tree> sentenceConstituencyParseList1 = cacheSentiment1 == null
? cacheSentimentLocal1.getSentenceConstituencyParseList() : cacheSentiment1.getSentenceConstituencyParseList();
score = iterateTrees(sentenceConstituencyParseList2, sentenceConstituencyParseList1, score);
Collection<TypedDependency> allTypedDependencies2 = cacheSentiment2 == null ? cacheSentimentLocal2.getAllTypedDependencies()
: cacheSentiment2.getAllTypedDependencies();
Collection<TypedDependency> allTypedDependencies1 = cacheSentiment1 == null ? cacheSentimentLocal1.getAllTypedDependencies()
: cacheSentiment1.getAllTypedDependencies();
ConcurrentMap<Integer, GrammaticalStructure> grammaticalMap1 = cacheSentiment1 == null ? cacheSentimentLocal1.getGs() : cacheSentiment1.getGs();
ConcurrentMap<Integer, GrammaticalStructure> grammaticalMap2 = cacheSentiment2 == null ? cacheSentimentLocal2.getGs() : cacheSentiment2.getGs();
score = typeDependenciesGrammaticalRelation(allTypedDependencies1, allTypedDependencies2, score, grammaticalMap1, grammaticalMap2,
sentenceConstituencyParseList1, sentenceConstituencyParseList2);
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = sentimentCoreAnnotationSetup(pipelineAnnotation1Sentiment, cacheSentimentLocal1);
try {
score = tgwListScoreIncrementer(score, cacheSentiment1 == null
? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2);
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = GrammaticStructureSetup(cacheSentimentLocal1, pipelineAnnotation1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = GrammaticStructureSetup(cacheSentimentLocal2, pipelineAnnotation2);
}
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = sentimentCoreAnnotationSetup(pipelineAnnotation2Sentiment, cacheSentimentLocal2);
ConcurrentMap<Integer, Tree> sentenceConstituencyParseList1 = null;
ConcurrentMap<Integer, Tree> sentenceConstituencyParseList2 = null;
try {
sentenceConstituencyParseList2 = cacheSentiment2 == null
? cacheSentimentLocal2.getSentenceConstituencyParseList() : cacheSentiment2.getSentenceConstituencyParseList();
sentenceConstituencyParseList1 = cacheSentiment1 == null
? cacheSentimentLocal1.getSentenceConstituencyParseList() : cacheSentiment1.getSentenceConstituencyParseList();
score = iterateTrees(sentenceConstituencyParseList2, sentenceConstituencyParseList1, score);
} catch (Exception ex) {
}
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlist1 = cacheSentiment1 == null
? cacheSentimentLocal1.getSimpleSMXlist() : cacheSentiment1.getSimpleSMXlist();
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlist2 = cacheSentiment2 == null
? cacheSentimentLocal2.getSimpleSMXlist() : cacheSentiment2.getSimpleSMXlist();
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlistVector1 = cacheSentiment1 == null
? cacheSentimentLocal1.getSimpleSMXlistVector() : cacheSentiment1.getSimpleSMXlistVector();
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlistVector2 = cacheSentiment2 == null
? cacheSentimentLocal2.getSimpleSMXlistVector() : cacheSentiment2.getSimpleSMXlistVector();
score = simpleRNNMatrixCalculations(score, simpleSMXlist1, simpleSMXlist2);
score = simpleRNNMaxtrixVectors(score, simpleSMXlistVector1, simpleSMXlistVector2);
int sentiment1 = cacheSentiment1 == null ? cacheSentimentLocal1.getRnnPrediectClassMap().size() : cacheSentiment1.getRnnPrediectClassMap().size();
int sentiment2 = cacheSentiment2 == null ? cacheSentimentLocal2.getRnnPrediectClassMap().size() : cacheSentiment2.getRnnPrediectClassMap().size();
score -= (sentiment1 > sentiment2 ? sentiment1 - sentiment2 : sentiment2 - sentiment1) * 500;
Map.Entry<Double, Map.Entry<SentimentValueCache, SentimentValueCache>> classifyRawEvaluationEntry = classifyRawEvaluation(score, cacheSentimentLocal1,
cacheSentimentLocal2);
score = classifyRawEvaluationEntry.getKey();
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = classifyRawEvaluationEntry.getValue().getKey();
try {
Collection<TypedDependency> allTypedDependencies2 = cacheSentiment2 == null ? cacheSentimentLocal2.getAllTypedDependencies()
: cacheSentiment2.getAllTypedDependencies();
Collection<TypedDependency> allTypedDependencies1 = cacheSentiment1 == null ? cacheSentimentLocal1.getAllTypedDependencies()
: cacheSentiment1.getAllTypedDependencies();
ConcurrentMap<Integer, GrammaticalStructure> grammaticalMap1 = cacheSentiment1 == null ? cacheSentimentLocal1.getGs() : cacheSentiment1.getGs();
ConcurrentMap<Integer, GrammaticalStructure> grammaticalMap2 = cacheSentiment2 == null ? cacheSentimentLocal2.getGs() : cacheSentiment2.getGs();
score = typeDependenciesGrammaticalRelation(allTypedDependencies1, allTypedDependencies2, score, grammaticalMap1, grammaticalMap2,
sentenceConstituencyParseList1, sentenceConstituencyParseList2);
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = classifyRawEvaluationEntry.getValue().getValue();
try {
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = sentimentCoreAnnotationSetup(pipelineAnnotation1Sentiment, cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = sentimentCoreAnnotationSetup(pipelineAnnotation2Sentiment, cacheSentimentLocal2);
}
} catch (Exception ex) {
}
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = setupMainSentimentandLongestVal(pipelineAnnotation1Sentiment, cacheSentimentLocal1);
try {
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlist1 = cacheSentiment1 == null
? cacheSentimentLocal1.getSimpleSMXlist() : cacheSentiment1.getSimpleSMXlist();
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlist2 = cacheSentiment2 == null
? cacheSentimentLocal2.getSimpleSMXlist() : cacheSentiment2.getSimpleSMXlist();
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlistVector1 = cacheSentiment1 == null
? cacheSentimentLocal1.getSimpleSMXlistVector() : cacheSentiment1.getSimpleSMXlistVector();
final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlistVector2 = cacheSentiment2 == null
? cacheSentimentLocal2.getSimpleSMXlistVector() : cacheSentiment2.getSimpleSMXlistVector();
score = simpleRNNMatrixCalculations(score, simpleSMXlist1, simpleSMXlist2);
score = simpleRNNMaxtrixVectors(score, simpleSMXlistVector1, simpleSMXlistVector2);
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = setupMainSentimentandLongestVal(pipelineAnnotation2Sentiment, cacheSentimentLocal2);
try {
int sentiment1 = cacheSentiment1 == null ? cacheSentimentLocal1.getRnnPrediectClassMap().size() : cacheSentiment1.getRnnPrediectClassMap().size();
int sentiment2 = cacheSentiment2 == null ? cacheSentimentLocal2.getRnnPrediectClassMap().size() : cacheSentiment2.getRnnPrediectClassMap().size();
score -= (sentiment1 > sentiment2 ? sentiment1 - sentiment2 : sentiment2 - sentiment1) * 500;
Map.Entry<Double, Map.Entry<SentimentValueCache, SentimentValueCache>> classifyRawEvaluationEntry = classifyRawEvaluation(score, cacheSentimentLocal1,
cacheSentimentLocal2);
score = classifyRawEvaluationEntry.getKey();
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = classifyRawEvaluationEntry.getValue().getKey();
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = classifyRawEvaluationEntry.getValue().getValue();
}
} catch (Exception ex) {
}
score = sentimentMatrixVariances(score, cacheSentiment1 == null ? cacheSentimentLocal1.getLongest() : cacheSentiment1.getLongest(),
cacheSentiment2 == null ? cacheSentimentLocal2.getLongest() : cacheSentiment2.getLongest(), cacheSentiment1 == null
? cacheSentimentLocal1.getMainSentiment() : cacheSentiment1.getMainSentiment(), cacheSentiment2 == null
? cacheSentimentLocal2.getMainSentiment() : cacheSentiment2.getMainSentiment());
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = jmweAnnotationSetup(jmweStrAnnotation1, cacheSentimentLocal1);
try {
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = setupMainSentimentandLongestVal(pipelineAnnotation1Sentiment, cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = setupMainSentimentandLongestVal(pipelineAnnotation2Sentiment, cacheSentimentLocal2);
}
score = sentimentMatrixVariances(score, cacheSentiment1 == null ? cacheSentimentLocal1.getLongest() : cacheSentiment1.getLongest(),
cacheSentiment2 == null ? cacheSentimentLocal2.getLongest() : cacheSentiment2.getLongest(), cacheSentiment1 == null
? cacheSentimentLocal1.getMainSentiment() : cacheSentiment1.getMainSentiment(), cacheSentiment2 == null
? cacheSentimentLocal2.getMainSentiment() : cacheSentiment2.getMainSentiment());
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = jmweAnnotationSetup(jmweStrAnnotation2, cacheSentimentLocal2);
try {
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = jmweAnnotationSetup(jmweStrAnnotation1, cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = jmweAnnotationSetup(jmweStrAnnotation2, cacheSentimentLocal2);
}
} catch (Exception ex) {
}
SentimentValueCache scoringCache1 = cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1;
SentimentValueCache scoringCache2 = cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2;
score = entryCountsRelation(score, scoringCache1, scoringCache2);
score = entryCountsScoring(score, scoringCache1, scoringCache2);
score = tokenEntryPosScoring(score, scoringCache1, scoringCache2);
score = unmarkedPatternCounterScoring(score, scoringCache1, scoringCache2);
score = markedContiniousCounterScoring(score, scoringCache1, scoringCache2);
score = strTokensMapScoring(score, scoringCache1, scoringCache2);
score = strTokenEntryScoring(score, scoringCache1, scoringCache2);
score = strTokenMapTagsScoring(score, scoringCache1, scoringCache2);
score = tokenformSizeScoring(score, scoringCache1, scoringCache2);
score = tokenStemmingMapScoring(score, scoringCache1, scoringCache2);
score = inflectedCounterScoring(score, scoringCache1, scoringCache2);
score = annotatorCountScoring(score, scoringCache1, scoringCache2);
score = tokensCounterScoring(score, scoringCache1, scoringCache2);
LevenshteinDistance leven = new LevenshteinDistance(str, str1);
double SentenceScoreDiff = leven.computeLevenshteinDistance();
SentenceScoreDiff *= 15;
score -= SentenceScoreDiff;
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument1, cacheSentimentLocal1);
try {
score = entryCountsRelation(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument2, cacheSentimentLocal2);
try {
score = entryCountsScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
score = nerEntitiesAndTokenScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null
? cacheSentimentLocal2 : cacheSentiment2);
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = setupStoWordTokensLemma(pipelineAnnotation1Sentiment, cacheSentimentLocal1);
try {
score = tokenEntryPosScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = setupStoWordTokensLemma(pipelineAnnotation2Sentiment, cacheSentimentLocal2);
try {
score = unmarkedPatternCounterScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = markedContiniousCounterScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = strTokensMapScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = strTokenEntryScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = strTokenMapTagsScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = tokenformSizeScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = tokenStemmingMapScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = inflectedCounterScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = annotatorCountScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
score = tokensCounterScoring(score, scoringCache1, scoringCache2);
} catch (Exception ex) {
}
try {
LevenshteinDistance leven = new LevenshteinDistance(str, str1);
double SentenceScoreDiff = leven.computeLevenshteinDistance();
SentenceScoreDiff *= 15;
score -= SentenceScoreDiff;
} catch (Exception ex) {
}
try {
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument1, cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument2, cacheSentimentLocal2);
}
score = nerEntitiesAndTokenScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null
? cacheSentimentLocal2 : cacheSentiment2);
} catch (Exception ex) {
}
try {
if (cacheSentiment1 == null) {
cacheSentimentLocal1 = setupStoWordTokensLemma(pipelineAnnotation1Sentiment, cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
cacheSentimentLocal2 = setupStoWordTokensLemma(pipelineAnnotation2Sentiment, cacheSentimentLocal2);
}
score = stopWordTokenLemmaScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null
? cacheSentimentLocal2 : cacheSentiment2);
} catch (Exception ex) {
}
try {
score = stopwordTokenPairCounterScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null
? cacheSentimentLocal2 : cacheSentiment2);
} catch (Exception ex) {
}
score = stopWordTokenLemmaScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null
? cacheSentimentLocal2 : cacheSentiment2);
score = stopwordTokenPairCounterScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null
? cacheSentimentLocal2 : cacheSentiment2);
smxParam.setDistance(score);
if (cacheSentiment1 == null) {
smxParam.setCacheValue1(cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
smxParam.setCacheValue2(cacheSentimentLocal2);
try {
if (cacheSentiment1 == null) {
smxParam.setCacheValue1(cacheSentimentLocal1);
}
if (cacheSentiment2 == null) {
smxParam.setCacheValue2(cacheSentimentLocal2);
}
} catch (Exception ex) {
}
return smxParam;
}