From 276730418d4f9c07d095186c4de7f7bdd330ab38 Mon Sep 17 00:00:00 2001 From: jenzur Date: Tue, 2 Apr 2019 00:59:23 +0200 Subject: [PATCH] calculation updates --- .../StanfordParser/SentimentAnalyzerTest.java | 152 ++++++++++-------- 1 file changed, 87 insertions(+), 65 deletions(-) diff --git a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java index f5011497..954bc433 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java @@ -171,6 +171,8 @@ public class SentimentAnalyzerTest implements Callable { } GrammaticalStructure gs1 = gsf.newGrammaticalStructure(sentenceConstituencyParse1); Collection allTypedDependencies1 = gs1.allTypedDependencies(); + int relationApplicable1 = 0; + int relationApplicable2 = 0; for (TypedDependency TDY1 : allTypedDependencies1) { IndexedWord dep = TDY1.dep(); IndexedWord gov = TDY1.gov(); @@ -181,6 +183,7 @@ public class SentimentAnalyzerTest implements Callable { GrammaticalRelation reln = TDY1.reln(); if (reln.isApplicable(sentenceConstituencyParse)) { score += 525; + relationApplicable1++; } } for (TypedDependency TDY : allTypedDependencies) { @@ -193,6 +196,16 @@ public class SentimentAnalyzerTest implements Callable { GrammaticalRelation reln = TDY.reln(); if (reln.isApplicable(sentenceConstituencyParse1)) { score += 525; + relationApplicable2++; + } + } + if (!allTypedDependencies.isEmpty() || !allTypedDependencies1.isEmpty()) { + if (relationApplicable1 > 0 && relationApplicable2 > 0) { + score += 3500; + } else { + score -= allTypedDependencies.size() > allTypedDependencies1.size() + ? (allTypedDependencies.size() - allTypedDependencies1.size()) * (allTypedDependencies.size() * 160) + : (allTypedDependencies1.size() - allTypedDependencies.size()) * (allTypedDependencies1.size() * 160); } } AtomicInteger runCount1 = new AtomicInteger(0); @@ -233,37 +246,37 @@ public class SentimentAnalyzerTest implements Callable { SimpleMatrix nodeVector = RNNCoreAnnotations.getNodeVector(tree); ConcurrentMap AccumulateDotMap = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap subtractorMap = new MapMaker().concurrencyLevel(2).makeMap(); - score += simpleSMXlist.values().stream().map(new Function() { - @Override - public Double apply(SimpleMatrix simpleSMX) { - return predictions.dot(simpleSMX) * 100; - } - }).map(new Function() { - @Override - public Double apply(Double dot) { - AccumulateDotMap.put(AccumulateDotMap.size() + 1, dot); - return dot > 50 ? dot - 100 : dot > 0 ? 100 - dot : 0; - } - }).map((subtracter) -> { + 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); - subtracter *= 25; //25 - return subtracter; - }).map(new Function() { - @Override - public Double apply(Double subtracter) { - return subtracter; - } - }).reduce(score, new BinaryOperator() { - @Override - public Double apply(Double accumulator, Double _item) { - int accumulator1 = 0; - while (accumulator < 0) { - accumulator++; - accumulator1++; + if (!dotPredictions.values().contains(dotPrediction)) { + if (dotPrediction > largest) { + largest = dotPrediction; } - return accumulator1 + _item; + if (dotPrediction < shortest) { + shortest = dotPrediction; + } + Double dotPredictionIntervalDifference = largest - shortest; + subtracter *= 25; + if (dotPredictionIntervalDifference < 5.0) { + if (dotPredictions.values().size() > 0) { + score += subtracter; + } + } else { + score -= subtracter; + } + } else { + subtracter -= 100; + subtracter *= 25; + score += subtracter * dotPrediction; } - }); + dotPredictions.put(dotPredictions.size() + 1, dotPrediction); + } Double subTracPre = 0.0; for (Double subtractors : subtractorMap.values()) { if (Objects.equals(subTracPre, subtractors)) { @@ -271,41 +284,37 @@ public class SentimentAnalyzerTest implements Callable { } subTracPre = subtractors; } - score += simpleSMXlist.values().stream().map(new Function() { - @Override - public Double apply(SimpleMatrix simpleSMX) { - return simpleSMX.dot(predictions) * 100; - } - }).map(new Function() { - @Override - public Double apply(Double dot) { - AccumulateDotMap.put(AccumulateDotMap.size() + 1, dot); - return dot > 50 ? dot - 50 : dot > 0 ? 50 - dot : 0; - } - }).map((subtracter) -> { - subtracter *= 25; //25 - return subtracter; - }).map(new Function() { - @Override - public Double apply(Double subtracter) { - return subtracter; - } - }).reduce(score, new BinaryOperator() { - @Override - public Double apply(Double accumulator, Double _item) { - int accumulator1 = 0; - while (accumulator < 0) { - accumulator++; - accumulator1++; + ConcurrentMap DotOverTransfer = dotPredictions; + dotPredictions = new MapMaker().concurrencyLevel(2).makeMap(); + 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; + subtractorMap.put(subtractorMap.size() + 1, subtracter); + if (!dotPredictions.values().contains(dotPrediction)) { + subtracter *= 25; + int match = 0; + for (Double transferDots : DotOverTransfer.values()) { + if (transferDots == dotPrediction) { + score += subtracter; + match++; + } } - return accumulator1 + _item; + if (match == 0) { + score -= subtracter; + } + } else { + subtracter -= 100; + subtracter *= 25; + score += subtracter * dotPrediction; } - }); + dotPredictions.put(dotPredictions.size() + 1, dotPrediction); + } Double preAccumulatorDot = 0.0; Double postAccumulatorDot = 0.0; for (Double accumulators : AccumulateDotMap.values()) { - if (preAccumulatorDot == accumulators) { - if (postAccumulatorDot == accumulators) { + if (Objects.equals(preAccumulatorDot, accumulators)) { + if (Objects.equals(postAccumulatorDot, accumulators)) { score -= 4000; } postAccumulatorDot = accumulators; @@ -334,7 +343,9 @@ public class SentimentAnalyzerTest implements Callable { elementSum = Math.round(elementSum * 100.0) / 100.0; elementSumCounter.put(elementSumCounter.size() + 1, elementSum); dotMap.put(dotMap.size() + 1, dot); - if (dot < 0.1) { + if (dot < 0.000) { + score += dot * 1500; + } else if (dot < 0.1) { score += 256; } if (dot > 0.50) { @@ -438,11 +449,13 @@ public class SentimentAnalyzerTest implements Callable { if (deffLongest > deffshorter * 5) { score -= 5500; } else if (deffLongest < (deffshorter * 2) - 1 && deffLongest - deffshorter <= 45) { - score += (deffLongest - deffshorter) * 120; + score += (deffLongest - deffshorter) * 60; } else if (mainSentiment1 != mainSentiment2 && deffLongest - deffshorter > 20 && deffLongest - deffshorter < 45) { score += (deffLongest - deffshorter) * 120; } else if (deffLongest - deffshorter < 2) { score += (deffLongest + deffshorter) * 40; + } else if (deffshorter * 2 >= deffLongest && deffshorter * 2 < deffLongest + 5) { + score += deffLongest * 160; } else { score -= (deffLongest - deffshorter) * 50; } @@ -459,6 +472,8 @@ public class SentimentAnalyzerTest implements Callable { int inflectedCounterNegative = 0; int MarkedContinuousCounter1 = 0; int MarkedContinuousCounter2 = 0; + Integer MarkedContiniousCounter1Entries = 0; + Integer MarkedContiniousCounter2Entries = 0; int UnmarkedPatternCounter = 0; ConcurrentMap ITokenMapTag1 = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap ITokenMapTag2 = new MapMaker().concurrencyLevel(2).makeMap(); @@ -497,6 +512,7 @@ public class SentimentAnalyzerTest implements Callable { ITokenMapTag1.put(ITokenMapTag1.size() + 1, tokens.getTag()); for (String strtoken : tokens.getStems()) { strTokenStems1.put(strTokenStems1.size() + 1, strtoken); + MarkedContiniousCounter1Entries++; } } tokensCounter1++; @@ -527,6 +543,7 @@ public class SentimentAnalyzerTest implements Callable { ITokenMapTag2.put(ITokenMapTag2.size() + 1, tokens.getTag()); for (String strtoken : tokens.getStems()) { strTokenStems2.put(strTokenStems2.size() + 1, strtoken); + MarkedContiniousCounter2Entries++; } } tokensCounter2++; @@ -544,11 +561,18 @@ public class SentimentAnalyzerTest implements Callable { } } if (UnmarkedPatternCounter > 0 && UnmarkedPatternCounter < 5) { - score += UnmarkedPatternCounter * 1600; + score -= UnmarkedPatternCounter * 1600; } if (MarkedContinuousCounter1 > 0 && MarkedContinuousCounter2 > 0) { - score += MarkedContinuousCounter1 > MarkedContinuousCounter2 ? (MarkedContinuousCounter1 - MarkedContinuousCounter2) * 500 - : (MarkedContinuousCounter2 - MarkedContinuousCounter1) * 500; + if (!Objects.equals(MarkedContiniousCounter1Entries, MarkedContiniousCounter2Entries) + && (MarkedContinuousCounter1 * 2 >= MarkedContinuousCounter2 * MarkedContinuousCounter1) + || (MarkedContinuousCounter2 * 2 >= MarkedContinuousCounter1 * MarkedContinuousCounter2)) { + score += MarkedContinuousCounter1 > MarkedContinuousCounter2 ? (MarkedContinuousCounter1 - MarkedContinuousCounter2) * 500 + : (MarkedContinuousCounter2 - MarkedContinuousCounter1) * 500; + } else { + score += MarkedContinuousCounter1 > MarkedContinuousCounter2 ? (MarkedContinuousCounter2 - MarkedContinuousCounter1) * 500 + : (MarkedContinuousCounter1 - MarkedContinuousCounter2) * 500; + } } for (String strTokeniPart1 : strTokenGetiPart1.values()) { for (String strTokeniPart2 : strTokenGetiPart2.values()) { @@ -602,8 +626,6 @@ public class SentimentAnalyzerTest implements Callable { int elseint = tokensCounter1 >= tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500; if (elseint > 0) { score -= elseint * 2; - } else { - score -= 1500; } } LevenshteinDistance leven = new LevenshteinDistance(str, str1);