diff --git a/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java b/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java index 5b477ac4..df108d03 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java @@ -7,6 +7,7 @@ package FunctionLayer; import DataLayer.DataMapper; import FunctionLayer.StanfordParser.SentimentAnalyzerTest; +import FunctionLayer.StanfordParser.SentimentValueCache; import com.google.common.base.Stopwatch; import com.google.common.collect.MapMaker; import edu.stanford.nlp.ie.AbstractSequenceClassifier; @@ -48,7 +49,7 @@ import java.util.stream.Collectors; * @author install1 */ public class Datahandler { - + public static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(10, TimeUnit.MINUTES); public static final long EXPIRE_TIME_IN_SECONDS1 = TimeUnit.SECONDS.convert(10, TimeUnit.HOURS); public static Datahandler instance = new Datahandler(); @@ -69,6 +70,7 @@ public class Datahandler { private static ConcurrentMap coreDocumentAnnotationCache; private static ConcurrentMap conversationMatchMap; private static ConcurrentMap conversationUserMatchMap; + private static ConcurrentMap sentimentCachingMap = new MapMaker().concurrencyLevel(6).makeMap(); private static final ConcurrentMap locateFaultySentences = new MapMaker().concurrencyLevel(6).makeMap(); private static final ConcurrentMap mapUdate = new MapMaker().concurrencyLevel(4).makeMap(); private final static ConcurrentMap strmapreturn = new MapMaker().concurrencyLevel(4).makeMap(); @@ -95,7 +97,7 @@ public class Datahandler { // set up Stanford CoreNLP pipeline private static final StanfordCoreNLP pipeline = getPipeLineSetUp(); private static StanfordCoreNLP pipelineSentiment; - + public Datahandler() { this.stopwatch = Stopwatch.createUnstarted(); this.jmweAnnotationCache = new MapMaker().concurrencyLevel(3).makeMap(); @@ -105,7 +107,7 @@ public class Datahandler { this.conversationMatchMap = new MapMaker().concurrencyLevel(4).makeMap(); this.conversationUserMatchMap = new MapMaker().concurrencyLevel(4).makeMap(); } - + private static StanfordCoreNLP getPipeLineSetUp() { props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse"); props.setProperty("parse.model", shiftReduceParserPath); @@ -123,7 +125,7 @@ public class Datahandler { props.setProperty("tokenize.options", "untokenizable=firstDelete"); return new StanfordCoreNLP(props); } - + public void shiftReduceParserInitiate() { //got 8 cores CountDownLatch cdl = new CountDownLatch(2); @@ -161,15 +163,15 @@ public class Datahandler { } System.out.println("finished shiftReduceParserInitiate\n"); } - + public static AbstractSequenceClassifier getClassifier() { return classifier; } - + public static void setClassifier(AbstractSequenceClassifier classifier) { Datahandler.classifier = classifier; } - + public void updateStringCache() { try { checkIfUpdateStrings(true); @@ -177,42 +179,42 @@ public class Datahandler { Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex); } } - + private static ForkJoinPool instantiateExecutor() { //Runtime.getRuntime().availableProcessors() or static value like 25 return new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, false); } - + public static GrammaticalStructureFactory getGsf() { return gsf; } - + public static StanfordCoreNLP getPipeline() { return pipeline; } - + public static StanfordCoreNLP getPipelineSentiment() { return pipelineSentiment; } - + public static MaxentTagger getTagger() { return tagger; } - + private Map getCache() throws SQLException, IOException, CustomError { return DataMapper.getAllStrings(); } - + public int getlHMSMXSize() { return lHMSMX.size(); } - + public int getstringCacheSize() { return stringCache.size(); } - + public void initiateMYSQL() throws SQLException, IOException { try { DataMapper.createTables(); @@ -223,7 +225,7 @@ public class Datahandler { .getName()).log(Level.SEVERE, null, ex); } } - + public void addHLstatsMessages() { ConcurrentMap hlStatsMessages = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap strCacheLocal = stringCache; @@ -233,7 +235,7 @@ public class Datahandler { hlStatsMessages.put(str, hlStatsMessages.size()); } } - int capacity = 15000; + int capacity = 5550; 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); @@ -243,7 +245,7 @@ public class Datahandler { } }); } - + public void instantiateAnnotationMapJMWE() { if (!stringCache.isEmpty()) { ConcurrentMap jmweAnnotation = PipelineJMWESingleton.INSTANCE.getJMWEAnnotation(stringCache.values()); @@ -252,7 +254,7 @@ public class Datahandler { } } } - + public void instantiateAnnotationMap() { if (!stringCache.isEmpty()) { ConcurrentMap Annotationspipeline = new MapMaker().concurrencyLevel(2).makeMap(); @@ -277,29 +279,41 @@ public class Datahandler { }); } } - - private final static void futuresReturnOverallEvaluation(ConcurrentMap> entries, String str) { + + private static void futuresReturnOverallEvaluation(ConcurrentMap> entries, String str) { for (Entry> entrySet : entries.entrySet()) { String transmittedStr = entrySet.getKey(); - final SimilarityMatrix getSMX = retrieveFutureSMX(entrySet.getValue()); + SimilarityMatrix getSMX = retrieveFutureSMX(entrySet.getValue()); if (handleRetrievedSMX(getSMX, str, transmittedStr)) { break; } + try { + SentimentValueCache cacheValue1 = getSMX.getCacheValue1(); + SentimentValueCache cacheValue2 = getSMX.getCacheValue2(); + if (cacheValue1 != null && !sentimentCachingMap.keySet().contains(str)) { + sentimentCachingMap.put(str, getSMX.getCacheValue1()); + } + if (cacheValue2 != null && !sentimentCachingMap.keySet().contains(transmittedStr)) { + sentimentCachingMap.put(transmittedStr, getSMX.getCacheValue2()); + } + } catch (Exception ex) { + //System.out.println("FAILING futures return. EX: " + ex.getLocalizedMessage() + "\n"); + } } sentenceRelationMap.put(str, mapUdate); } - - private static final boolean handleRetrievedSMX(SimilarityMatrix getSMX, String str, String transmittedStr) { + + private static boolean handleRetrievedSMX(SimilarityMatrix getSMX, String str, String transmittedStr) { final int relationCap = 20; if (getSMX != null) { + //System.out.println("getSMX primary: " + getSMX.getPrimaryString() + "\ngetSMX secondary: " + getSMX.getSecondaryString() + "\n"); final Double scoreRelationNewMsgToRecentMsg = getSMX.getDistance(); - System.out.println("scoreRelationNewMsgToRecentMsg: " + scoreRelationNewMsgToRecentMsg + "\n"); + //System.out.println("scoreRelationNewMsgToRecentMsg: " + scoreRelationNewMsgToRecentMsg + "\n"); mapUdate.put(getSMX.getSecondaryString(), scoreRelationNewMsgToRecentMsg); - System.out.println("getSMX primary: " + getSMX.getPrimaryString() + "\ngetSMX secodary: " + getSMX.getSecondaryString() + "\n"); if (scoreRelationNewMsgToRecentMsg >= 200.0) { positiveRelationCounter++; if (positiveRelationCounter >= relationCap) { - System.out.println("added to strmapreturn str: " + str + "\n"); + //System.out.println("added to strmapreturn str: " + str + "\n"); strmapreturn.put(strmapreturn.size() + 1, str); return true; } @@ -319,8 +333,10 @@ public class Datahandler { } return false; } - - private final static Entry>, ConcurrentMap> StrComparringNoSentenceRelationMap(ConcurrentMap strCacheLocal, String str, ConcurrentMap localJMWEMap, ConcurrentMap localPipelineAnnotation, ConcurrentMap localPipelineSentimentAnnotation, + + private static Entry>, ConcurrentMap> StrComparringNoSentenceRelationMap( + ConcurrentMap strCacheLocal, String str, ConcurrentMap localJMWEMap, + ConcurrentMap localPipelineAnnotation, ConcurrentMap localPipelineSentimentAnnotation, ConcurrentMap localCoreDocumentMap) { final ConcurrentMap> futures = new MapMaker().concurrencyLevel(4).makeMap(); strCacheLocal.values().removeIf(e -> { @@ -330,29 +346,32 @@ public class Datahandler { } return true; }); + SentimentValueCache sentimentCacheStr = sentimentCachingMap.getOrDefault(str, null); for (String str1 : strCacheLocal.values()) { - if (!str.equals(str1)) { + //experimental change + if (!str.equals(str1) && !futures.keySet().contains(str1)) { final SimilarityMatrix SMX = new SimilarityMatrix(str, str1); + SentimentValueCache sentimentCacheStr1 = sentimentCachingMap.getOrDefault(str1, null); final Callable worker; if (stringCache.size() < 150) { worker = new SentimentAnalyzerTest(str, str1, SMX, localJMWEMap.get(str), localJMWEMap.get(str1), localPipelineAnnotation.get(str), localPipelineAnnotation.get(str1), localPipelineSentimentAnnotation.get(str), - localPipelineSentimentAnnotation.get(str1), localCoreDocumentMap.get(str), localCoreDocumentMap.get(str1)); + localPipelineSentimentAnnotation.get(str1), localCoreDocumentMap.get(str), localCoreDocumentMap.get(str1), sentimentCacheStr, sentimentCacheStr1); } else { worker = new SentimentAnalyzerTest(str, str1, SMX, localJMWEMap.get(str), jmweAnnotationCache.get(str1), localPipelineAnnotation.get(str), pipelineAnnotationCache.get(str1), localPipelineSentimentAnnotation.get(str), - pipelineSentimentAnnotationCache.get(str1), localCoreDocumentMap.get(str), coreDocumentAnnotationCache.get(str1)); + pipelineSentimentAnnotationCache.get(str1), localCoreDocumentMap.get(str), coreDocumentAnnotationCache.get(str1), sentimentCacheStr, sentimentCacheStr1); } futures.put(str1, executor.submit(worker)); } } - Map.Entry>, ConcurrentMap> entryReturn + Map.Entry>, ConcurrentMap> mapreturn = new AbstractMap.SimpleEntry(futures, strCacheLocal); - return entryReturn; + return mapreturn; } - + private static ConcurrentMap stringIteratorComparator(ConcurrentMap strmap, ConcurrentMap strCacheLocal, ConcurrentMap localJMWEMap, ConcurrentMap localPipelineAnnotation, ConcurrentMap localPipelineSentimentAnnotation, @@ -376,7 +395,7 @@ public class Datahandler { } return strmapreturn; } - + private static final ConcurrentMap removeNonSensicalStrings(ConcurrentMap strmap) { final ConcurrentMap strCacheLocal = stringCache.size() < 150 ? strmap : stringCache; final ConcurrentMap localJMWEMap = getMultipleJMWEAnnotation(strmap.values()); @@ -386,16 +405,19 @@ public class Datahandler { System.out.println("finished removeNonSensicalStrings annotations \n"); return stringIteratorComparator(strmap, strCacheLocal, localJMWEMap, localPipelineAnnotation, localPipelineSentimentAnnotation, localCoreDocumentMap); } - - private final static SimilarityMatrix retrieveFutureSMX(Future future) { + + private static SimilarityMatrix retrieveFutureSMX(Future future) { try { - return future.get(5, TimeUnit.SECONDS); + // SimilarityMatrix SMX = future.get(); + SimilarityMatrix SMX = future.get(5, TimeUnit.SECONDS); + return SMX; } catch (InterruptedException | ExecutionException | TimeoutException ex) { Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("retrieveFutureSMX timeout Exception; " + ex.getLocalizedMessage() + "\n"); } return null; } - + public synchronized void checkIfUpdateStrings(boolean hlStatsMsg) throws CustomError { if (stopwatch.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS || !stopwatch.isRunning()) { ConcurrentMap str = MessageResponseHandler.getStr(); @@ -434,14 +456,7 @@ public class Datahandler { } } } - - /** - * - * @param str is strF aka user message, - * @param MostRecent String most recently responded with - * @return - * @throws CustomError - */ + public synchronized String getResponseMsg(String str, String MostRecent) throws CustomError { str = str.trim(); if (str.startsWith("<@")) { @@ -470,19 +485,21 @@ public class Datahandler { } if (!present) { SimilarityMatrix SMX = new SimilarityMatrix(strF, str1); + SentimentValueCache sentimentCacheStr1 = sentimentCachingMap.getOrDefault(str1, null); Callable worker = new SentimentAnalyzerTest(strF, str1, SMX, strAnnoJMWE, jmweAnnotationCache.get(str1), strAnno, pipelineAnnotationCache.get(str1), strAnnoSentiment, - pipelineSentimentAnnotationCache.get(str1), coreDoc, coreDocumentAnnotationCache.get(str1)); + pipelineSentimentAnnotationCache.get(str1), coreDoc, coreDocumentAnnotationCache.get(str1), null, sentimentCacheStr1); futureslocal.put(futureslocal.size() + 1, executor.submit(worker)); } } }); futureslocal.values().forEach((future) -> { - SimilarityMatrix SMX = new SimilarityMatrix("", ""); + SimilarityMatrix SMX; try { SMX = future.get(5, TimeUnit.SECONDS); futureAndCacheCombineMap.put(futureAndCacheCombineMap.size(), SMX); + //System.out.println("futureAndCacheCombineMap size: " + futureAndCacheCombineMap.size() + "\n"); } catch (InterruptedException | ExecutionException | TimeoutException ex) { System.out.println("ex getResponsemsg: " + ex.getMessage() + "\n"); } @@ -494,6 +511,7 @@ public class Datahandler { futureAndCacheCombineMap.put(futureAndCacheCombineMap.size(), SMX); } } + //System.out.println("futureAndCacheCombineMap size: " + futureAndCacheCombineMap.size() + "\n"); futureAndCacheCombineMap.values().parallelStream().forEach((SMX) -> { if (sentenceRelationMap.get(strF) == null) { ConcurrentMap localMap = new MapMaker().concurrencyLevel(2).makeMap(); @@ -514,12 +532,19 @@ public class Datahandler { Double scoreRelationOldUserMsg = 0.0; ConcurrentMap getPrimaryLocal = new MapMaker().concurrencyLevel(2).makeMap(); for (String conversationStr : conversationMatchMap.keySet()) { - getPrimaryLocal = sentenceRelationMap.get(strF); - Double getSecondary = getPrimaryLocal.get(conversationStr); - if (getSecondary == null) { + Double getSecondary = 0.0; + getPrimaryLocal = sentenceRelationMap.getOrDefault(strF, null); + if (getPrimaryLocal == null) { getSecondary = getScoreRelationStrF(strF, conversationStr); getPrimaryLocal.put(conversationStr, getSecondary); sentenceRelationMap.put(strF, getPrimaryLocal); + } else { + getSecondary = getPrimaryLocal.get(conversationStr); + if (getSecondary == null) { + getSecondary = getScoreRelationStrF(strF, conversationStr); + getPrimaryLocal.put(conversationStr, getSecondary); + sentenceRelationMap.put(strF, getPrimaryLocal); + } } scoreRelationNewMsgToRecentMsg += getSecondary; System.out.println("scoreRelationNewMsgToRecentMsg: " + scoreRelationNewMsgToRecentMsg + "\n"); @@ -546,6 +571,7 @@ public class Datahandler { } ConcurrentMap> concurrentRelationsMap = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap preRelationUserCountersMap = new MapMaker().concurrencyLevel(2).makeMap(); + System.out.println("futureAndCacheCombineMap size for: " + futureAndCacheCombineMap.values().size() + "\n"); for (SimilarityMatrix SMX : futureAndCacheCombineMap.values()) { Double scoreRelation = 500.0; Double scoreRelationLastUserMsg = SMX.getDistance(); @@ -574,13 +600,17 @@ public class Datahandler { } } Double totalRelation = scoreRelation + scoreRelationLastUserMsg; - if (totalRelation > preRelationCounters + preRelationUserCounters && scoreRelationLastUserMsg + (preRelationUserCounters / 10) - > preRelationUserCounters) { + if (totalRelation > preRelationCounters + preRelationUserCounters && (scoreRelationLastUserMsg + (preRelationUserCounters / 10) + >= preRelationUserCounters) || preRelationUserCounters == -100.0) { Entry localEntry = new AbstractMap.SimpleEntry(totalRelation, SMX); concurrentRelationsMap.put(concurrentRelationsMap.size(), localEntry); preRelationUserCountersMap.put(preRelationUserCountersMap.size(), preRelationUserCounters); + System.out.println("SUCESS concurrentRelationsMap size: " + concurrentRelationsMap.size() + "\n"); preRelationCounters = scoreRelation; preRelationUserCounters = scoreRelationLastUserMsg; + } else { + System.out.println("FAILED totalRelation: " + totalRelation + "\npreRelationUserCounters: " + preRelationUserCounters + "\npreRelationCounters: " + + preRelationCounters + "\nscoreRelationLastUserMsg: " + scoreRelationLastUserMsg + "\n"); } } StringBuilder SB = new StringBuilder(); @@ -601,7 +631,7 @@ public class Datahandler { System.out.println("Reached end: SB: " + SB.toString() + "\n: "); return SB.toString(); } - + public void getSingularAnnotation(String str) { strAnno = new Annotation(str); pipeline.annotate(strAnno); @@ -615,12 +645,12 @@ public class Datahandler { pipeline.annotate(coreDocument); coreDoc = coreDocument; } - + private static ConcurrentMap getMultipleJMWEAnnotation(Collection str) { ConcurrentMap jmweAnnotation = PipelineJMWESingleton.INSTANCE.getJMWEAnnotation(str); return jmweAnnotation; } - + private static ConcurrentMap getMultiplePipelineAnnotation(Collection str) { ConcurrentMap pipelineAnnotationMap = new MapMaker().concurrencyLevel(2).makeMap(); for (String str1 : str) { @@ -630,7 +660,7 @@ public class Datahandler { pipeline.annotate(pipelineAnnotationMap.values()); return pipelineAnnotationMap; } - + private static ConcurrentMap getMultiplePipelineSentimentAnnotation(Collection str) { ConcurrentMap pipelineAnnotationMap = new MapMaker().concurrencyLevel(2).makeMap(); for (String str1 : str) { @@ -640,14 +670,16 @@ public class Datahandler { pipelineSentiment.annotate(pipelineAnnotationMap.values()); return pipelineAnnotationMap; } - + private Double getScoreRelationNewMsgToRecentMsg(String str, String mostRecentMsg) { SimilarityMatrix SMX = new SimilarityMatrix(str, mostRecentMsg); + SentimentValueCache cacheSentiment1 = sentimentCachingMap.getOrDefault(str, null); + SentimentValueCache cacheSentiment2 = sentimentCachingMap.getOrDefault(mostRecentMsg, null); Callable worker = new SentimentAnalyzerTest(str, mostRecentMsg, SMX, jmweAnnotationCache.get(str), jmweAnnotationCache.get(mostRecentMsg), pipelineAnnotationCache.get(str), pipelineAnnotationCache.get(mostRecentMsg), pipelineSentimentAnnotationCache.get(str), pipelineSentimentAnnotationCache.get(mostRecentMsg), coreDocumentAnnotationCache.get(str), - coreDocumentAnnotationCache.get(mostRecentMsg)); + coreDocumentAnnotationCache.get(mostRecentMsg), cacheSentiment1, cacheSentiment2); SimilarityMatrix callSMX = null; try { callSMX = worker.call(); @@ -661,13 +693,15 @@ public class Datahandler { } return 0.0; } - + private Double getScoreRelationStrF(String str, String mostRecentMsg) { SimilarityMatrix SMX = new SimilarityMatrix(str, mostRecentMsg); + SentimentValueCache cacheSentiment1 = sentimentCachingMap.getOrDefault(str, null); + SentimentValueCache cacheSentiment2 = sentimentCachingMap.getOrDefault(mostRecentMsg, null); Callable worker = new SentimentAnalyzerTest(str, mostRecentMsg, SMX, strAnnoJMWE, jmweAnnotationCache.get(mostRecentMsg), strAnno, pipelineAnnotationCache.get(mostRecentMsg), strAnnoSentiment, - pipelineSentimentAnnotationCache.get(mostRecentMsg), coreDoc, coreDocumentAnnotationCache.get(mostRecentMsg)); + pipelineSentimentAnnotationCache.get(mostRecentMsg), coreDoc, coreDocumentAnnotationCache.get(mostRecentMsg), cacheSentiment1, cacheSentiment2); SimilarityMatrix callSMX = null; try { callSMX = worker.call(); @@ -681,7 +715,7 @@ public class Datahandler { } return 0.0; } - + public String mostSimilar(String toBeCompared, ConcurrentMap concurrentStrings, String MostRecent) { similar = ""; minDistance = 6.0; @@ -759,7 +793,7 @@ public class Datahandler { } return similar.isEmpty() ? null : similar; } - + public static ConcurrentMap cutContent(ConcurrentMap str, boolean hlStatsMsg) { ConcurrentMap returnlist = new MapMaker().concurrencyLevel(2).makeMap(); str.values().parallelStream().forEach(str1 -> { @@ -773,7 +807,7 @@ public class Datahandler { }); return returnlist; } - + public static ConcurrentMap filterContent(ConcurrentMap str) { ConcurrentMap strlistreturn = new MapMaker().concurrencyLevel(2).makeMap(); str.values().parallelStream().forEach(str1 -> { @@ -880,7 +914,7 @@ public class Datahandler { }); return strlistreturn; } - + private ConcurrentMap removeSlacks(ConcurrentMap str) { ConcurrentMap strreturn = new MapMaker().concurrencyLevel(2).makeMap(); if (stringCache.isEmpty()) { @@ -905,7 +939,7 @@ public class Datahandler { }); return strreturn; } - + private ConcurrentMap annotationCacheUpdate(ConcurrentMap strmap) { ConcurrentMap jmweAnnotation = PipelineJMWESingleton.INSTANCE.getJMWEAnnotation(strmap.values()); for (Entry jmweitr : jmweAnnotation.entrySet()) { @@ -943,18 +977,18 @@ public class Datahandler { }); return strmap; } - + private static class AnnotationCollector implements Consumer { - + private static int i = 0; private final List annotationsT = new ArrayList(); - + @Override public final void accept(T ann) { annotationsT.add(ann); } } - + public final static ConcurrentMap getMultipleCoreDocumentsWaySuggestion(Collection str, StanfordCoreNLP localNLP) { AnnotationCollector annCollector = new AnnotationCollector(); for (final String exampleString : str) { diff --git a/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java b/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java index 8c8c20da..7ec62657 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java @@ -5,22 +5,33 @@ */ package FunctionLayer; +import FunctionLayer.StanfordParser.SentimentValueCache; /** * * @author install1 */ -public class SimilarityMatrix{ +public class SimilarityMatrix { - private String PrimaryString; - private String SecondaryString; - private double distance; + private static String PrimaryString; + private static String SecondaryString; + private static double distance; + private static SentimentValueCache cacheValue1; + private static SentimentValueCache cacheValue2; - public double getDistance() { + public final SentimentValueCache getCacheValue2() { + return cacheValue2; + } + + public final void setCacheValue2(SentimentValueCache cacheValue2) { + SimilarityMatrix.cacheValue2 = cacheValue2; + } + + public final double getDistance() { return distance; } - public void setDistance(double distance) { + public final void setDistance(double distance) { this.distance = distance; } @@ -35,21 +46,28 @@ public class SimilarityMatrix{ this.distance = result; } - public String getPrimaryString() { + public final String getPrimaryString() { return PrimaryString; } - public void setPrimaryString(String PrimaryString) { + public final void setPrimaryString(String PrimaryString) { this.PrimaryString = PrimaryString; } - public String getSecondaryString() { + public final String getSecondaryString() { return SecondaryString; } - public void setSecondaryString(String SecondaryString) { + public final void setSecondaryString(String SecondaryString) { this.SecondaryString = SecondaryString; } + public final SentimentValueCache getCacheValue1() { + return cacheValue1; + } + + public final void setCacheValue1(SentimentValueCache cacheValue1) { + this.cacheValue1 = cacheValue1; + } } diff --git a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java index 4adf54e8..f7a3021e 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java @@ -16,7 +16,6 @@ import edu.stanford.nlp.ling.IndexedWord; import edu.stanford.nlp.ling.JMWEAnnotation; import edu.stanford.nlp.ling.TaggedWord; import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations; -import edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser; import edu.stanford.nlp.pipeline.Annotation; import edu.stanford.nlp.pipeline.CoreDocument; import edu.stanford.nlp.pipeline.CoreEntityMention; @@ -39,6 +38,7 @@ import edu.stanford.nlp.trees.tregex.gui.Tdiff; import edu.stanford.nlp.util.CoreMap; import edu.stanford.nlp.util.Pair; import java.io.StringReader; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -49,8 +49,6 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.BinaryOperator; -import java.util.function.Function; import org.apache.lucene.analysis.core.StopAnalyzer; import org.ejml.simple.SimpleMatrix; @@ -65,26 +63,36 @@ import org.ejml.simple.SimpleMatrix; */ public class SentimentAnalyzerTest implements Callable { - private SimilarityMatrix smxParam; - private String str; - private String str1; - private MaxentTagger tagger; - private GrammaticalStructureFactory gsf; - private StanfordCoreNLP pipeline; - private StanfordCoreNLP pipelineSentiment; - private AbstractSequenceClassifier classifier; - private Annotation jmweStrAnnotation1; - private Annotation jmweStrAnnotation2; - private Annotation pipelineAnnotation1; - private Annotation pipelineAnnotation2; - private Annotation pipelineAnnotation1Sentiment; - private Annotation pipelineAnnotation2Sentiment; - private CoreDocument pipelineCoreDcoument1; - private CoreDocument pipelineCoreDcoument2; + private final SimilarityMatrix smxParam; + private final String str; + private final String str1; + private final MaxentTagger tagger; + private final GrammaticalStructureFactory gsf; + private final StanfordCoreNLP pipeline; + private final StanfordCoreNLP pipelineSentiment; + private final AbstractSequenceClassifier classifier; + private final Annotation jmweStrAnnotation1; + private final Annotation jmweStrAnnotation2; + private final Annotation pipelineAnnotation1; + private final Annotation pipelineAnnotation2; + private final Annotation pipelineAnnotation1Sentiment; + private final Annotation pipelineAnnotation2Sentiment; + private final CoreDocument pipelineCoreDcoument1; + private final CoreDocument pipelineCoreDcoument2; + private static SentimentValueCache cacheSentiment1; + private static SentimentValueCache cacheSentiment2; + + public final SentimentValueCache getCacheSentiment1() { + return cacheSentiment1; + } + + public final SentimentValueCache getCacheSentiment2() { + return cacheSentiment2; + } public SentimentAnalyzerTest(String str, String str1, SimilarityMatrix smxParam, Annotation str1Annotation, Annotation str2Annotation, Annotation strPipeline1, Annotation strPipeline2, Annotation strPipeSentiment1, Annotation strPipeSentiment2, - CoreDocument pipelineCoreDcoument1, CoreDocument pipelineCoreDcoument2) { + CoreDocument pipelineCoreDcoument1, CoreDocument pipelineCoreDcoument2, SentimentValueCache cacheValue1, SentimentValueCache cacheValue2) { this.str = str; this.str1 = str1; this.smxParam = smxParam; @@ -101,1023 +109,1173 @@ public class SentimentAnalyzerTest implements Callable { this.pipelineAnnotation2Sentiment = strPipeSentiment2; this.pipelineCoreDcoument1 = pipelineCoreDcoument1; this.pipelineCoreDcoument2 = pipelineCoreDcoument2; + this.cacheSentiment1 = cacheValue1; + this.cacheSentiment2 = cacheValue2; + } + + private List> getTaggedWordList(String message) { + List> taggedwordlist = new ArrayList(); + DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(message)); + TokenizerFactory ptbTokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), "untokenizable=firstDelete"); //noneDelete + tokenizer.setTokenizerFactory(ptbTokenizerFactory); + for (final List sentence : tokenizer) { + taggedwordlist.add(tagger.tagSentence(sentence)); + } + return taggedwordlist; + } + + private int tokenizeCounting(List> taggedwordlist) { + int counter = 0; + return taggedwordlist.stream().map((taggedlist2) -> taggedlist2.size()).reduce(counter, Integer::sum); + } + + private ConcurrentMap retrieveTGWListIndex(List> taggedwordlist) { + ConcurrentMap tgwlistIndex = new MapMaker().concurrencyLevel(2).makeMap(); + taggedwordlist.forEach((TGWList) -> { + TGWList.forEach((TaggedWord) -> { + if (!tgwlistIndex.values().contains(TaggedWord.tag()) && !TaggedWord.tag().equals(":")) { + tgwlistIndex.put(tgwlistIndex.size() + 1, TaggedWord.tag()); + } + }); + }); + return tgwlistIndex; + } + + private final Double iterateTrees(ConcurrentMap sentenceConstituencyParseList2, ConcurrentMap sentenceConstituencyParseList1, Double score) { + for (final Tree sentenceConstituencyParse2 : sentenceConstituencyParseList2.values()) { + int constiRelationsize = 0; + for (final Tree sentenceConstituencyParse1 : sentenceConstituencyParseList1.values()) { + Set constinuent1 = Tdiff.markDiff(sentenceConstituencyParse1, sentenceConstituencyParse2); + Set constinuent2 = Tdiff.markDiff(sentenceConstituencyParse2, sentenceConstituencyParse1); + ConcurrentMap constiLabels = new MapMaker().concurrencyLevel(2).makeMap(); + for (final Constituent consti : constinuent1) { + for (final Constituent consti1 : constinuent2) { + if (consti.value().equals(consti1.value()) && !constiLabels.values().contains(consti.value())) { + constiLabels.put(constiLabels.size(), consti.value()); + constiRelationsize++; + } + } + } + int constituents1 = constinuent1.size() - constiRelationsize; + int constituents2 = constinuent2.size() - constiRelationsize; + if (constituents1 * 5 < constituents2 || constituents2 * 5 < constituents1) { + score -= (constituents1 + constituents2) * 200; + } else if (constituents1 == 0 || constituents2 == 0) { + score -= constiRelationsize * 200; + } else { + score += constiRelationsize * 160; + //System.out.println("score post constiRelationsize: " + score + "\nconstituents1: " + constituents1 + // + "\nconstituents2: " + constituents2 + "\nconstiRelationsize: " + constiRelationsize + "\n"); + } + } + } + return score; + } + + private Double typeDependenciesGrammaticalRelation(Collection allTypedDependencies1, Collection allTypedDependencies2, + Double score, ConcurrentMap grammaticalMap1, ConcurrentMap grammaticalMap2, + ConcurrentMap sentenceConstituencyParseList1, ConcurrentMap sentenceConstituencyParseList2) { + ConcurrentMap alltypeDepsSizeMap = new MapMaker().concurrencyLevel(2).makeMap(); + ConcurrentMap summationMap = new MapMaker().concurrencyLevel(2).makeMap(); + int relationApplicable1 = 0; + int relationApplicable2 = 0; + int grammaticalRelation1 = 0; + int grammaticalRelation2 = 0; + //believe in faith + for (TypedDependency TDY1 : allTypedDependencies1) { + IndexedWord dep = TDY1.dep(); + IndexedWord gov = TDY1.gov(); + for (GrammaticalStructure gs : grammaticalMap1.values()) { + GrammaticalRelation grammaticalRelation = gs.getGrammaticalRelation(gov, dep); + for (Tree sentenceConstituencyParse2 : sentenceConstituencyParseList2.values()) { + if (grammaticalRelation.isApplicable(sentenceConstituencyParse2)) { + score += 700; + //System.out.println("grammaticalRelation applicable score: " + score + "\n"); + grammaticalRelation1++; + } + GrammaticalRelation reln = TDY1.reln(); + //sentenceConstituencyParse1 + if (reln.isApplicable(sentenceConstituencyParse2)) { + score += 525; + relationApplicable1++; + } + } + } + } + for (TypedDependency TDY : allTypedDependencies2) { + IndexedWord dep = TDY.dep(); + IndexedWord gov = TDY.gov(); + for (GrammaticalStructure gs : grammaticalMap2.values()) { + GrammaticalRelation grammaticalRelation = gs.getGrammaticalRelation(gov, dep); + for (Tree sentenceConstituencyParse1 : sentenceConstituencyParseList1.values()) { + if (grammaticalRelation.isApplicable(sentenceConstituencyParse1)) { + score += 700; + //System.out.println("grammaticalRelation applicable score: " + score + "\n"); + grammaticalRelation2++; + } + GrammaticalRelation reln = TDY.reln(); + //sentenceConstituencyParse1 + if (reln.isApplicable(sentenceConstituencyParse1)) { + score += 525; + relationApplicable2++; + } + } + } + } + if ((grammaticalRelation1 == 0 && grammaticalRelation2 > 4) || (grammaticalRelation2 == 0 && grammaticalRelation1 > 4)) { + score -= 3450; + //System.out.println("grammaticalRelation1 score trim: " + score + "\ngrammaticalRelation1: " + grammaticalRelation1 + // + "\ngrammaticalRelation2: " + grammaticalRelation2 + "\n"); + } + if (!allTypedDependencies1.isEmpty() || !allTypedDependencies2.isEmpty()) { + int allTypeDep1 = allTypedDependencies1.size(); + int allTypeDep2 = allTypedDependencies2.size(); + if (allTypeDep1 <= allTypeDep2 * 5 && allTypeDep2 <= allTypeDep1 * 5) { + if (allTypeDep1 > 0 && allTypeDep2 > 0) { + if (allTypeDep1 * 2 <= allTypeDep2 || allTypeDep2 * 2 <= allTypeDep1) { + score -= allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 160 : (allTypeDep2 - allTypeDep1) * 160; + //System.out.println(" allTypeDep score: " + score + "\nallTypeDep1: " + allTypeDep1 + "\nallTypeDep2: " + // + allTypeDep2 + "\n"); + } else { + score += allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 600 : (allTypeDep2 - allTypeDep1) * 600; + //System.out.println(" allTypeDep score: " + score + "\nallTypeDep1: " + allTypeDep1 + "\nallTypeDep2: " + // + allTypeDep2 + "\n"); + } + alltypeDepsSizeMap.put(alltypeDepsSizeMap.size() + 1, allTypeDep1); + alltypeDepsSizeMap.put(alltypeDepsSizeMap.size() + 1, allTypeDep2); + } + } + if (allTypeDep1 >= 5 && allTypeDep2 >= 5) { + int largerTypeDep = allTypeDep1 > allTypeDep2 ? allTypeDep1 : allTypeDep2; + int smallerTypeDep = allTypeDep1 < allTypeDep2 ? allTypeDep1 : allTypeDep2; + int summation = (largerTypeDep * largerTypeDep) - (smallerTypeDep * smallerTypeDep); + if (summation / largerTypeDep < 15.0 && summation / largerTypeDep > 10.0 && smallerTypeDep * 2 > largerTypeDep + && !summationMap.values().contains(summation)) { + score += summation * 80; + summationMap.put(summationMap.size() + 1, summation); + //System.out.println("score post summation: " + score + "\nsummation: " + summation + "\n"); + } else if (largerTypeDep == smallerTypeDep) { + score += 2500; + //System.out.println("score largerTypeDep equals smallerTypeDep: " + score + "\nlargerTypeDep: " + largerTypeDep + "\n"); + } + } + if (relationApplicable1 > 0 && relationApplicable2 > 0 && relationApplicable1 == relationApplicable2 + && grammaticalRelation1 > 0 && grammaticalRelation2 > 0 && grammaticalRelation1 == grammaticalRelation2) { + score += 3500; + //System.out.println("score relationApplicable equal: " + score + "\n"); + } else if (allTypeDep1 * 5 < allTypeDep2 || allTypeDep2 * 5 < allTypeDep1) { + score -= allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * (allTypeDep2 * 450) + : (allTypeDep2 - allTypeDep1) * (allTypeDep1 * 450); + //System.out.println("score minus grammaticalRelation equal: " + score + "\n"); + } + if (relationApplicable1 > 1 && relationApplicable2 > 1 && relationApplicable1 * 3 > relationApplicable2 + && relationApplicable2 * 3 > relationApplicable1) { + score += relationApplicable1 > relationApplicable2 ? (relationApplicable1 - relationApplicable2) * 1500 + : (relationApplicable2 - relationApplicable1) * 1500; + //System.out.println("score relationApplicable plus: " + score + "\n"); + } else if (relationApplicable1 * 5 < relationApplicable2 || relationApplicable2 * 5 < relationApplicable1) { + score -= relationApplicable1 > relationApplicable2 ? (relationApplicable1 - relationApplicable2) * 500 + : (relationApplicable2 - relationApplicable1) * 500; + //System.out.println("score relationApplicable minus: " + score + "\n"); + } + if (grammaticalRelation1 > 0 && grammaticalRelation2 > 0 && grammaticalRelation1 * 3 > grammaticalRelation2 + && grammaticalRelation2 * 3 > grammaticalRelation1) { + score += grammaticalRelation1 > grammaticalRelation2 ? (grammaticalRelation1 - grammaticalRelation2) * 1500 + : (grammaticalRelation2 - grammaticalRelation1) * 1500; + //System.out.println("score grammaticalRelation plus: " + score + "\n"); + } else if (grammaticalRelation1 * 5 < grammaticalRelation2 || grammaticalRelation2 * 5 < grammaticalRelation1) { + score -= grammaticalRelation1 > grammaticalRelation2 ? (grammaticalRelation1 - grammaticalRelation2) * 500 + : (grammaticalRelation2 - grammaticalRelation1) * 500; + //System.out.println("score grammaticalRelation minus: " + score + "\n"); + } + //System.out.println("score post relationApplicable1 veri: " + score + "\nrelationApplicable1: " + relationApplicable1 + // + "\nrelationApplicable2: " + relationApplicable2 + "\ngrammaticalRelation1: " + grammaticalRelation1 + "\n" + // + "grammaticalRelation2: " + grammaticalRelation2 + "\n"); + } + ConcurrentMap filerTreeContent = new MapMaker().concurrencyLevel(2).makeMap(); + AtomicInteger runCount1 = new AtomicInteger(0); + for (Tree sentenceConstituencyParse1 : sentenceConstituencyParseList1.values()) { + for (Tree sentenceConstituencyParse2 : sentenceConstituencyParseList2.values()) { + sentenceConstituencyParse1.taggedLabeledYield().forEach((LBW) -> { + sentenceConstituencyParse2.taggedLabeledYield().stream().filter((LBW1) -> (LBW.lemma().equals(LBW1.lemma()) + && !filerTreeContent.values().contains(LBW.lemma()))).map((_item) -> { + filerTreeContent.put(filerTreeContent.size() + 1, LBW.lemma()); + return _item; + }).forEachOrdered((_item) -> { + runCount1.getAndIncrement(); + }); + }); + } + } + score += runCount1.get() * 250; + //System.out.println("score pre typeSizeSmallest: " + score + "\n"); + int typeSizeSmallest = 100; + int typeSizeLargest = 0; + for (Integer i : alltypeDepsSizeMap.values()) { + if (i > typeSizeLargest) { + typeSizeLargest = i; + } + if (i < typeSizeSmallest) { + typeSizeSmallest = i; + } + } + if (typeSizeLargest >= typeSizeSmallest * 3) { + score -= typeSizeLargest * 160; + } + typeSizeLargest = 0; + typeSizeSmallest = 100; + for (int i : summationMap.values()) { + if (i > typeSizeLargest) { + typeSizeLargest = i; + } + if (i < typeSizeSmallest) { + typeSizeSmallest = i; + } + } + if (typeSizeLargest >= typeSizeSmallest * 3) { + score -= typeSizeLargest * 160; + } + return score; + } + + private final Double simpleRNNMatrixCalculations(Double score, ConcurrentMap simpleSMXlist1, ConcurrentMap simpleSMXlist2) { + for (SimpleMatrix simpleSMX2 : simpleSMXlist2.values()) { + ConcurrentMap AccumulateDotMap = new MapMaker().concurrencyLevel(2).makeMap(); + ConcurrentMap subtractorMap = new MapMaker().concurrencyLevel(2).makeMap(); + ConcurrentMap dotPredictions = new MapMaker().concurrencyLevel(2).makeMap(); + ConcurrentMap DotOverTransfer = dotPredictions; + dotPredictions = new MapMaker().concurrencyLevel(2).makeMap(); + Double totalSubtraction = 0.0; + Double largest = 10.0; + Double shortest = 100.0; + for (SimpleMatrix simpleSMX1 : simpleSMXlist1.values()) { + double dotPrediction2 = simpleSMX2.dot(simpleSMX1) * 100; + double dotPrediction1 = simpleSMX1.dot(simpleSMX2) * 100; + AccumulateDotMap.put(AccumulateDotMap.size() + 1, dotPrediction1); + AccumulateDotMap.put(AccumulateDotMap.size() + 1, dotPrediction2); + double subtracter1 = dotPrediction1 > 50 ? dotPrediction1 - 100 : dotPrediction1 > 0 ? 100 - dotPrediction1 : 0; + double subtracter2 = dotPrediction2 > 50 ? dotPrediction2 - 100 : dotPrediction2 > 0 ? 100 - dotPrediction2 : 0; + subtractorMap.put(subtractorMap.size() + 1, subtracter1); + subtractorMap.put(subtractorMap.size() + 1, subtracter2); + //System.out.println("dotPrediction: " + dotPrediction + "\nsubtracter: " + subtracter + "\n"); + if (!dotPredictions.values().contains(dotPrediction1)) { + for (Double transferDots : DotOverTransfer.values()) { + if (transferDots == dotPrediction1) { + totalSubtraction += transferDots; + } else { + score -= subtracter1 * 25; + //System.out.println("score minus subtracter: " + score + "\nsubtracter: " + subtracter + "\n"); + } + //System.out.println("transferDots: " + transferDots + "\n"); + } + } else { + subtracter1 -= 100; + subtracter1 *= 25; + score -= subtracter1 * dotPrediction1; + //System.out.println("score minus subtracter * dotPrediction 2: " + score + "\ndotPrediction: " + // + dotPrediction + "\n"); + } + dotPredictions.put(dotPredictions.size() + 1, dotPrediction1); + if (!dotPredictions.values().contains(dotPrediction2)) { + if (dotPrediction2 > largest) { + largest = dotPrediction2; + } + if (dotPrediction2 < shortest) { + shortest = dotPrediction2; + } + Double dotPredictionIntervalDifference = largest - shortest; + subtracter2 *= 25; + //System.out.println("subtracter: " + subtracter + "\n"); + if (dotPredictionIntervalDifference < 5.0) { + if (dotPredictions.values().size() > 0) { + if (subtracter2 > 0) { + score -= subtracter2; + } else { + score += subtracter2; + //System.out.println("score + subtracter: " + score + "\nsubtracter: " + subtracter + "\n"); + } + } + } else { + score -= subtracter2 / 10; + } + } else { + subtracter2 -= 100; + subtracter2 *= 25; + score += subtracter2 * dotPrediction2; + //System.out.println("score + subtracter * dotPrediction: " + score + "\nsubtracter: " + subtracter + "\ndotPrediction: " + //+ dotPrediction + "\n"); + } + dotPredictions.put(dotPredictions.size() + 1, dotPrediction2); + } + //System.out.println("score post subtracter1: " + score + "\n"); + Double subTracPre = 0.0; + for (Double subtractors : subtractorMap.values()) { + if (Objects.equals(subTracPre, subtractors)) { + score -= 1500; + //System.out.println("score minus subTracPre equals: " + score + "\nsubTracPre: " + subTracPre + "\n"); + } + subTracPre = subtractors; + } + if (totalSubtraction > 45.0) { + score -= totalSubtraction * 25; + } else { + score += totalSubtraction * 25; + } + //System.out.println("score post totalSubtraction: " + score + "\ntotalSubtraction: " + totalSubtraction + "\n"); + Double preAccumulatorDot = 0.0; + Double postAccumulatorDot = 0.0; + for (Double accumulators : AccumulateDotMap.values()) { + if (Objects.equals(preAccumulatorDot, accumulators)) { + if (Objects.equals(postAccumulatorDot, accumulators)) { + score -= 1400; + } + postAccumulatorDot = accumulators; + } + preAccumulatorDot = accumulators; + } + subTracPre = 0.0; + for (Double subtractors : subtractorMap.values()) { + if (Objects.equals(subTracPre, subtractors)) { + score -= 500; + } + subTracPre = subtractors; + } + } + return score; + } + + private final Double simpleRNNMaxtrixVectors(Double score, ConcurrentMap simpleSMXlistVector1, ConcurrentMap simpleSMXlistVector2) { + final ConcurrentMap elementSumCounter = new MapMaker().concurrencyLevel(3).makeMap(); + final ConcurrentMap dotMap = new MapMaker().concurrencyLevel(3).makeMap(); + final ConcurrentMap elementSumMap = new MapMaker().concurrencyLevel(3).makeMap(); + final ConcurrentMap dotSumMap = new MapMaker().concurrencyLevel(3).makeMap(); + Double preDot = 0.0; + Double postDot = 0.0; + for (SimpleMatrix simpleSMX2 : simpleSMXlistVector2.values()) { + for (SimpleMatrix simpleSMX1 : simpleSMXlistVector1.values()) { + double dot2 = simpleSMX2.dot(simpleSMX1); + double elementSum2 = simpleSMX2.kron(simpleSMX1).elementSum(); + double dot1 = simpleSMX1.dot(simpleSMX2); + double elementSum1 = simpleSMX1.kron(simpleSMX2).elementSum(); + if (preDot == dot2) { + if (postDot == dot2) { + score -= 500; + } + postDot = dot2; + } + if (preDot == dot1) { + if (postDot == dot1) { + score -= 500; + } + postDot = dot1; + } + preDot = dot1; + elementSum1 = Math.round(elementSum1 * 100.0) / 100.0; + elementSumCounter.put(elementSumCounter.size() + 1, elementSum1); + dotMap.put(dotMap.size() + 1, dot1); + preDot = dot2; + elementSum2 = Math.round(elementSum2 * 100.0) / 100.0; + elementSumCounter.put(elementSumCounter.size() + 1, elementSum2); + dotMap.put(dotMap.size() + 1, dot2); + if (!dotSumMap.values().contains(dot1)) { + if (dot1 < 0.1) { + score += 256; + //System.out.println("score dot < 0.1: " + score + "\ndot: " + // + dot + "\n"); + } + if (dot1 > 0.50) { + score -= 1400; + } + dotSumMap.put(dotSumMap.size() + 1, dot1); + } else { + score -= 250; + } + if (!elementSumMap.values().contains(elementSum1)) { + if (elementSum1 < 0.01 && elementSum1 > 0.00) { + score += 1300; + //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " + // + elementSum + "\n"); + } else if (elementSum1 > 0.1 && elementSum1 < 1.0) { + score += 1100; + //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " + // + elementSum + "\n"); + } else { + score -= elementSum1 * 1024; + } + elementSumMap.put(elementSumMap.size() + 1, elementSum1); + } else { + score -= 250; + } + if (!dotSumMap.values().contains(dot2)) { + if (dot2 < 0.000) { + score += dot2 * 500; + //System.out.println("score + dot * 500: " + score + "\ndot: " + dot + "\n"); + } else if (dot2 < 0.1) { + score += 256; + //System.out.println("score + 256: " + score + "\ndot: " + dot + " 0.50) { + score -= 1200; + } + dotSumMap.put(dotSumMap.size() + 1, dot2); + } else { + score -= 250; + } + if (!elementSumMap.values().contains(elementSum2)) { + if (elementSum2 < 0.01 && elementSum2 > 0.00) { + score += 3300; + //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " + // + elementSum + "\n"); + } else if (elementSum2 > 0.1 && elementSum2 < 0.2) { + score += 1100; + //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " + // + elementSum + "\n"); + } else { + score -= elementSum2 * 1024; + } + elementSumMap.put(elementSumMap.size() + 1, elementSum2); + } else { + score -= 250; + } + } + } + score = elementsAndDotsRelation(score, dotMap, elementSumCounter); + return score; + } + + private final Double elementsAndDotsRelation(Double score, ConcurrentMap dotMap, ConcurrentMap elementSumCounter) { + //System.out.println("score post sentiment analyzer2: " + score + "\n"); + OptionalDouble minvalueDots = dotMap.values().stream().mapToDouble(Double::doubleValue).min(); + OptionalDouble maxvalueDots = dotMap.values().stream().mapToDouble(Double::doubleValue).max(); + double total = minvalueDots.getAsDouble() + maxvalueDots.getAsDouble(); + boolean permitted = false; + if (minvalueDots.getAsDouble() != maxvalueDots.getAsDouble()) { + permitted = true; + } + if (permitted) { + Double dotsVariance = maxvalueDots.getAsDouble() - minvalueDots.getAsDouble(); + //System.out.println("maxvalueDots.getAsDouble():" + maxvalueDots.getAsDouble() + "\nminvalueDots.getAsDouble():" + // + minvalueDots.getAsDouble() + "\ndotsVariance: " + dotsVariance + "\n"); + if (maxvalueDots.getAsDouble() > minvalueDots.getAsDouble() * 10) { + score -= 5500; + } else if (minvalueDots.getAsDouble() < -0.10) { + score -= 3500; + } else if (dotsVariance < 0.5 && dotsVariance > 0.1) { + score -= 3500; + } else if (dotsVariance > minvalueDots.getAsDouble() * 2) { + score += 3500; + //System.out.println("varians 4 score. " + score + "\n"); + } else if (minvalueDots.getAsDouble() * 3 > maxvalueDots.getAsDouble() && maxvalueDots.getAsDouble() < 0.1001) { + score += dotsVariance * 200000; + } + } + //System.out.println("score post dotsVariance: " + score + "\n"); + OptionalDouble minvalueElements = elementSumCounter.values().stream().mapToDouble(Double::doubleValue).min(); + OptionalDouble maxvalueElements = elementSumCounter.values().stream().mapToDouble(Double::doubleValue).max(); + Double elementsVariance = maxvalueElements.getAsDouble() - minvalueElements.getAsDouble(); + //System.out.println("elementsVariance: " + elementsVariance + "\nmaxvalueElements.getAsDouble(): " + // + maxvalueElements.getAsDouble() + "\nminvalueElements.getAsDouble(): " + minvalueElements.getAsDouble() + "\n"); + if (elementsVariance == 0.0) { + score -= 550; + } else if (elementsVariance < 0.02 && elementsVariance > -0.01) { + score += 3500; + } else if (minvalueElements.getAsDouble() < 0.0 && minvalueElements.getAsDouble() - maxvalueElements.getAsDouble() < 0.50) { + score -= 2500; + } else if (elementsVariance * 2 >= maxvalueElements.getAsDouble() && elementsVariance < 0.1) { + score -= elementsVariance * 86000; + } + return score; + } + + private final Double sentimentMatrixVariances(Double score, int longest1, int longest2, int mainSentiment1, int mainSentiment2) { + //System.out.println("score post pipelineAnnotation2Sentiment: " + score + "\n"); + if (longest1 != longest2) { + long deffLongest = longest1 > longest2 ? longest1 : longest2; + long deffshorter = longest1 < longest2 ? longest1 : longest2; + if (deffLongest > deffshorter * 5) { + score -= 5500; + } else if (deffLongest < (deffshorter * 2) - 1 && deffLongest - deffshorter <= 45) { + score += (deffLongest - deffshorter) * 20; + } else if (mainSentiment1 != mainSentiment2 && deffLongest - deffshorter > 20 && deffLongest - deffshorter < 45) { + score += (deffLongest - deffshorter) * 20; + } else if (deffLongest - deffshorter < 2) { + score += (deffLongest - deffshorter) * 20; + } else if (deffshorter * 2 >= deffLongest && deffshorter * 2 < deffLongest + 5) { + score += (deffLongest - deffshorter) * 20; + } else { + score -= (deffLongest - deffshorter) * 50; + } + if (deffLongest - deffshorter <= 5) { + score += 250; + } + } + return score; + } + + private final Map.Entry> classifyRawEvaluation(Double score, SentimentValueCache cacheSentimentLocal1, + SentimentValueCache cacheSentimentLocal2) { + if (cacheSentiment1 == null || cacheSentiment2 == null) { + DocumentReaderAndWriter readerAndWriter = classifier.makePlainTextReaderAndWriter(); + if (cacheSentiment1 == null) { + cacheSentimentLocal1.setClassifyRaw(classifier.classifyRaw(str, readerAndWriter)); + } + if (cacheSentiment2 == null) { + cacheSentimentLocal2.setClassifyRaw(classifier.classifyRaw(str1, readerAndWriter)); + } + } + final List classifyRaw1 = cacheSentiment1 == null ? cacheSentimentLocal1.getClassifyRaw() : cacheSentiment1.getClassifyRaw(); + final List classifyRaw2 = cacheSentiment2 == null ? cacheSentimentLocal2.getClassifyRaw() : cacheSentiment2.getClassifyRaw(); + score -= (classifyRaw1.size() > classifyRaw2.size() ? classifyRaw1.size() - classifyRaw2.size() : classifyRaw2.size() - classifyRaw1.size()) * 200; + Map.Entry< Double, Map.Entry> entry + = new AbstractMap.SimpleEntry(score, new AbstractMap.SimpleEntry(cacheSentimentLocal1, cacheSentimentLocal2)); + return entry; + } + + private final Double entryCountsRelation(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int entry1 = cacheSentiment1 == null ? cacheSentimentLocal1.getEntryCounts().values().size() : cacheSentiment1.getEntryCounts().values().size(); + int entry2 = cacheSentiment2 == null ? cacheSentimentLocal2.getEntryCounts().values().size() : cacheSentiment2.getEntryCounts().values().size(); + //System.out.println("score post JMWEAnnotation: " + score + "\nentry1: " + entry1 + "\nentry2: " + entry2 + "\n"); + if (entry1 > 0 && entry2 > 0) { + if ((entry1 >= entry2 * 5) || (entry2 >= entry1 * 5)) { + score -= entry1 > entry2 ? (entry1 - entry2) * 450 : (entry2 - entry1) * 450; + //System.out.println("1"); + } else if ((entry1 >= entry2 * 50 || entry2 >= entry1 * 50)) { + score -= entry1 > entry2 ? entry1 * 180 : entry2 * 180; + //System.out.println("2"); + } else if (entry1 >= entry2 * 2 || entry2 >= entry1 * 2) { + score += entry1 > entry2 ? (entry1 - entry2) * 450 : (entry2 - entry1) * 450; + //System.out.println("3"); + } else if (entry1 > 10 && entry2 > 10 && entry1 * 2 > entry2 && entry2 * 2 > entry1) { + score += entry1 > entry2 ? entry2 * 600 : entry1 * 600; + //System.out.println("6"); + } + } + return score; + } + + private SentimentValueCache GrammaticStructureSetup(SentimentValueCache cacheSentimentLocal, Annotation pipelineAnnotation) { + for (CoreMap sentence : pipelineAnnotation.get(CoreAnnotations.SentencesAnnotation.class)) { + Tree sentenceConstituencyParse = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); + cacheSentimentLocal.addSentenceConstituencyParse(sentenceConstituencyParse); + GrammaticalStructure gs = gsf.newGrammaticalStructure(sentenceConstituencyParse); + cacheSentimentLocal.addTypedDependencies(gs.allTypedDependencies()); + cacheSentimentLocal.addGS(gs); + } + return cacheSentimentLocal; + } + + private SentimentValueCache initializeCacheSetup(String str, SentimentValueCache cacheSentimentLocal) { + cacheSentimentLocal = new SentimentValueCache(str); + cacheSentimentLocal.setTaggedwords(getTaggedWordList(str)); + cacheSentimentLocal.setCounter(tokenizeCounting(cacheSentimentLocal.getTaggedwordlist())); + return cacheSentimentLocal; + } + + private SentimentValueCache sentimentCoreAnnotationSetup(Annotation pipelineAnnotationSentiment, SentimentValueCache cacheSentimentLocal) { + for (CoreMap sentence : pipelineAnnotationSentiment.get(CoreAnnotations.SentencesAnnotation.class)) { + Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); + int predictedClass = RNNCoreAnnotations.getPredictedClass(tree); + SimpleMatrix predictions = RNNCoreAnnotations.getPredictions(tree); + SimpleMatrix nodeVector = RNNCoreAnnotations.getNodeVector(tree); + try { + cacheSentimentLocal.addRNNPredictClass(predictedClass); + cacheSentimentLocal.addSimpleMatrix(predictions); + cacheSentimentLocal.addSimpleMatrixVector(nodeVector); + } catch (Exception ex) { + System.out.println("ex: " + ex.getLocalizedMessage() + "\n"); + } + } + return cacheSentimentLocal; + } + + private SentimentValueCache setupMainSentimentandLongestVal(Annotation pipelineAnnotationSentiment, SentimentValueCache cacheSentimentLocal) { + for (CoreMap sentence : pipelineAnnotationSentiment.get(CoreAnnotations.SentencesAnnotation.class)) { + Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); + int sentiment = RNNCoreAnnotations.getPredictedClass(tree); + String partText = sentence.toString(); + //SimpleMatrix predictions = RNNCoreAnnotations.getPredictions(tree); + if (partText.length() > cacheSentimentLocal.getLongest()) { + cacheSentimentLocal.setMainSentiment(sentiment); + cacheSentimentLocal.setLongest(partText.length()); + } + } + return cacheSentimentLocal; + } + + private SentimentValueCache jmweAnnotationSetup(Annotation jmweStrAnnotation, SentimentValueCache cacheSentimentLocal) { + List sentences = jmweStrAnnotation.get(CoreAnnotations.SentencesAnnotation.class); + for (CoreMap sentence : sentences) { + for (IMWE token : sentence.get(JMWEAnnotation.class)) { + if (token.isInflected()) { + cacheSentimentLocal.setInflectedCounterPositive(cacheSentimentLocal.getInflectedCounterPositive() + 1); + } else { + cacheSentimentLocal.setInflectedCounterNegative(cacheSentimentLocal.getInflectedCounterNegative() + 1); + } + cacheSentimentLocal.addstrTokenForm(token.getForm()); + cacheSentimentLocal.addstrTokenGetEntry(token.getEntry().toString().substring(token.getEntry().toString().length() - 1)); + Collection values = token.getPartMap().values(); + IMWEDesc entry = token.getEntry(); + cacheSentimentLocal.setMarkedContinuousCounter(cacheSentimentLocal.getMarkedContinuousCounter() + entry.getMarkedContinuous()); + cacheSentimentLocal.setUnmarkedPatternCounter(cacheSentimentLocal.getUnmarkedPatternCounter() + entry.getUnmarkedPattern()); + for (IMWEDesc.IPart iPart : values) { + cacheSentimentLocal.addstrTokenGetiPart(iPart.getForm()); + } + for (String strPostPrefix : entry.getPOS().getPrefixes()) { + cacheSentimentLocal.addstrTokenEntryPOS(strPostPrefix); + } + for (int counts : entry.getCounts()) { + cacheSentimentLocal.addEntryCounts(counts); + } + for (IToken tokens : token.getTokens()) { + cacheSentimentLocal.addITokenMapTag(tokens.getTag()); + for (String strtoken : tokens.getStems()) { + cacheSentimentLocal.addstrTokenStems(strtoken); + cacheSentimentLocal.setMarkedContiniousCounterEntries(cacheSentimentLocal.getMarkedContiniousCounterEntries() + 1); + } + } + cacheSentimentLocal.setTokensCounter(cacheSentimentLocal.getTokensCounter() + 1); + } + cacheSentimentLocal.setAnotatorcounter(cacheSentimentLocal.getAnotatorcounter() + 1); + } + return cacheSentimentLocal; + } + + private Double entryCountsScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + ConcurrentMap countsMap = new MapMaker().concurrencyLevel(2).makeMap(); + for (int counts : cacheSentimentLocal1.getEntryCounts().values()) { + for (int counts1 : cacheSentimentLocal2.getEntryCounts().values()) { + if (counts == counts1 && counts > 0 && !countsMap.values().contains(counts)) { + score += counts * 250; + //System.out.println("score post counts: " + score + "\nCounts: " + counts + "\n"); + countsMap.put(countsMap.size() + 1, counts); + } + } + } + return score; + } + + private Double tokenEntryPosScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + if (cacheSentimentLocal1.getstrTokenEntryPOS().values().size() > 1 && cacheSentimentLocal2.getstrTokenEntryPOS().values().size() > 1) { + for (String strTokenPos1 : cacheSentimentLocal1.getstrTokenEntryPOS().values()) { + for (String strTokenPos2 : cacheSentimentLocal2.getstrTokenEntryPOS().values()) { + if (strTokenPos1.equals(strTokenPos2)) { + score += 500; + } else { + score -= 650; + //System.out.println("strTokenEntryPOS score: " + score + "\n"); + } + } + } + } + return score; + } + + private Double unmarkedPatternCounterScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int UnmarkedPatternCounter1 = cacheSentimentLocal1.getUnmarkedPatternCounter(); + int UnmarkedPatternCounter2 = cacheSentimentLocal2.getUnmarkedPatternCounter(); + if (UnmarkedPatternCounter1 > 0 && UnmarkedPatternCounter2 > 0) { + if (UnmarkedPatternCounter1 * 2 > UnmarkedPatternCounter2 && UnmarkedPatternCounter2 * 2 > UnmarkedPatternCounter1) { + score += 2500; + } else if (UnmarkedPatternCounter1 * 5 < UnmarkedPatternCounter2 || UnmarkedPatternCounter2 * 5 < UnmarkedPatternCounter1) { + score -= 4000; + } + } + return score; + } + + private Double markedContiniousCounterScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int MarkedContinuousCounter1 = cacheSentimentLocal1.getMarkedContinuousCounter(); + int MarkedContinuousCounter2 = cacheSentimentLocal2.getMarkedContinuousCounter(); + int MarkedContiniousCounter1Entries = cacheSentimentLocal1.getMarkedContiniousCounterEntries(); + int MarkedContiniousCounter2Entries = cacheSentimentLocal2.getMarkedContiniousCounterEntries(); + if (MarkedContinuousCounter1 > 0 && MarkedContinuousCounter2 > 0) { + if (MarkedContinuousCounter1 > MarkedContinuousCounter2 * 50 || MarkedContinuousCounter2 > MarkedContinuousCounter1 * 50) { + score -= MarkedContinuousCounter1 > MarkedContinuousCounter2 ? MarkedContinuousCounter1 * 120 : MarkedContinuousCounter2 * 120; + //System.out.println("score post MarkedContinuousCounter too big: " + score + "\n"); + } else if (!Objects.equals(MarkedContiniousCounter1Entries, MarkedContiniousCounter2Entries) + && (MarkedContinuousCounter1 * 2 >= MarkedContinuousCounter2 * MarkedContinuousCounter1) + || (MarkedContinuousCounter2 * 2 >= MarkedContinuousCounter1 * MarkedContinuousCounter2)) { + score += 4500; + } else if (MarkedContiniousCounter1Entries == 0 || MarkedContiniousCounter2Entries == 0) { + score += MarkedContinuousCounter1 > MarkedContinuousCounter2 ? (MarkedContinuousCounter2 - MarkedContinuousCounter1) * 500 + : (MarkedContinuousCounter1 - MarkedContinuousCounter2) * 500; + } + if (MarkedContiniousCounter1Entries > 0 && MarkedContiniousCounter2Entries > 0 && MarkedContinuousCounter1 > 0 + && MarkedContinuousCounter2 > 0 && MarkedContinuousCounter1 < MarkedContinuousCounter2 * 10 + && MarkedContinuousCounter2 < MarkedContinuousCounter1 * 10) { + if (MarkedContiniousCounter1Entries > MarkedContiniousCounter2Entries * 5 + || MarkedContiniousCounter2Entries > MarkedContiniousCounter1Entries * 5 + || MarkedContiniousCounter1Entries * 5 < MarkedContinuousCounter1 + || MarkedContiniousCounter1Entries * 5 < MarkedContinuousCounter2 + || MarkedContiniousCounter2Entries * 5 < MarkedContinuousCounter1 + || MarkedContiniousCounter2Entries * 5 < MarkedContinuousCounter2) { + score -= MarkedContinuousCounter1 > MarkedContinuousCounter2 ? MarkedContinuousCounter1 * 400 : MarkedContinuousCounter2 * 400; + //System.out.println("score post MarkedContinuousCounter: " + score + "\n"); + } + } + } + return score; + } + + private Double strTokensMapScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + ConcurrentMap strtokensMap = new MapMaker().concurrencyLevel(2).makeMap(); + for (String strTokeniPart1 : cacheSentimentLocal1.getstrTokenGetiPart().values()) { + for (String strTokeniPart2 : cacheSentimentLocal2.getstrTokenGetiPart().values()) { + if (strTokeniPart1.equals(strTokeniPart2) && !strtokensMap.values().contains(strTokeniPart2)) { + strtokensMap.put(strtokensMap.size() + 1, strTokeniPart2); + score += 400; + } else { + score -= 200; + //System.out.println("score minus strTokenGetiPart: " + score + "\n"); + } + } + } + return score; + } + + private Double strTokenEntryScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int tokenEntry1 = cacheSentimentLocal1.getstrTokenGetEntry().values().size(); + int tokenEntry2 = cacheSentimentLocal2.getstrTokenGetEntry().values().size(); + boolean boundaryLeaks = false; + int remnantCounter = 0; + if (tokenEntry1 * 2 != tokenEntry2 && tokenEntry2 * 2 != tokenEntry1) { + boundaryLeaks = true; + } + ConcurrentMap entryTokenMap = new MapMaker().concurrencyLevel(2).makeMap(); + for (String strTokenEntry1 : cacheSentimentLocal1.getstrTokenGetEntry().values()) { + for (String strTokenEntry2 : cacheSentimentLocal2.getstrTokenGetEntry().values()) { + if (!entryTokenMap.values().contains(strTokenEntry2)) { + if (strTokenEntry1.equals(strTokenEntry2)) { + score += boundaryLeaks ? 2500 : 2500 / 2; + } else if (!boundaryLeaks) { + score -= 450; + //System.out.println("boundariyLeacks score: " + score + "\n"); + } else { + remnantCounter++; + } + } + entryTokenMap.put(entryTokenMap.size() + 1, strTokenEntry2); + } + } + //System.out.println("score pre remnantCounter: " + score + "\n"); + score += remnantCounter * 250; + return score; + } + + private Double strTokenMapTagsScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + ConcurrentMap iTokenMapTagsMap = new MapMaker().concurrencyLevel(2).makeMap(); + for (String strmapTag : cacheSentimentLocal1.getITokenMapTag().values()) { + for (String strmapTag1 : cacheSentimentLocal2.getITokenMapTag().values()) { + if (strmapTag.equals(strmapTag1)) { + score -= 1450; + } else if (!iTokenMapTagsMap.values().contains(strmapTag)) { + score += 725; + iTokenMapTagsMap.put(iTokenMapTagsMap.size() + 1, strmapTag); + } + } + } + return score; + } + + private Double tokenformSizeScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int tokenform1size = cacheSentimentLocal1.getstrTokenForm().values().size(); + int tokenform2size = cacheSentimentLocal2.getstrTokenForm().values().size(); + if (tokenform1size > 0 || tokenform2size > 0) { + if (tokenform1size < tokenform2size * 5 && tokenform2size < tokenform1size * 5) { + for (String strTokenForm1itr1 : cacheSentimentLocal1.getstrTokenForm().values()) { + for (String strTokenForm1itr2 : cacheSentimentLocal2.getstrTokenForm().values()) { + if (strTokenForm1itr1.equals(strTokenForm1itr2)) { + score -= 1600; + } else { + score += 500; + //System.out.println("tokenform1size score500: " + score + "\n"); + } + } + } + } else if (tokenform1size > 0 && tokenform2size > 0) { + if (tokenform1size * 2 >= tokenform2size && tokenform2size * 2 >= tokenform1size) { + score += tokenform1size > tokenform2size ? tokenform1size * 600 : tokenform2size * 600; + } else if (tokenform1size * 4 <= tokenform2size || tokenform2size * 4 <= tokenform1size) { + score -= tokenform1size > tokenform2size ? (tokenform1size - tokenform2size) * 600 : (tokenform2size - tokenform1size) * 600; + } + //System.out.println("tokenform1size score: " + score + "\ntokenform1size: " + tokenform1size + "\ntokenform2size: " + // + tokenform2size + "\n"); + } + } + return score; + } + + private Double tokenStemmingMapScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + ConcurrentMap tokenStemmingMap = new MapMaker().concurrencyLevel(2).makeMap(); + for (String strTokenStem : cacheSentimentLocal1.getstrTokenStems().values()) { + for (String strTokenStem1 : cacheSentimentLocal2.getstrTokenStems().values()) { + if (strTokenStem.equals(strTokenStem1) && !tokenStemmingMap.values().contains(strTokenStem)) { + score += 1500; + tokenStemmingMap.put(tokenStemmingMap.size() + 1, strTokenStem); + } + //System.out.println("score strTokenStem: " + score + "\n"); + } + } + return score; + } + + private Double inflectedCounterScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int inflectedCounterPositive1 = cacheSentimentLocal1.getInflectedCounterPositive(); + int inflectedCounterPositive2 = cacheSentimentLocal2.getInflectedCounterPositive(); + int inflectedCounterNegative = cacheSentimentLocal1.getInflectedCounterNegative() + cacheSentimentLocal2.getInflectedCounterNegative(); + //System.out.println("inflectedCounterPositive1: " + inflectedCounterPositive1 + "\ninflectedCounterPositive2: " + // + inflectedCounterPositive2 + "\ninflectedCounterNegative: " + inflectedCounterNegative + "\n"); + if (inflectedCounterPositive1 + inflectedCounterPositive2 > inflectedCounterNegative && inflectedCounterNegative > 0) { + score += ((inflectedCounterPositive1 + inflectedCounterPositive2) - inflectedCounterNegative) * 650; + //System.out.println("score inflectedCounterPositive plus: " + score + "\n"); + } + if (inflectedCounterPositive1 > 0 && inflectedCounterPositive2 > 0) { + if (inflectedCounterPositive1 * 2 > inflectedCounterPositive2 && inflectedCounterPositive2 * 2 > inflectedCounterPositive1) { + score += ((inflectedCounterPositive1 + inflectedCounterPositive2) - inflectedCounterNegative) * 550; + //System.out.println("score plus inflectedCounterPositive * 2: " + score + "\n"); + } else if (inflectedCounterPositive1 * 5 < inflectedCounterPositive2 || inflectedCounterPositive2 * 5 < inflectedCounterPositive1) { + score -= inflectedCounterPositive1 > inflectedCounterPositive2 ? (inflectedCounterPositive1 - inflectedCounterPositive2) * 400 + : (inflectedCounterPositive2 - inflectedCounterPositive1) * 400; + //System.out.println("score minus inflectedCounterPositive * 2: " + score + "\n"); + } + } + return score; + } + + private Double annotatorCountScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int anotatorcounter1 = cacheSentimentLocal1.getAnotatorcounter(); + int anotatorcounter2 = cacheSentimentLocal2.getAnotatorcounter(); + //System.out.println("anotatorcounter1: " + anotatorcounter1 + "\nanotatorcounter2: " + anotatorcounter2 + "\n"); + if (anotatorcounter1 > 1 && anotatorcounter2 > 1) { + if (anotatorcounter1 * 2 > anotatorcounter2 && anotatorcounter2 * 2 > anotatorcounter1) { + score += anotatorcounter1 > anotatorcounter2 ? (anotatorcounter1 - anotatorcounter2) * 700 + : (anotatorcounter2 - anotatorcounter1) * 700; + //System.out.println("score plus anotatorcounter: " + score + "\n"); + } else if (anotatorcounter1 * 5 < anotatorcounter2 || anotatorcounter2 * 5 < anotatorcounter1) { + score -= anotatorcounter1 > anotatorcounter2 ? (anotatorcounter1 - anotatorcounter2) * 400 : (anotatorcounter2 - anotatorcounter1) * 400; + //System.out.println("score minus anotatorcounter: " + score + "\n"); + } + } + return score; + } + + private Double tokensCounterScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + int tokensCounter1 = cacheSentimentLocal1.getTokensCounter(); + int tokensCounter2 = cacheSentimentLocal2.getTokensCounter(); + //System.out.println("tokensCounter1: " + tokensCounter1 + "\ntokensCounter2: " + tokensCounter2 + "\n"); + if ((tokensCounter1 > 1 && tokensCounter2 > 1) && tokensCounter1 < tokensCounter2 * 5 && tokensCounter2 < tokensCounter1 * 5) { + if (tokensCounter1 > tokensCounter2 / 2 && tokensCounter2 > tokensCounter1 / 2) { + score += (tokensCounter1 + tokensCounter2) * 1400; + //System.out.println("score plus tokensCounter: " + score + "\n"); + } else { + score -= 3500; + //System.out.println("score minus tokensCounter: " + score + "\n"); + } + } else { + int elseint = tokensCounter1 >= tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500; + //System.out.println("elseint: " + elseint + " tokensCounter2 * 5 || tokensCounter2 > tokensCounter1 * 5) + && tokensCounter1 > 0 && tokensCounter2 > 0) { + score -= tokensCounter1 > tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500; + //System.out.println("score post tokensCounter: " + score + "\n"); + } else if (elseint > 0 && tokensCounter1 > 0 && tokensCounter2 > 0) { + score -= elseint * 2; + //System.out.println("score post elseint: " + elseint + "\n"); + } + } + return score; + } + + private SentimentValueCache setupNEREntitiesAndTokenTags(CoreDocument pipelineCoreDcoument, SentimentValueCache cacheSentimentLocal) { + for (CoreEntityMention em : pipelineCoreDcoument.entityMentions()) { + Set> entrySet = em.entityTypeConfidences().entrySet(); + String entityType = em.entityType(); + Double EntityConfidences = 0.0; + for (Map.Entry entries : entrySet) { + EntityConfidences = entries.getValue(); + } + List tokens = em.tokens(); + for (CoreLabel token : tokens) { + try { + if (!cacheSentimentLocal.getnerEntityTokenTags().values().contains(token.tag())) { + if (entityType.equals("PERSON") && EntityConfidences > 0.80) { + cacheSentimentLocal.addnerEntityTokenTags(token.tag()); + } + } + } catch (Exception ex) { + //System.out.println("failed corelabel ex: " + ex.getLocalizedMessage() + "\n" + ex.getCause() + "\n"); + } + } + if (!cacheSentimentLocal.getnerEntities1().values().contains(em.text())) { + cacheSentimentLocal.addNEREntities1(em.text()); + cacheSentimentLocal.addNEREntities2(em.entityType()); + } + } + return cacheSentimentLocal; + } + + private Double nerEntitiesAndTokenScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + for (String strEnts1 : cacheSentimentLocal1.getnerEntities1().values()) { + Collection values = cacheSentimentLocal2.getnerEntities1().values(); + for (String strEnts2 : values) { + if (strEnts1.equalsIgnoreCase(strEnts2)) { + score += 2500; + //System.out.println("score strEnts1 plus: " + score + "\n"); + } else { + score -= 150; + } + } + } + for (String strEnts1 : cacheSentimentLocal1.getnerEntities2().values()) { + if (cacheSentimentLocal2.getnerEntities2().values().contains(strEnts1)) { + score -= 1500; + //System.out.println("score nerEntities4 minus: " + score + "\n"); + } else { + score -= 150; + } + } + for (String strToken : cacheSentimentLocal1.getnerEntityTokenTags().values()) { + if (cacheSentimentLocal2.getnerEntityTokenTags().values().contains(strToken)) { + score += 2000; + //System.out.println("score nerEntities4 plus: " + score + "\n"); + } else { + score -= 150; + } + } + return score; + } + + private SentimentValueCache setupStoWordTokensLemma(Annotation pipelineAnnotationSentiment, SentimentValueCache cacheSentimentLocal) { + String customStopWordList = "start,starts,period,periods,a,an,and,are,as,at,be,but,by,for,if,in,into,is,it,no,not,of,on,or,such,that,the,their,then,there,these,they,this,to,was,will,with"; + List tokensSentiment = pipelineAnnotationSentiment.get(CoreAnnotations.TokensAnnotation.class); + Set stopWords = StopAnalyzer.ENGLISH_STOP_WORDS_SET; + Set stopWordsCustom = StopwordAnnotator.getStopWordList(customStopWordList, true); + for (CoreLabel token : tokensSentiment) { + Pair stopword = token.get(StopwordAnnotator.class); + String word = token.word().toLowerCase(); + if (stopWords.contains(word) || stopWordsCustom.contains(word)) { + cacheSentimentLocal.addstopwordTokens(word); + } + String lemma = token.lemma().toLowerCase(); + if (stopWords.contains(lemma) || stopWordsCustom.contains(lemma)) { + cacheSentimentLocal.addStopWordLemma(lemma); + } + if (stopword.first() && stopword.second()) { + cacheSentimentLocal.setPairCounter(cacheSentimentLocal.getPairCounter() + 1); + } + //System.out.println("stopword Pair: " + stopword.first() + " " + stopword.second() + "\nword: " + // + word + "\nlemma: " + lemma + "\n"); + } + return cacheSentimentLocal; + } + + private Double stopWordTokenLemmaScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + for (String stopwords1 : cacheSentimentLocal1.getStopwordTokens().values()) { + for (String stopwords2 : cacheSentimentLocal2.getStopwordTokens().values()) { + if (stopwords1.equals(stopwords2)) { + score -= 500; + //System.out.println("score stopwordsToken: " + score + "\n"); + } + } + } + for (String stopwords1 : cacheSentimentLocal1.getStopWordLemma().values()) { + for (String stopwords2 : cacheSentimentLocal2.getStopWordLemma().values()) { + if (stopwords1.equals(stopwords2)) { + score -= 500; + //System.out.println("score stopwords Lemma: " + score + "\n"); + } + } + } + return score; + } + + private Double stopwordTokenPairCounterScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + if (!cacheSentimentLocal1.getStopwordTokens().values().isEmpty() && !cacheSentimentLocal2.getStopwordTokens().values().isEmpty()) { + int stopwordsize1 = cacheSentimentLocal1.getStopwordTokens().values().size(); + int stopwordsize2 = cacheSentimentLocal2.getStopwordTokens().values().size(); + if (stopwordsize1 * 5 < stopwordsize2 || stopwordsize2 * 5 < stopwordsize1) { + score -= stopwordsize1 > stopwordsize2 ? (stopwordsize1 - stopwordsize2) * 850 : (stopwordsize2 - stopwordsize1) * 850; + } else { + score += stopwordsize1 > stopwordsize2 ? (stopwordsize1 - stopwordsize2) * 850 : (stopwordsize2 - stopwordsize1) * 850;; + } + //System.out.println("score post stopwordsize: " + score + "\nstopwordsize1: " + stopwordsize1 + "\nstopwordsize2: " + // + stopwordsize2 + "\n"); + } + int pairCounter1 = cacheSentimentLocal1.getPairCounter(); + int pairCounter2 = cacheSentimentLocal2.getPairCounter(); + if (pairCounter1 > 0 && pairCounter2 > 0) { + if (pairCounter1 * 3 <= pairCounter2 || pairCounter2 * 3 <= pairCounter1) { + score -= pairCounter1 > pairCounter2 ? (pairCounter1 - pairCounter2) * 1500 : (pairCounter2 - pairCounter1) * 1500; + } else { + score += pairCounter1 > pairCounter2 ? (pairCounter1 - pairCounter2) * 700 : (pairCounter2 - pairCounter1) * 700; + } + //System.out.println("score post pairCounter: " + score + "\npairCounter1: " + pairCounter1 + "\npairCounter2: " + pairCounter2 + "\n"); + } + return score; + } + + private Double tgwListScoreIncrementer(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + AtomicInteger runCount = new AtomicInteger(0); + cacheSentimentLocal1.getTgwlistIndex().values().forEach(TaggedWord -> { + if (!cacheSentimentLocal2.getTgwlistIndex().values().contains(TaggedWord)) { + cacheSentimentLocal2.addTgwlistIndex(TaggedWord); + runCount.getAndIncrement(); + } + }); + score += runCount.get() * 64; + return score; } @Override - public SimilarityMatrix call() { + public final SimilarityMatrix call() { Double score = -100.0; - try { - List> taggedwordlist1 = new ArrayList(); - List> taggedwordlist2 = new ArrayList(); - DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(str1)); - //noneDelete - TokenizerFactory ptbTokenizerFactory - = PTBTokenizer.factory(new CoreLabelTokenFactory(), "untokenizable=firstDelete"); - tokenizer.setTokenizerFactory(ptbTokenizerFactory); - for (List sentence : tokenizer) { - taggedwordlist1.add(tagger.tagSentence(sentence)); - //taggedwordlist1.add(model.apply(tagger.tagSentence(sentence)).taggedYield()); - } - tokenizer = new DocumentPreprocessor(new StringReader(str)); - tokenizer.setTokenizerFactory(ptbTokenizerFactory); - for (List sentence : tokenizer) { - taggedwordlist2.add(tagger.tagSentence(sentence)); - //taggedwordlist2.add(model.apply(tagger.tagSentence(sentence)).taggedYield()); - } - int counter = 0; - int counter1 = 0; - counter = taggedwordlist2.stream().map((taggedlist2) -> taggedlist2.size()).reduce(counter, Integer::sum); - counter1 = taggedwordlist1.stream().map((taggedlist1) -> taggedlist1.size()).reduce(counter1, Integer::sum); - int overValue = counter >= counter1 ? counter - counter1 : counter1 - counter; - overValue *= 32; - score -= overValue; - ConcurrentMap tgwlistIndex = new MapMaker().concurrencyLevel(2).makeMap(); - taggedwordlist1.forEach((TGWList) -> { - TGWList.forEach((TaggedWord) -> { - if (!tgwlistIndex.values().contains(TaggedWord.tag()) && !TaggedWord.tag().equals(":")) { - tgwlistIndex.put(tgwlistIndex.size() + 1, TaggedWord.tag()); - } - }); - }); - AtomicInteger runCount = new AtomicInteger(0); - taggedwordlist2.forEach((TGWList) -> { - TGWList.forEach((TaggedWord) -> { - if (tgwlistIndex.values().contains(TaggedWord.tag())) { - tgwlistIndex.values().remove(TaggedWord.tag()); - runCount.getAndIncrement(); - } - }); - }); - score += runCount.get() * 64; - ////System.out.println("score post runCountGet: " + score + "\n"); - ConcurrentMap sentenceConstituencyParseList = new MapMaker().concurrencyLevel(2).makeMap(); - try { - for (CoreMap sentence : pipelineAnnotation1.get(CoreAnnotations.SentencesAnnotation.class)) { - Tree sentenceConstituencyParse = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); - sentenceConstituencyParseList.put(sentenceConstituencyParseList.size(), sentenceConstituencyParse); - } - ConcurrentMap alltypeDepsSizeMap = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap summationMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (CoreMap sentence : pipelineAnnotation2.get(CoreAnnotations.SentencesAnnotation.class)) { - int constiRelationsize = 0; - Tree sentenceConstituencyParse = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); - GrammaticalStructure gs = gsf.newGrammaticalStructure(sentenceConstituencyParse); - Collection allTypedDependencies = gs.allTypedDependencies(); - ConcurrentMap filerTreeContent = new MapMaker().concurrencyLevel(2).makeMap(); - for (Tree sentenceConstituencyParse1 : sentenceConstituencyParseList.values()) { - Set constinuent1 = Tdiff.markDiff(sentenceConstituencyParse, sentenceConstituencyParse1); - Set constinuent2 = Tdiff.markDiff(sentenceConstituencyParse1, sentenceConstituencyParse); - ConcurrentMap constiLabels = new MapMaker().concurrencyLevel(2).makeMap(); - for (Constituent consti : constinuent1) { - for (Constituent consti1 : constinuent2) { - if (consti.value().equals(consti1.value()) && !constiLabels.values().contains(consti.value())) { - constiLabels.put(constiLabels.size(), consti.value()); - constiRelationsize++; - } - } - } - int constituents1 = constinuent1.size() - constiRelationsize; - int constituents2 = constinuent2.size() - constiRelationsize; - if (constituents1 * 5 < constituents2 || constituents2 * 5 < constituents1) { - score -= (constituents1 + constituents2) * 200; - } else if (constituents1 == 0 || constituents2 == 0) { - score -= constiRelationsize * 200; - } else { - score += constiRelationsize * 160; - //System.out.println("score post constiRelationsize: " + score + "\nconstituents1: " + constituents1 - // + "\nconstituents2: " + constituents2 + "\nconstiRelationsize: " + constiRelationsize + "\n"); - } - GrammaticalStructure gs1 = gsf.newGrammaticalStructure(sentenceConstituencyParse1); - Collection allTypedDependencies1 = gs1.allTypedDependencies(); - int relationApplicable1 = 0; - int relationApplicable2 = 0; - int grammaticalRelation1 = 0; - int grammaticalRelation2 = 0; - for (TypedDependency TDY1 : allTypedDependencies1) { - IndexedWord dep = TDY1.dep(); - IndexedWord gov = TDY1.gov(); - GrammaticalRelation grammaticalRelation = gs.getGrammaticalRelation(gov, dep); - if (grammaticalRelation.isApplicable(sentenceConstituencyParse)) { - score += 700; - //System.out.println("grammaticalRelation applicable score: " + score + "\n"); - grammaticalRelation1++; - } - GrammaticalRelation reln = TDY1.reln(); - if (reln.isApplicable(sentenceConstituencyParse)) { - score += 525; - relationApplicable1++; - } - } - for (TypedDependency TDY : allTypedDependencies) { - IndexedWord dep = TDY.dep(); - IndexedWord gov = TDY.gov(); - GrammaticalRelation grammaticalRelation = gs1.getGrammaticalRelation(gov, dep); - if (grammaticalRelation.isApplicable(sentenceConstituencyParse)) { - score += 900; - //System.out.println("grammaticalRelation appliceable score: " + score + "\n"); - grammaticalRelation2++; - } - GrammaticalRelation reln = TDY.reln(); - if (reln.isApplicable(sentenceConstituencyParse1)) { - score += 525; - //System.out.println("reln appliceable score: " + score + "\n"); - relationApplicable2++; - } - } - if ((grammaticalRelation1 == 0 && grammaticalRelation2 > 4) || (grammaticalRelation2 == 0 && grammaticalRelation1 > 4)) { - score -= 3450; - //System.out.println("grammaticalRelation1 score trim: " + score + "\ngrammaticalRelation1: " + grammaticalRelation1 - // + "\ngrammaticalRelation2: " + grammaticalRelation2 + "\n"); - } - if (!allTypedDependencies.isEmpty() || !allTypedDependencies1.isEmpty()) { - int allTypeDep1 = allTypedDependencies.size(); - int allTypeDep2 = allTypedDependencies1.size(); - if (allTypeDep1 <= allTypeDep2 * 5 && allTypeDep2 <= allTypeDep1 * 5) { - if (allTypeDep1 > 0 && allTypeDep2 > 0) { - if (allTypeDep1 * 2 <= allTypeDep2 || allTypeDep2 * 2 <= allTypeDep1) { - score -= allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 160 : (allTypeDep2 - allTypeDep1) * 160; - //System.out.println(" allTypeDep score: " + score + "\nallTypeDep1: " + allTypeDep1 + "\nallTypeDep2: " - // + allTypeDep2 + "\n"); - } else { - score += allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 600 : (allTypeDep2 - allTypeDep1) * 600; - //System.out.println(" allTypeDep score: " + score + "\nallTypeDep1: " + allTypeDep1 + "\nallTypeDep2: " - // + allTypeDep2 + "\n"); - } - alltypeDepsSizeMap.put(alltypeDepsSizeMap.size() + 1, allTypeDep1); - alltypeDepsSizeMap.put(alltypeDepsSizeMap.size() + 1, allTypeDep2); - } - } - if (allTypeDep1 >= 5 && allTypeDep2 >= 5) { - int largerTypeDep = allTypeDep1 > allTypeDep2 ? allTypeDep1 : allTypeDep2; - int smallerTypeDep = allTypeDep1 < allTypeDep2 ? allTypeDep1 : allTypeDep2; - int summation = (largerTypeDep * largerTypeDep) - (smallerTypeDep * smallerTypeDep); - if (summation / largerTypeDep < 15.0 && summation / largerTypeDep > 10.0 && smallerTypeDep * 2 > largerTypeDep - && !summationMap.values().contains(summation)) { - score += summation * 80; - summationMap.put(summationMap.size() + 1, summation); - //System.out.println("score post summation: " + score + "\nsummation: " + summation + "\n"); - } else if (largerTypeDep == smallerTypeDep) { - score += 2500; - //System.out.println("score largerTypeDep equals smallerTypeDep: " + score + "\nlargerTypeDep: " + largerTypeDep + "\n"); - } - } - if (relationApplicable1 > 0 && relationApplicable2 > 0 && relationApplicable1 == relationApplicable2 - && grammaticalRelation1 > 0 && grammaticalRelation2 > 0 && grammaticalRelation1 == grammaticalRelation2) { - score += 3500; - //System.out.println("score relationApplicable equal: " + score + "\n"); - } else if (allTypeDep1 * 5 < allTypeDep2 || allTypeDep2 * 5 < allTypeDep1) { - score -= allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * (allTypeDep2 * 450) - : (allTypeDep2 - allTypeDep1) * (allTypeDep1 * 450); - //System.out.println("score minus grammaticalRelation equal: " + score + "\n"); - } - if (relationApplicable1 > 1 && relationApplicable2 > 1 && relationApplicable1 * 3 > relationApplicable2 - && relationApplicable2 * 3 > relationApplicable1) { - score += relationApplicable1 > relationApplicable2 ? (relationApplicable1 - relationApplicable2) * 1500 - : (relationApplicable2 - relationApplicable1) * 1500; - //System.out.println("score relationApplicable plus: " + score + "\n"); - } else if (relationApplicable1 * 5 < relationApplicable2 || relationApplicable2 * 5 < relationApplicable1) { - score -= relationApplicable1 > relationApplicable2 ? (relationApplicable1 - relationApplicable2) * 500 - : (relationApplicable2 - relationApplicable1) * 500; - //System.out.println("score relationApplicable minus: " + score + "\n"); - } - if (grammaticalRelation1 > 0 && grammaticalRelation2 > 0 && grammaticalRelation1 * 3 > grammaticalRelation2 - && grammaticalRelation2 * 3 > grammaticalRelation1) { - score += grammaticalRelation1 > grammaticalRelation2 ? (grammaticalRelation1 - grammaticalRelation2) * 1500 - : (grammaticalRelation2 - grammaticalRelation1) * 1500; - //System.out.println("score grammaticalRelation plus: " + score + "\n"); - } else if (grammaticalRelation1 * 5 < grammaticalRelation2 || grammaticalRelation2 * 5 < grammaticalRelation1) { - score -= grammaticalRelation1 > grammaticalRelation2 ? (grammaticalRelation1 - grammaticalRelation2) * 500 - : (grammaticalRelation2 - grammaticalRelation1) * 500; - //System.out.println("score grammaticalRelation minus: " + score + "\n"); - } - //System.out.println("score post relationApplicable1 veri: " + score + "\nrelationApplicable1: " + relationApplicable1 - // + "\nrelationApplicable2: " + relationApplicable2 + "\ngrammaticalRelation1: " + grammaticalRelation1 + "\n" - // + "grammaticalRelation2: " + grammaticalRelation2 + "\n"); - } - AtomicInteger runCount1 = new AtomicInteger(0); - sentenceConstituencyParse.taggedLabeledYield().forEach((LBW) -> { - sentenceConstituencyParse1.taggedLabeledYield().stream().filter((LBW1) -> (LBW.lemma().equals(LBW1.lemma()) - && !filerTreeContent.values().contains(LBW.lemma()))).map((_item) -> { - filerTreeContent.put(filerTreeContent.size() + 1, LBW.lemma()); - return _item; - }).forEachOrdered((_item) -> { - runCount1.getAndIncrement(); - }); - }); - score += runCount1.get() * 250; - } - } - //System.out.println("score pre typeSizeSmallest: " + score + "\n"); - int typeSizeSmallest = 100; - int typeSizeLargest = 0; - for (Integer i : alltypeDepsSizeMap.values()) { - if (i > typeSizeLargest) { - typeSizeLargest = i; - } - if (i < typeSizeSmallest) { - typeSizeSmallest = i; - } - } - if (typeSizeLargest >= typeSizeSmallest * 3) { - score -= typeSizeLargest * 160; - } - typeSizeLargest = 0; - typeSizeSmallest = 100; - for (int i : summationMap.values()) { - if (i > typeSizeLargest) { - typeSizeLargest = i; - } - if (i < typeSizeSmallest) { - typeSizeSmallest = i; - } - } - if (typeSizeLargest >= typeSizeSmallest * 3) { - score -= typeSizeLargest * 160; - } - } catch (Exception ex) { - //System.out.println("pipelineAnnotation stacktrace: " + ex.getLocalizedMessage() + "\n"); - } - sentenceConstituencyParseList.clear(); - ConcurrentMap simpleSMXlist = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap simpleSMXlistVector = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap sentiment1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap sentiment2 = new MapMaker().concurrencyLevel(2).makeMap(); - for (CoreMap sentence : pipelineAnnotation1Sentiment.get(CoreAnnotations.SentencesAnnotation.class)) { - Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); - sentiment1.put(sentiment1.size(), RNNCoreAnnotations.getPredictedClass(tree)); - SimpleMatrix predictions = RNNCoreAnnotations.getPredictions(tree); - SimpleMatrix nodeVector = RNNCoreAnnotations.getNodeVector(tree); - simpleSMXlist.put(simpleSMXlist.size(), predictions); - simpleSMXlistVector.put(simpleSMXlistVector.size() + 1, nodeVector); - } - ConcurrentMap elementSumCounter = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap dotMap = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap elementSumMap = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap dotSumMap = new MapMaker().concurrencyLevel(2).makeMap(); - //System.out.println("score pre pipelineAnnotation2Sentiment: " + score + "\n"); - for (CoreMap sentence : pipelineAnnotation2Sentiment.get(CoreAnnotations.SentencesAnnotation.class)) { - Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); - sentiment2.put(sentiment2.size() + 1, RNNCoreAnnotations.getPredictedClass(tree)); - SimpleMatrix predictions = RNNCoreAnnotations.getPredictions(tree); - SimpleMatrix nodeVector = RNNCoreAnnotations.getNodeVector(tree); - ConcurrentMap AccumulateDotMap = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap subtractorMap = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap dotPredictions = new MapMaker().concurrencyLevel(2).makeMap(); - Double largest = 10.0; - Double shortest = 100.0; - for (SimpleMatrix simpleSMX : simpleSMXlist.values()) { - double dotPrediction = predictions.dot(simpleSMX) * 100; - AccumulateDotMap.put(AccumulateDotMap.size() + 1, dotPrediction); - double subtracter = dotPrediction > 50 ? dotPrediction - 100 : dotPrediction > 0 ? 100 - dotPrediction : 0; - subtractorMap.put(subtractorMap.size() + 1, subtracter); - if (!dotPredictions.values().contains(dotPrediction)) { - if (dotPrediction > largest) { - largest = dotPrediction; - } - if (dotPrediction < shortest) { - shortest = dotPrediction; - } - Double dotPredictionIntervalDifference = largest - shortest; - subtracter *= 25; - //System.out.println("subtracter: " + subtracter + "\n"); - if (dotPredictionIntervalDifference < 5.0) { - if (dotPredictions.values().size() > 0) { - if (subtracter > 0) { - score -= subtracter; - } else { - score += subtracter; - //System.out.println("score + subtracter: " + score + "\nsubtracter: " + subtracter + "\n"); - } - } - } else { - score -= subtracter / 10; - } - } else { - subtracter -= 100; - subtracter *= 25; - score += subtracter * dotPrediction; - //System.out.println("score + subtracter * dotPrediction: " + score + "\nsubtracter: " + subtracter + "\ndotPrediction: " - //+ dotPrediction + "\n"); - } - dotPredictions.put(dotPredictions.size() + 1, dotPrediction); - } - //System.out.println("score post subtracter1: " + score + "\n"); - Double subTracPre = 0.0; - for (Double subtractors : subtractorMap.values()) { - if (Objects.equals(subTracPre, subtractors)) { - score -= 1500; - //System.out.println("score minus subTracPre equals: " + score + "\nsubTracPre: " + subTracPre + "\n"); - } - subTracPre = subtractors; - } - ConcurrentMap DotOverTransfer = dotPredictions; - dotPredictions = new MapMaker().concurrencyLevel(2).makeMap(); - Double totalSubtraction = 0.0; - for (SimpleMatrix simpleSMX : simpleSMXlist.values()) { - double dotPrediction = simpleSMX.dot(predictions) * 100; - AccumulateDotMap.put(AccumulateDotMap.size() + 1, dotPrediction); - double subtracter = dotPrediction > 50 ? dotPrediction - 100 : dotPrediction > 0 ? 100 - dotPrediction : 0; - //System.out.println("dotPrediction: " + dotPrediction + "\nsubtracter: " + subtracter + "\n"); - subtractorMap.put(subtractorMap.size() + 1, subtracter); - if (!dotPredictions.values().contains(dotPrediction)) { - for (Double transferDots : DotOverTransfer.values()) { - if (transferDots == dotPrediction) { - totalSubtraction += transferDots; - } else { - score -= subtracter * 25; - //System.out.println("score minus subtracter: " + score + "\nsubtracter: " + subtracter + "\n"); - } - //System.out.println("transferDots: " + transferDots + "\n"); - } - } else { - subtracter -= 100; - subtracter *= 25; - score -= subtracter * dotPrediction; - //System.out.println("score minus subtracter * dotPrediction 2: " + score + "\ndotPrediction: " - // + dotPrediction + "\n"); - } - dotPredictions.put(dotPredictions.size() + 1, dotPrediction); - } - if (totalSubtraction > 45.0) { - score -= totalSubtraction * 25; - } else { - score += totalSubtraction * 25; - } - //System.out.println("score post totalSubtraction: " + score + "\ntotalSubtraction: " + totalSubtraction + "\n"); - Double preAccumulatorDot = 0.0; - Double postAccumulatorDot = 0.0; - for (Double accumulators : AccumulateDotMap.values()) { - if (Objects.equals(preAccumulatorDot, accumulators)) { - if (Objects.equals(postAccumulatorDot, accumulators)) { - score -= 1400; - } - postAccumulatorDot = accumulators; - } - preAccumulatorDot = accumulators; - } - subTracPre = 0.0; - for (Double subtractors : subtractorMap.values()) { - if (Objects.equals(subTracPre, subtractors)) { - score -= 500; - } - subTracPre = subtractors; - } - Double preDot = 0.0; - Double postDot = 0.0; - for (SimpleMatrix simpleSMX : simpleSMXlistVector.values()) { - double dot = nodeVector.dot(simpleSMX); - double elementSum = nodeVector.kron(simpleSMX).elementSum(); - if (preDot == dot) { - if (postDot == dot) { - score -= 500; - } - postDot = dot; - } - preDot = dot; - elementSum = Math.round(elementSum * 100.0) / 100.0; - elementSumCounter.put(elementSumCounter.size() + 1, elementSum); - dotMap.put(dotMap.size() + 1, dot); - if (!dotSumMap.values().contains(dot)) { - if (dot < 0.000) { - score += dot * 500; - //System.out.println("score + dot * 500: " + score + "\ndot: " + dot + "\n"); - } else if (dot < 0.1) { - score += 256; - //System.out.println("score + 256: " + score + "\ndot: " + dot + " 0.50) { - score -= 1200; - } - dotSumMap.put(dotSumMap.size() + 1, dot); - } else { - score -= 250; - } - if (!elementSumMap.values().contains(elementSum)) { - if (elementSum < 0.01 && elementSum > 0.00) { - score += 3300; - //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " - // + elementSum + "\n"); - } else if (elementSum > 0.1 && elementSum < 0.2) { - score += 1100; - //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " - // + elementSum + "\n"); - } else { - score -= elementSum * 1024; - } - elementSumMap.put(elementSumMap.size() + 1, elementSum); - } else { - score -= 250; - } - } - for (SimpleMatrix simpleSMX : simpleSMXlistVector.values()) { - double dot = simpleSMX.dot(nodeVector); - double elementSum = simpleSMX.kron(nodeVector).elementSum(); - if (preDot == dot) { - if (postDot == dot) { - score -= 500; - } - postDot = dot; - } - preDot = dot; - elementSum = Math.round(elementSum * 100.0) / 100.0; - elementSumCounter.put(elementSumCounter.size() + 1, elementSum); - dotMap.put(dotMap.size() + 1, dot); - if (!dotSumMap.values().contains(dot)) { - if (dot < 0.1) { - score += 256; - //System.out.println("score dot < 0.1: " + score + "\ndot: " - // + dot + "\n"); - } - if (dot > 0.50) { - score -= 1400; - } - dotSumMap.put(dotSumMap.size() + 1, dot); - } else { - score -= 250; - } - if (!elementSumMap.values().contains(elementSum)) { - if (elementSum < 0.01 && elementSum > 0.00) { - score += 1300; - //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " - // + elementSum + "\n"); - } else if (elementSum > 0.1 && elementSum < 1.0) { - score += 1100; - //System.out.println("score elementSum < 0.01 && elementSum > 0.00: " + score + "\nelementSum: " - // + elementSum + "\n"); - } else { - score -= elementSum * 1024; - } - elementSumMap.put(elementSumMap.size() + 1, elementSum); - } else { - score -= 250; - } - } - } - //System.out.println("score post sentiment analyzer2: " + score + "\n"); - OptionalDouble minvalueDots = dotMap.values().stream().mapToDouble(Double::doubleValue).min(); - OptionalDouble maxvalueDots = dotMap.values().stream().mapToDouble(Double::doubleValue).max(); - double total = minvalueDots.getAsDouble() + maxvalueDots.getAsDouble(); - boolean permitted = false; - if (minvalueDots.getAsDouble() != maxvalueDots.getAsDouble()) { - permitted = true; - } - if (permitted) { - Double dotsVariance = maxvalueDots.getAsDouble() - minvalueDots.getAsDouble(); - //System.out.println("maxvalueDots.getAsDouble():" + maxvalueDots.getAsDouble() + "\nminvalueDots.getAsDouble():" - // + minvalueDots.getAsDouble() + "\ndotsVariance: " + dotsVariance + "\n"); - if (maxvalueDots.getAsDouble() > minvalueDots.getAsDouble() * 10) { - score -= 5500; - } else if (minvalueDots.getAsDouble() < -0.10) { - score -= 3500; - } else if (dotsVariance < 0.5 && dotsVariance > 0.1) { - score -= 3500; - } else if (dotsVariance > minvalueDots.getAsDouble() * 2) { - score += 3500; - //System.out.println("varians 4 score. " + score + "\n"); - } else if (minvalueDots.getAsDouble() * 3 > maxvalueDots.getAsDouble() && maxvalueDots.getAsDouble() < 0.1001) { - score += dotsVariance * 200000; - } - } - //System.out.println("score post dotsVariance: " + score + "\n"); - OptionalDouble minvalueElements = elementSumCounter.values().stream().mapToDouble(Double::doubleValue).min(); - OptionalDouble maxvalueElements = elementSumCounter.values().stream().mapToDouble(Double::doubleValue).max(); - Double elementsVariance = maxvalueElements.getAsDouble() - minvalueElements.getAsDouble(); - //System.out.println("elementsVariance: " + elementsVariance + "\nmaxvalueElements.getAsDouble(): " - // + maxvalueElements.getAsDouble() + "\nminvalueElements.getAsDouble(): " + minvalueElements.getAsDouble() + "\n"); - if (elementsVariance == 0.0) { - score -= 550; - } else if (elementsVariance < 0.02 && elementsVariance > -0.01) { - score += 3500; - } else if (minvalueElements.getAsDouble() < 0.0 && minvalueElements.getAsDouble() - maxvalueElements.getAsDouble() < 0.50) { - score -= 2500; - } else if (elementsVariance * 2 >= maxvalueElements.getAsDouble() && elementsVariance < 0.1) { - score -= elementsVariance * 86000; - } - //System.out.println("score post elementsVariance: " + score + "\n"); - score -= (sentiment1.size() > sentiment2.size() ? sentiment1.size() - sentiment2.size() : sentiment2.size() - sentiment1.size()) * 500; - DocumentReaderAndWriter readerAndWriter = classifier.makePlainTextReaderAndWriter(); - List classifyRaw1 = classifier.classifyRaw(str, readerAndWriter); - List classifyRaw2 = classifier.classifyRaw(str1, readerAndWriter); - score -= (classifyRaw1.size() > classifyRaw2.size() ? classifyRaw1.size() - classifyRaw2.size() : classifyRaw2.size() - classifyRaw1.size()) * 200; - //System.out.println("score post classifyRaw: " + score + "\n"); - int mainSentiment1 = 0; - int longest1 = 0; - int mainSentiment2 = 0; - int longest2 = 0; - for (CoreMap sentence : pipelineAnnotation1Sentiment.get(CoreAnnotations.SentencesAnnotation.class)) { - Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); - int sentiment = RNNCoreAnnotations.getPredictedClass(tree); - String partText = sentence.toString(); - SimpleMatrix predictions = RNNCoreAnnotations.getPredictions(tree); - if (partText.length() > longest1) { - mainSentiment1 = sentiment; - longest1 = partText.length(); - } - } - for (CoreMap sentence : pipelineAnnotation2Sentiment.get(CoreAnnotations.SentencesAnnotation.class)) { - Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); - int sentiment = RNNCoreAnnotations.getPredictedClass(tree); - SimpleMatrix predictions = RNNCoreAnnotations.getPredictions(tree); - String partText = sentence.toString(); - if (partText.length() > longest2) { - mainSentiment2 = sentiment; - longest2 = partText.length(); - } - } - //System.out.println("score post pipelineAnnotation2Sentiment: " + score + "\n"); - if (longest1 != longest2) { - long deffLongest = longest1 > longest2 ? longest1 : longest2; - long deffshorter = longest1 < longest2 ? longest1 : longest2; - if (deffLongest > deffshorter * 5) { - score -= 5500; - } else if (deffLongest < (deffshorter * 2) - 1 && deffLongest - deffshorter <= 45) { - score += (deffLongest - deffshorter) * 20; - } else if (mainSentiment1 != mainSentiment2 && deffLongest - deffshorter > 20 && deffLongest - deffshorter < 45) { - score += (deffLongest - deffshorter) * 20; - } else if (deffLongest - deffshorter < 2) { - score += (deffLongest - deffshorter) * 20; - } else if (deffshorter * 2 >= deffLongest && deffshorter * 2 < deffLongest + 5) { - score += (deffLongest - deffshorter) * 20; - } else { - score -= (deffLongest - deffshorter) * 50; - } - if (deffLongest - deffshorter <= 5) { - score += 250; - } - } - int tokensCounter1 = 0; - int tokensCounter2 = 0; - int anotatorcounter1 = 0; - int anotatorcounter2 = 0; - int inflectedCounterPositive1 = 0; - int inflectedCounterPositive2 = 0; - int inflectedCounterNegative = 0; - int MarkedContinuousCounter1 = 0; - int MarkedContinuousCounter2 = 0; - Integer MarkedContiniousCounter1Entries = 0; - Integer MarkedContiniousCounter2Entries = 0; - int UnmarkedPatternCounter1 = 0; - int UnmarkedPatternCounter2 = 0; - ConcurrentMap ITokenMapTag1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap ITokenMapTag2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenStems1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenStems2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenForm1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenForm2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenGetEntry1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenGetEntry2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenGetiPart1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenGetiPart2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenEntryPOS1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap strTokenEntryPOS2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap entryCounts1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap entryCounts2 = new MapMaker().concurrencyLevel(2).makeMap(); - try { - List sentences = jmweStrAnnotation1.get(CoreAnnotations.SentencesAnnotation.class); - for (CoreMap sentence : sentences) { - for (IMWE token : sentence.get(JMWEAnnotation.class)) { - if (token.isInflected()) { - inflectedCounterPositive1++; - } else { - inflectedCounterNegative++; - } - strTokenForm1.put(strTokenForm1.size() + 1, token.getForm()); - strTokenGetEntry1.put(strTokenGetEntry1.size() + 1, token.getEntry().toString().substring(token.getEntry().toString().length() - 1)); - Collection values = token.getPartMap().values(); - IMWEDesc entry = token.getEntry(); - MarkedContinuousCounter1 += entry.getMarkedContinuous(); - UnmarkedPatternCounter1 += entry.getUnmarkedPattern(); - for (IMWEDesc.IPart iPart : values) { - strTokenGetiPart1.put(strTokenGetiPart1.size() + 1, iPart.getForm()); - } - for (String strPostPrefix : entry.getPOS().getPrefixes()) { - strTokenEntryPOS1.put(strTokenEntryPOS1.size() + 1, strPostPrefix); - } - for (int counts : entry.getCounts()) { - entryCounts1.put(entryCounts1.size() + 1, counts); - } - for (IToken tokens : token.getTokens()) { - ITokenMapTag1.put(ITokenMapTag1.size() + 1, tokens.getTag()); - for (String strtoken : tokens.getStems()) { - strTokenStems1.put(strTokenStems1.size() + 1, strtoken); - MarkedContiniousCounter1Entries++; - } - } - tokensCounter1++; - } - anotatorcounter1++; - } - sentences = jmweStrAnnotation2.get(CoreAnnotations.SentencesAnnotation.class); - for (CoreMap sentence : sentences) { - for (IMWE token : sentence.get(JMWEAnnotation.class)) { - if (token.isInflected()) { - inflectedCounterPositive2++; - } else { - inflectedCounterNegative--; - } - strTokenForm2.put(strTokenForm2.size() + 1, token.getForm()); - strTokenGetEntry2.put(strTokenGetEntry2.size() + 1, token.getEntry().toString().substring(token.getEntry().toString().length() - 1)); - Collection values = token.getPartMap().values(); - IMWEDesc entry = token.getEntry(); - MarkedContinuousCounter2 += entry.getMarkedContinuous(); - UnmarkedPatternCounter2 += entry.getUnmarkedPattern(); - for (IMWEDesc.IPart iPart : values) { - strTokenGetiPart2.put(strTokenGetiPart2.size() + 1, iPart.getForm()); - } - for (String strPostPrefix : entry.getPOS().getPrefixes()) { - strTokenEntryPOS2.put(strTokenEntryPOS2.size() + 1, strPostPrefix); - } - for (int counts : entry.getCounts()) { - entryCounts2.put(entryCounts2.size() + 1, counts); - } - for (IToken tokens : token.getTokens()) { - ITokenMapTag2.put(ITokenMapTag2.size() + 1, tokens.getTag()); - for (String strtoken : tokens.getStems()) { - strTokenStems2.put(strTokenStems2.size() + 1, strtoken); - MarkedContiniousCounter2Entries++; - } - } - tokensCounter2++; - } - anotatorcounter2++; - } - } catch (Exception ex) { - //System.out.println("SENTIMENT stacktrace: " + ex.getMessage() + "\n"); - } - - int entry1 = entryCounts1.values().size(); - int entry2 = entryCounts2.values().size(); - //System.out.println("score post JMWEAnnotation: " + score + "\nentry1: " + entry1 + "\nentry2: " + entry2 + "\n"); - if (entry1 > 0 && entry2 > 0) { - if ((entry1 >= entry2 * 5) || (entry2 >= entry1 * 5)) { - score -= entry1 > entry2 ? (entry1 - entry2) * 450 : (entry2 - entry1) * 450; - //System.out.println("1"); - } else if ((entry1 >= entry2 * 50 || entry2 >= entry1 * 50)) { - score -= entry1 > entry2 ? entry1 * 180 : entry2 * 180; - //System.out.println("2"); - } else if (entry1 >= entry2 * 2 || entry2 >= entry1 * 2) { - score += entry1 > entry2 ? (entry1 - entry2) * 450 : (entry2 - entry1) * 450; - //System.out.println("3"); - } else if (entry1 > 10 && entry2 > 10 && entry1 * 2 > entry2 && entry2 * 2 > entry1) { - score += entry1 > entry2 ? entry2 * 600 : entry1 * 600; - //System.out.println("6"); - } - } - ConcurrentMap countsMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (int counts : entryCounts1.values()) { - for (int counts1 : entryCounts2.values()) { - if (counts == counts1 && counts > 0 && !countsMap.values().contains(counts)) { - score += counts * 250; - //System.out.println("score post counts: " + score + "\nCounts: " + counts + "\n"); - countsMap.put(countsMap.size() + 1, counts); - } - } - } - if (strTokenEntryPOS1.values().size() > 1 && strTokenEntryPOS2.values().size() > 1) { - for (String strTokenPos1 : strTokenEntryPOS1.values()) { - for (String strTokenPos2 : strTokenEntryPOS2.values()) { - if (strTokenPos1.equals(strTokenPos2)) { - score += 500; - } else { - score -= 650; - //System.out.println("strTokenEntryPOS score: " + score + "\n"); - } - } - } - } - //System.out.println("score pre UnmarkedPatternCounter: " + score + "\nUnmarkedPatternCounter1: " + UnmarkedPatternCounter1 - // + "\nUnmarkedPatternCounter2: " + UnmarkedPatternCounter2 + "\n"); - if (UnmarkedPatternCounter1 > 0 && UnmarkedPatternCounter2 > 0) { - if (UnmarkedPatternCounter1 * 2 > UnmarkedPatternCounter2 && UnmarkedPatternCounter2 * 2 > UnmarkedPatternCounter1) { - score += 2500; - } else if (UnmarkedPatternCounter1 * 5 < UnmarkedPatternCounter2 || UnmarkedPatternCounter2 * 5 < UnmarkedPatternCounter1) { - score -= 4000; - } - } - //System.out.println("score post UnmarkedPatternCounter: " + score + "\n"); - if (MarkedContinuousCounter1 > 0 && MarkedContinuousCounter2 > 0) { - if (MarkedContinuousCounter1 > MarkedContinuousCounter2 * 50 || MarkedContinuousCounter2 > MarkedContinuousCounter1 * 50) { - score -= MarkedContinuousCounter1 > MarkedContinuousCounter2 ? MarkedContinuousCounter1 * 120 : MarkedContinuousCounter2 * 120; - //System.out.println("score post MarkedContinuousCounter too big: " + score + "\n"); - } else if (!Objects.equals(MarkedContiniousCounter1Entries, MarkedContiniousCounter2Entries) - && (MarkedContinuousCounter1 * 2 >= MarkedContinuousCounter2 * MarkedContinuousCounter1) - || (MarkedContinuousCounter2 * 2 >= MarkedContinuousCounter1 * MarkedContinuousCounter2)) { - score += 4500; - } else if (MarkedContiniousCounter1Entries == 0 || MarkedContiniousCounter2Entries == 0) { - score += MarkedContinuousCounter1 > MarkedContinuousCounter2 ? (MarkedContinuousCounter2 - MarkedContinuousCounter1) * 500 - : (MarkedContinuousCounter1 - MarkedContinuousCounter2) * 500; - } - if (MarkedContiniousCounter1Entries > 0 && MarkedContiniousCounter2Entries > 0 && MarkedContinuousCounter1 > 0 - && MarkedContinuousCounter2 > 0 && MarkedContinuousCounter1 < MarkedContinuousCounter2 * 10 - && MarkedContinuousCounter2 < MarkedContinuousCounter1 * 10) { - if (MarkedContiniousCounter1Entries > MarkedContiniousCounter2Entries * 5 - || MarkedContiniousCounter2Entries > MarkedContiniousCounter1Entries * 5 - || MarkedContiniousCounter1Entries * 5 < MarkedContinuousCounter1 - || MarkedContiniousCounter1Entries * 5 < MarkedContinuousCounter2 - || MarkedContiniousCounter2Entries * 5 < MarkedContinuousCounter1 - || MarkedContiniousCounter2Entries * 5 < MarkedContinuousCounter2) { - score -= MarkedContinuousCounter1 > MarkedContinuousCounter2 ? MarkedContinuousCounter1 * 400 : MarkedContinuousCounter2 * 400; - //System.out.println("score post MarkedContinuousCounter: " + score + "\n"); - } - } - } - ConcurrentMap strtokensMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (String strTokeniPart1 : strTokenGetiPart1.values()) { - for (String strTokeniPart2 : strTokenGetiPart2.values()) { - if (strTokeniPart1.equals(strTokeniPart2) && !strtokensMap.values().contains(strTokeniPart2)) { - strtokensMap.put(strtokensMap.size() + 1, strTokeniPart2); - score += 400; - } else { - score -= 200; - //System.out.println("score minus strTokenGetiPart: " + score + "\n"); - } - } - } - int tokenEntry1 = strTokenGetEntry1.values().size(); - int tokenEntry2 = strTokenGetEntry2.values().size(); - boolean boundariyLeacks = false; - int remnantCounter = 0; - if (tokenEntry1 * 2 != tokenEntry2 && tokenEntry2 * 2 != tokenEntry1) { - boundariyLeacks = true; - } - ConcurrentMap entryTokenMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (String strTokenEntry1 : strTokenGetEntry1.values()) { - for (String strTokenEntry2 : strTokenGetEntry2.values()) { - if (!entryTokenMap.values().contains(strTokenEntry2)) { - if (strTokenEntry1.equals(strTokenEntry2)) { - score += boundariyLeacks ? 2500 : 2500 / 2; - } else if (!boundariyLeacks) { - score -= 450; - //System.out.println("boundariyLeacks score: " + score + "\n"); - } else { - remnantCounter++; - } - } - entryTokenMap.put(entryTokenMap.size() + 1, strTokenEntry2); - } - } - //System.out.println("score pre remnantCounter: " + score + "\n"); - score += remnantCounter * 250; - //System.out.println("score post remnantCounter: " + score + "\n"); - ConcurrentMap iTokenMapTagsMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (String strmapTag : ITokenMapTag1.values()) { - for (String strmapTag1 : ITokenMapTag2.values()) { - if (strmapTag.equals(strmapTag1)) { - score -= 1450; - } else if (!iTokenMapTagsMap.values().contains(strmapTag)) { - score += 725; - iTokenMapTagsMap.put(iTokenMapTagsMap.size() + 1, strmapTag); - } - } - } - //System.out.println("score post strmapTag: " + score + "\n"); - int tokenform1size = strTokenForm1.values().size(); - int tokenform2size = strTokenForm2.values().size(); - if (tokenform1size > 0 || tokenform2size > 0) { - if (tokenform1size < tokenform2size * 5 && tokenform2size < tokenform1size * 5) { - for (String strTokenForm1itr1 : strTokenForm1.values()) { - for (String strTokenForm1itr2 : strTokenForm2.values()) { - if (strTokenForm1itr1.equals(strTokenForm1itr2)) { - score -= 1600; - } else { - score += 500; - //System.out.println("tokenform1size score500: " + score + "\n"); - } - } - } - } else if (tokenform1size > 0 && tokenform2size > 0) { - if (tokenform1size * 2 >= tokenform2size && tokenform2size * 2 >= tokenform1size) { - score += tokenform1size > tokenform2size ? tokenform1size * 600 : tokenform2size * 600; - } else if (tokenform1size * 4 <= tokenform2size || tokenform2size * 4 <= tokenform1size) { - score -= tokenform1size > tokenform2size ? (tokenform1size - tokenform2size) * 600 : (tokenform2size - tokenform1size) * 600; - } - //System.out.println("tokenform1size score: " + score + "\ntokenform1size: " + tokenform1size + "\ntokenform2size: " - // + tokenform2size + "\n"); - } - } - //System.out.println("Score pre tokenStemmingMap: " + score + "\n"); - ConcurrentMap tokenStemmingMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (String strTokenStem : strTokenStems1.values()) { - for (String strTokenStem1 : strTokenStems2.values()) { - if (strTokenStem.equals(strTokenStem1) && !tokenStemmingMap.values().contains(strTokenStem)) { - score += 1500; - tokenStemmingMap.put(tokenStemmingMap.size() + 1, strTokenStem); - } - //System.out.println("score strTokenStem: " + score + "\n"); - } - } - //System.out.println("Score pre inflected: " + score + "\n"); - //System.out.println("inflectedCounterPositive1: " + inflectedCounterPositive1 + "\ninflectedCounterPositive2: " - // + inflectedCounterPositive2 + "\ninflectedCounterNegative: " + inflectedCounterNegative + "\n"); - if (inflectedCounterPositive1 + inflectedCounterPositive2 > inflectedCounterNegative && inflectedCounterNegative > 0) { - score += ((inflectedCounterPositive1 + inflectedCounterPositive2) - inflectedCounterNegative) * 650; - //System.out.println("score inflectedCounterPositive plus: " + score + "\n"); - } - if (inflectedCounterPositive1 > 0 && inflectedCounterPositive2 > 0) { - if (inflectedCounterPositive1 * 2 > inflectedCounterPositive2 && inflectedCounterPositive2 * 2 > inflectedCounterPositive1) { - score += ((inflectedCounterPositive1 + inflectedCounterPositive2) - inflectedCounterNegative) * 550; - //System.out.println("score plus inflectedCounterPositive * 2: " + score + "\n"); - } else if (inflectedCounterPositive1 * 5 < inflectedCounterPositive2 || inflectedCounterPositive2 * 5 < inflectedCounterPositive1) { - score -= inflectedCounterPositive1 > inflectedCounterPositive2 ? (inflectedCounterPositive1 - inflectedCounterPositive2) * 400 - : (inflectedCounterPositive2 - inflectedCounterPositive1) * 400; - //System.out.println("score minus inflectedCounterPositive * 2: " + score + "\n"); - } - } - //System.out.println("anotatorcounter1: " + anotatorcounter1 + "\nanotatorcounter2: " + anotatorcounter2 + "\n"); - if (anotatorcounter1 > 1 && anotatorcounter2 > 1) { - if (anotatorcounter1 * 2 > anotatorcounter2 && anotatorcounter2 * 2 > anotatorcounter1) { - score += anotatorcounter1 > anotatorcounter2 ? (anotatorcounter1 - anotatorcounter2) * 700 - : (anotatorcounter2 - anotatorcounter1) * 700; - //System.out.println("score plus anotatorcounter: " + score + "\n"); - } else if (anotatorcounter1 * 5 < anotatorcounter2 || anotatorcounter2 * 5 < anotatorcounter1) { - score -= anotatorcounter1 > anotatorcounter2 ? (anotatorcounter1 - anotatorcounter2) * 400 : (anotatorcounter2 - anotatorcounter1) * 400; - //System.out.println("score minus anotatorcounter: " + score + "\n"); - } - } - //System.out.println("tokensCounter1: " + tokensCounter1 + "\ntokensCounter2: " + tokensCounter2 + "\n"); - if ((tokensCounter1 > 1 && tokensCounter2 > 1) && tokensCounter1 < tokensCounter2 * 5 && tokensCounter2 < tokensCounter1 * 5) { - if (tokensCounter1 > tokensCounter2 / 2 && tokensCounter2 > tokensCounter1 / 2) { - score += (tokensCounter1 + tokensCounter2) * 1400; - //System.out.println("score plus tokensCounter: " + score + "\n"); - } else { - score -= 3500; - //System.out.println("score minus tokensCounter: " + score + "\n"); - } - } else { - int elseint = tokensCounter1 >= tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500; - //System.out.println("elseint: " + elseint + " tokensCounter2 * 5 || tokensCounter2 > tokensCounter1 * 5) - && tokensCounter1 > 0 && tokensCounter2 > 0) { - score -= tokensCounter1 > tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500; - //System.out.println("score post tokensCounter: " + score + "\n"); - } else if (elseint > 0 && tokensCounter1 > 0 && tokensCounter2 > 0) { - score -= elseint * 2; - //System.out.println("score post elseint: " + elseint + "\n"); - } - } - //System.out.println("Score Pre levenhstein: " + score + "\n"); - LevenshteinDistance leven = new LevenshteinDistance(str, str1); - double SentenceScoreDiff = leven.computeLevenshteinDistance(); - SentenceScoreDiff *= 15; - score -= SentenceScoreDiff; - ConcurrentMap nerEntities1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap nerEntities2 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap nerEntities3 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap nerEntities4 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap nerEntityTokenTags1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap nerEntityTokenTags2 = new MapMaker().concurrencyLevel(2).makeMap(); - for (CoreEntityMention em : pipelineCoreDcoument1.entityMentions()) { - Set> entrySet = em.entityTypeConfidences().entrySet(); - String entityType = em.entityType(); - Double EntityConfidences = 0.0; - for (Map.Entry entries : entrySet) { - EntityConfidences = entries.getValue(); - } - List tokens = em.tokens(); - for (CoreLabel token : tokens) { - if (!nerEntityTokenTags1.values().contains(token.tag())) { - if (entityType.equals("PERSON") && EntityConfidences > 0.80) { - nerEntityTokenTags1.put(nerEntityTokenTags1.size() + 1, token.tag()); - } - } - } - if (!nerEntities1.values().contains(em.text())) { - nerEntities1.put(nerEntities1.size() + 1, em.text()); - nerEntities3.put(nerEntities3.size() + 1, em.entityType()); - } - } - for (CoreEntityMention em : pipelineCoreDcoument2.entityMentions()) { - Set> entrySet = em.entityTypeConfidences().entrySet(); - String entityType = em.entityType(); - Double EntityConfidences = 0.0; - for (Map.Entry entries : entrySet) { - EntityConfidences = entries.getValue(); - } - List tokens = em.tokens(); - for (CoreLabel token : tokens) { - if (!nerEntityTokenTags2.values().contains(token.tag())) { - if (entityType.equals("PERSON") && EntityConfidences > 0.80) { - nerEntityTokenTags2.put(nerEntityTokenTags2.size() + 1, token.tag()); - } - } - } - if (!nerEntities2.values().contains(em.text())) { - nerEntities2.put(nerEntities2.size() + 1, em.text()); - nerEntities4.put(nerEntities4.size() + 1, em.entityType()); - } - } - //System.out.println("score post PERSON trim: " + score + "\n"); - for (String strEnts1 : nerEntities1.values()) { - Collection values = nerEntities2.values(); - for (String strEnts2 : values) { - if (strEnts1.equalsIgnoreCase(strEnts2)) { - score += 2500; - //System.out.println("score strEnts1 plus: " + score + "\n"); - } else { - score -= 150; - } - } - } - for (String strEnts1 : nerEntities3.values()) { - if (nerEntities4.values().contains(strEnts1)) { - score -= 1500; - //System.out.println("score nerEntities4 minus: " + score + "\n"); - } else { - score -= 150; - } - } - for (String strToken : nerEntityTokenTags1.values()) { - if (nerEntityTokenTags2.values().contains(strToken)) { - score += 2000; - //System.out.println("score nerEntities4 plus: " + score + "\n"); - } else { - score -= 150; - } - } - //System.out.println("score pre stopwordTokens: " + score + "\n"); - ConcurrentMap stopwordTokens = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap stopwordTokens1 = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap stopWordLemma = new MapMaker().concurrencyLevel(2).makeMap(); - ConcurrentMap stopWordLemma1 = new MapMaker().concurrencyLevel(2).makeMap(); - Integer pairCounter1 = 0; - Integer pairCounter2 = 0; - String customStopWordList = "start,starts,period,periods,a,an,and,are,as,at,be,but,by,for,if,in,into,is,it,no,not,of,on,or,such,that,the,their,then,there,these,they,this,to,was,will,with"; - List tokensSentiment1 = pipelineAnnotation1Sentiment.get(CoreAnnotations.TokensAnnotation.class); - List tokensSentiment2 = pipelineAnnotation2Sentiment.get(CoreAnnotations.TokensAnnotation.class); - Set stopWords = StopAnalyzer.ENGLISH_STOP_WORDS_SET; - Set stopWordsCustom = StopwordAnnotator.getStopWordList(customStopWordList, true); - for (CoreLabel token : tokensSentiment1) { - Pair stopword = token.get(StopwordAnnotator.class); - String word = token.word().toLowerCase(); - if (stopWords.contains(word) || stopWordsCustom.contains(word)) { - stopwordTokens.put(stopwordTokens.size(), word); - } - String lemma = token.lemma().toLowerCase(); - if (stopWords.contains(lemma) || stopWordsCustom.contains(lemma)) { - stopWordLemma.put(stopWordLemma.size(), lemma); - } - if (stopword.first() && stopword.second()) { - pairCounter1++; - } - //System.out.println("stopword Pair: " + stopword.first() + " " + stopword.second() + "\nword: " - // + word + "\nlemma: " + lemma + "\n"); - } - for (CoreLabel token : tokensSentiment2) { - Pair stopword = token.get(StopwordAnnotator.class); - String word = token.word().toLowerCase(); - if (stopWords.contains(word) || stopWordsCustom.contains(word)) { - stopwordTokens1.put(stopwordTokens1.size(), word); - } - String lemma = token.lemma().toLowerCase(); - if (stopWords.contains(lemma) || stopWordsCustom.contains(lemma)) { - stopWordLemma1.put(stopWordLemma1.size(), lemma); - } - if (stopword.first() && stopword.second()) { - pairCounter2++; - } - //System.out.println("stopword Pair: " + stopword.first() + " " + stopword.second() + "\nword: " - // + word + "\nlemma: " + lemma + "\n"); - } - for (String stopwords1 : stopwordTokens.values()) { - for (String stopwords2 : stopwordTokens1.values()) { - if (stopwords1.equals(stopwords2)) { - score -= 500; - //System.out.println("score stopwordsToken: " + score + "\n"); - } - } - } - for (String stopwords1 : stopWordLemma.values()) { - for (String stopwords2 : stopWordLemma1.values()) { - if (stopwords1.equals(stopwords2)) { - score -= 500; - //System.out.println("score stopwords Lemma: " + score + "\n"); - } - } - } - if (!stopwordTokens.values().isEmpty() && !stopwordTokens1.values().isEmpty()) { - int stopwordsize1 = stopwordTokens.values().size(); - int stopwordsize2 = stopwordTokens1.values().size(); - if (stopwordsize1 * 5 < stopwordsize2 || stopwordsize2 * 5 < stopwordsize1) { - score -= stopwordsize1 > stopwordsize2 ? (stopwordsize1 - stopwordsize2) * 850 : (stopwordsize2 - stopwordsize1) * 850; - } else { - score += stopwordsize1 > stopwordsize2 ? (stopwordsize1 - stopwordsize2) * 850 : (stopwordsize2 - stopwordsize1) * 850;; - } - //System.out.println("score post stopwordsize: " + score + "\nstopwordsize1: " + stopwordsize1 + "\nstopwordsize2: " - // + stopwordsize2 + "\n"); - } - if (pairCounter1 > 0 && pairCounter2 > 0) { - if (pairCounter1 * 3 <= pairCounter2 || pairCounter2 * 3 <= pairCounter1) { - score -= pairCounter1 > pairCounter2 ? (pairCounter1 - pairCounter2) * 1500 : (pairCounter2 - pairCounter1) * 1500; - } else { - score += pairCounter1 > pairCounter2 ? (pairCounter1 - pairCounter2) * 700 : (pairCounter2 - pairCounter1) * 700; - } - //System.out.println("score post pairCounter: " + score + "\npairCounter1: " + pairCounter1 + "\npairCounter2: " + pairCounter2 + "\n"); - } - } catch (Exception ex) { - //System.out.println("SENTIMENT stacktrace Overall catch: " + ex.getMessage() + "\n"); + SentimentValueCache cacheSentimentLocal1 = null; + SentimentValueCache cacheSentimentLocal2 = null; + int counter1; + int counter2; + if (cacheSentiment1 == null) { + cacheSentimentLocal1 = initializeCacheSetup(str, cacheSentimentLocal1); } - //System.out.println("Final current score: " + score + "\nSentence 1: " + str + "\nSentence 2: " + str1 + "\n"); + 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 retrieveTGWListIndex = retrieveTGWListIndex(cacheSentimentLocal1.getTaggedwordlist()); + for (String str : retrieveTGWListIndex.values()) { + cacheSentimentLocal1.addTgwlistIndex(str); + } + } + if (cacheSentiment2 == null) { + ConcurrentMap retrieveTGWListIndex = retrieveTGWListIndex(cacheSentimentLocal2.getTaggedwordlist()); + for (String str : retrieveTGWListIndex.values()) { + cacheSentimentLocal2.addTgwlistIndex(str); + } + } + score = tgwListScoreIncrementer(score, cacheSentiment1 == null + ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2); + // System.out.println("score post runCountGet: " + score + "\n"); + if (cacheSentiment1 == null) { + cacheSentimentLocal1 = GrammaticStructureSetup(cacheSentimentLocal1, pipelineAnnotation1); + } + if (cacheSentiment2 == null) { + cacheSentimentLocal2 = GrammaticStructureSetup(cacheSentimentLocal2, pipelineAnnotation2); + } + ConcurrentMap sentenceConstituencyParseList2 = cacheSentiment2 == null + ? cacheSentimentLocal2.getSentenceConstituencyParseList() : cacheSentiment2.getSentenceConstituencyParseList(); + ConcurrentMap sentenceConstituencyParseList1 = cacheSentiment1 == null + ? cacheSentimentLocal1.getSentenceConstituencyParseList() : cacheSentiment1.getSentenceConstituencyParseList(); + score = iterateTrees(sentenceConstituencyParseList2, sentenceConstituencyParseList1, score); + Collection allTypedDependencies2 = cacheSentiment2 == null ? cacheSentimentLocal2.getAllTypedDependencies() + : cacheSentiment2.getAllTypedDependencies(); + Collection allTypedDependencies1 = cacheSentiment1 == null ? cacheSentimentLocal1.getAllTypedDependencies() + : cacheSentiment1.getAllTypedDependencies(); + ConcurrentMap grammaticalMap1 = cacheSentiment1 == null ? cacheSentimentLocal1.getGs() : cacheSentiment1.getGs(); + ConcurrentMap grammaticalMap2 = cacheSentiment2 == null ? cacheSentimentLocal2.getGs() : cacheSentiment2.getGs(); + score = typeDependenciesGrammaticalRelation(allTypedDependencies1, allTypedDependencies2, score, grammaticalMap1, grammaticalMap2, + sentenceConstituencyParseList1, sentenceConstituencyParseList2); + if (cacheSentiment1 == null) { + cacheSentimentLocal1 = sentimentCoreAnnotationSetup(pipelineAnnotation1Sentiment, cacheSentimentLocal1); + } + if (cacheSentiment2 == null) { + cacheSentimentLocal2 = sentimentCoreAnnotationSetup(pipelineAnnotation2Sentiment, cacheSentimentLocal2); + } + final ConcurrentMap simpleSMXlist1 = cacheSentiment1 == null + ? cacheSentimentLocal1.getSimpleSMXlist() : cacheSentiment1.getSimpleSMXlist(); + final ConcurrentMap simpleSMXlist2 = cacheSentiment2 == null + ? cacheSentimentLocal2.getSimpleSMXlist() : cacheSentiment2.getSimpleSMXlist(); + final ConcurrentMap simpleSMXlistVector1 = cacheSentiment1 == null + ? cacheSentimentLocal1.getSimpleSMXlistVector() : cacheSentiment1.getSimpleSMXlistVector(); + final ConcurrentMap simpleSMXlistVector2 = cacheSentiment2 == null + ? cacheSentimentLocal2.getSimpleSMXlistVector() : cacheSentiment2.getSimpleSMXlistVector(); + //System.out.println("score pre pipelineAnnotation2Sentiment: " + score + "\n"); + 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(); + //System.out.println("score post elementsVariance: " + score + "\n"); + score -= (sentiment1 > sentiment2 ? sentiment1 - sentiment2 : sentiment2 - sentiment1) * 500; + Map.Entry> classifyRawEvaluationEntry = classifyRawEvaluation(score, cacheSentimentLocal1, + cacheSentimentLocal2); + score = classifyRawEvaluationEntry.getKey(); + if (cacheSentiment1 == null) { + cacheSentimentLocal1 = classifyRawEvaluationEntry.getValue().getKey(); + } + if (cacheSentiment2 == null) { + cacheSentimentLocal2 = classifyRawEvaluationEntry.getValue().getValue(); + } + //System.out.println("score post classifyRaw: " + score + "\n"); + 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()); + if (cacheSentiment1 == null) { + cacheSentimentLocal1 = jmweAnnotationSetup(jmweStrAnnotation1, cacheSentimentLocal1); + } + if (cacheSentiment2 == null) { + cacheSentimentLocal2 = jmweAnnotationSetup(jmweStrAnnotation2, cacheSentimentLocal2); + } + 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); + //System.out.println("score post UnmarkedPatternCounter: " + score + "\n"); + score = markedContiniousCounterScoring(score, scoringCache1, scoringCache2); + score = strTokensMapScoring(score, scoringCache1, scoringCache2); + score = strTokenEntryScoring(score, scoringCache1, scoringCache2); + score = strTokenMapTagsScoring(score, scoringCache1, scoringCache2); + //System.out.println("score post strmapTag: " + score + "\n"); + score = tokenformSizeScoring(score, scoringCache1, scoringCache2); + //System.out.println("Score pre tokenStemmingMap: " + score + "\n"); + score = tokenStemmingMapScoring(score, scoringCache1, scoringCache2); + //System.out.println("Score pre inflected: " + score + "\n"); + score = inflectedCounterScoring(score, scoringCache1, scoringCache2); + score = annotatorCountScoring(score, scoringCache1, scoringCache2); + score = tokensCounterScoring(score, scoringCache1, scoringCache2); + //System.out.println("Score Pre levenhstein: " + score + "\n"); + LevenshteinDistance leven = new LevenshteinDistance(str, str1); + double SentenceScoreDiff = leven.computeLevenshteinDistance(); + SentenceScoreDiff *= 15; + score -= SentenceScoreDiff; + if (cacheSentiment1 == null) { + cacheSentimentLocal1 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument1, cacheSentimentLocal1); + } + if (cacheSentiment2 == null) { + cacheSentimentLocal2 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument2, cacheSentimentLocal2); + } + //System.out.println("score post PERSON trim: " + score + "\n"); + score = nerEntitiesAndTokenScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null + ? cacheSentimentLocal2 : cacheSentiment2); + //System.out.println("score pre stopwordTokens: " + score + "\n"); + 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); + score = stopwordTokenPairCounterScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null + ? cacheSentimentLocal2 : cacheSentiment2); + // System.out.println("Final current score: " + score + "\nSentence 1: " + str + "\nSentence 2: " + str1 + "\n"); smxParam.setDistance(score); + if (cacheSentiment1 == null) { + smxParam.setCacheValue1(cacheSentimentLocal1); + } + if (cacheSentiment2 == null) { + smxParam.setCacheValue2(cacheSentimentLocal2); + } return smxParam; } } diff --git a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java new file mode 100644 index 00000000..5b2efd2e --- /dev/null +++ b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java @@ -0,0 +1,334 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package FunctionLayer.StanfordParser; + +import com.google.common.collect.MapMaker; +import edu.stanford.nlp.ling.TaggedWord; +import edu.stanford.nlp.trees.GrammaticalStructure; +import edu.stanford.nlp.trees.Tree; +import edu.stanford.nlp.trees.TypedDependency; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentMap; +import org.ejml.simple.SimpleMatrix; + +/** + * + * @author install1 + */ +public final class SentimentValueCache { + + private final String sentence; + private static int counter; + private static List> taggedwordlist = new ArrayList(); + private final ConcurrentMap tgwlistIndex = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap sentenceConstituencyParseList = new MapMaker().concurrencyLevel(2).makeMap(); + private final Collection allTypedDependencies = new ArrayList(); + private final ConcurrentMap gsMap = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap simpleSMXlist = new MapMaker().concurrencyLevel(3).makeMap(); + private final ConcurrentMap simpleSMXlistVector = new MapMaker().concurrencyLevel(3).makeMap(); + private final ConcurrentMap rnnPredictClassMap = new MapMaker().concurrencyLevel(3).makeMap(); + private static List classifyRaw; + private static int mainSentiment = 0; + private static int longest = 0; + private static int tokensCounter = 0; + private static int anotatorcounter = 0; + private static int inflectedCounterPositive = 0; + private static int inflectedCounterNegative = 0; + private static int MarkedContinuousCounter = 0; + private static int MarkedContiniousCounterEntries = 0; + private static int UnmarkedPatternCounter = 0; + private static int pairCounter = 0; + private final ConcurrentMap ITokenMapTag = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap strTokenStems = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap strTokenForm = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap strTokenGetEntry = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap strTokenGetiPart = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap strTokenEntryPOS = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap entryCounts = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap nerEntities1 = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap nerEntities2 = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap nerEntityTokenTags = new MapMaker().concurrencyLevel(3).makeMap(); + private final ConcurrentMap stopwordTokens = new MapMaker().concurrencyLevel(2).makeMap(); + private final ConcurrentMap stopWordLemma = new MapMaker().concurrencyLevel(2).makeMap(); + + public final int getPairCounter() { + return pairCounter; + } + + public final void setPairCounter(int pairCounter) { + SentimentValueCache.pairCounter = pairCounter; + } + + public final void addStopWordLemma(String str) { + stopWordLemma.put(stopWordLemma.size(), str); + } + + public final void addstopwordTokens(String str) { + stopwordTokens.put(stopwordTokens.size(), str); + } + + public final ConcurrentMap getStopwordTokens() { + return stopwordTokens; + } + + public final ConcurrentMap getStopWordLemma() { + return stopWordLemma; + } + + public final void addnerEntityTokenTags(String str) { + nerEntityTokenTags.put(nerEntityTokenTags.size(), str); + } + + public final ConcurrentMap getnerEntityTokenTags() { + return nerEntityTokenTags; + } + + public final ConcurrentMap getnerEntities1() { + return nerEntities1; + } + + public final ConcurrentMap getnerEntities2() { + return nerEntities2; + } + + public final void addNEREntities1(String str) { + nerEntities1.put(nerEntities1.size(), str); + } + + public final void addNEREntities2(String str) { + nerEntities2.put(nerEntities2.size(), str); + } + + public final void setTaggedwords(List> twlist) { + taggedwordlist = twlist; + } + + public final List> getTaggedwordlist() { + return taggedwordlist; + } + + public final void addEntryCounts(int counts) { + entryCounts.put(entryCounts.size(), counts); + } + + public final ConcurrentMap getEntryCounts() { + return entryCounts; + } + + public final void addstrTokenEntryPOS(String str) { + strTokenEntryPOS.put(strTokenEntryPOS.size(), str); + } + + public final ConcurrentMap getstrTokenEntryPOS() { + return strTokenEntryPOS; + } + + public final void addstrTokenGetiPart(String str) { + strTokenGetiPart.put(strTokenGetiPart.size(), str); + } + + public final ConcurrentMap getstrTokenGetiPart() { + return strTokenGetiPart; + } + + public final ConcurrentMap getstrTokenGetEntry() { + return strTokenGetEntry; + } + + public final void addstrTokenGetEntry(String str) { + strTokenGetEntry.put(strTokenGetEntry.size(), str); + } + + public final ConcurrentMap getstrTokenForm() { + return strTokenForm; + } + + public final void addstrTokenForm(String str) { + strTokenForm.put(strTokenForm.size(), str); + } + + public final ConcurrentMap getstrTokenStems() { + return strTokenStems; + } + + public final void addstrTokenStems(String str) { + strTokenStems.put(strTokenStems.size(), str); + } + + public final ConcurrentMap getITokenMapTag() { + return ITokenMapTag; + } + + public final void addITokenMapTag(String str) { + ITokenMapTag.put(ITokenMapTag.size(), str); + } + + public final int getUnmarkedPatternCounter() { + return UnmarkedPatternCounter; + } + + public final void setUnmarkedPatternCounter(int UnmarkedPatternCounter) { + SentimentValueCache.UnmarkedPatternCounter = UnmarkedPatternCounter; + } + + public final int getMarkedContiniousCounterEntries() { + return MarkedContiniousCounterEntries; + } + + public final void setMarkedContiniousCounterEntries(int MarkedContiniousCounterEntries) { + SentimentValueCache.MarkedContiniousCounterEntries = MarkedContiniousCounterEntries; + } + + public final int getMarkedContinuousCounter() { + return MarkedContinuousCounter; + } + + public final void setMarkedContinuousCounter(int MarkedContinuousCounter) { + SentimentValueCache.MarkedContinuousCounter = MarkedContinuousCounter; + } + + public final int getInflectedCounterNegative() { + return inflectedCounterNegative; + } + + public final void setInflectedCounterNegative(int inflectedCounterNegative) { + SentimentValueCache.inflectedCounterNegative = inflectedCounterNegative; + } + + public final int getInflectedCounterPositive() { + return inflectedCounterPositive; + } + + public final void setInflectedCounterPositive(int inflectedCounterPositive) { + SentimentValueCache.inflectedCounterPositive = inflectedCounterPositive; + } + + public final int getAnotatorcounter() { + return anotatorcounter; + } + + public final void setAnotatorcounter(int anotatorcounter) { + SentimentValueCache.anotatorcounter = anotatorcounter; + } + + public final int getTokensCounter() { + return tokensCounter; + } + + public final void setTokensCounter(int tokensCounter) { + SentimentValueCache.tokensCounter = tokensCounter; + } + + public final int getMainSentiment() { + return mainSentiment; + } + + public final void setMainSentiment(int mainSentiment) { + SentimentValueCache.mainSentiment = mainSentiment; + } + + public final int getLongest() { + return longest; + } + + public final void setLongest(int longest) { + SentimentValueCache.longest = longest; + } + + public final List getClassifyRaw() { + return classifyRaw; + } + + public final void setClassifyRaw(List classifyRaw) { + SentimentValueCache.classifyRaw = classifyRaw; + } + + public final ConcurrentMap getRnnPrediectClassMap() { + return rnnPredictClassMap; + } + + public final void addRNNPredictClass(int rnnPrediction) { + rnnPredictClassMap.put(rnnPredictClassMap.size(), rnnPrediction); + } + + public final void addSimpleMatrix(SimpleMatrix SMX) { + simpleSMXlist.put(simpleSMXlist.size(), SMX); + } + + public final void addSimpleMatrixVector(SimpleMatrix SMX) { + simpleSMXlistVector.put(simpleSMXlistVector.size(), SMX); + } + + public final ConcurrentMap getGsMap() { + return gsMap; + } + + public final ConcurrentMap getSimpleSMXlist() { + return simpleSMXlist; + } + + public final ConcurrentMap getSimpleSMXlistVector() { + return simpleSMXlistVector; + } + + public final ConcurrentMap getGs() { + return gsMap; + } + + public final int getCounter() { + return counter; + } + + public final void addGS(GrammaticalStructure gs) { + gsMap.put(gsMap.size(), gs); + } + + public final Collection getAllTypedDependencies() { + return allTypedDependencies; + } + + public final void addTypedDependencies(Collection TDPlist) { + for (TypedDependency TDP : TDPlist) { + allTypedDependencies.add(TDP); + } + } + + public final ConcurrentMap getSentenceConstituencyParseList() { + return sentenceConstituencyParseList; + } + + public final void addSentenceConstituencyParse(Tree tree) { + sentenceConstituencyParseList.put(sentenceConstituencyParseList.size(), tree); + } + + public final void setCounter(int counter) { + SentimentValueCache.counter = counter; + } + + public final String getSentence() { + return sentence; + } + + public SentimentValueCache(String str, int counter) { + this.sentence = str; + this.counter = counter; + } + + public final ConcurrentMap getTgwlistIndex() { + return tgwlistIndex; + } + + public final void addTgwlistIndex(String str) { + tgwlistIndex.put(tgwlistIndex.size(), str); + } + + public SentimentValueCache(String str) { + this.sentence = str; + } +}