calculation updates

This commit is contained in:
jenzur 2019-04-02 00:59:23 +02:00
parent d788d76ac6
commit 276730418d

View File

@ -171,6 +171,8 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
} }
GrammaticalStructure gs1 = gsf.newGrammaticalStructure(sentenceConstituencyParse1); GrammaticalStructure gs1 = gsf.newGrammaticalStructure(sentenceConstituencyParse1);
Collection<TypedDependency> allTypedDependencies1 = gs1.allTypedDependencies(); Collection<TypedDependency> allTypedDependencies1 = gs1.allTypedDependencies();
int relationApplicable1 = 0;
int relationApplicable2 = 0;
for (TypedDependency TDY1 : allTypedDependencies1) { for (TypedDependency TDY1 : allTypedDependencies1) {
IndexedWord dep = TDY1.dep(); IndexedWord dep = TDY1.dep();
IndexedWord gov = TDY1.gov(); IndexedWord gov = TDY1.gov();
@ -181,6 +183,7 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
GrammaticalRelation reln = TDY1.reln(); GrammaticalRelation reln = TDY1.reln();
if (reln.isApplicable(sentenceConstituencyParse)) { if (reln.isApplicable(sentenceConstituencyParse)) {
score += 525; score += 525;
relationApplicable1++;
} }
} }
for (TypedDependency TDY : allTypedDependencies) { for (TypedDependency TDY : allTypedDependencies) {
@ -193,6 +196,16 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
GrammaticalRelation reln = TDY.reln(); GrammaticalRelation reln = TDY.reln();
if (reln.isApplicable(sentenceConstituencyParse1)) { if (reln.isApplicable(sentenceConstituencyParse1)) {
score += 525; 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); AtomicInteger runCount1 = new AtomicInteger(0);
@ -233,37 +246,37 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
SimpleMatrix nodeVector = RNNCoreAnnotations.getNodeVector(tree); SimpleMatrix nodeVector = RNNCoreAnnotations.getNodeVector(tree);
ConcurrentMap<Integer, Double> AccumulateDotMap = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap<Integer, Double> AccumulateDotMap = new MapMaker().concurrencyLevel(2).makeMap();
ConcurrentMap<Integer, Double> subtractorMap = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap<Integer, Double> subtractorMap = new MapMaker().concurrencyLevel(2).makeMap();
score += simpleSMXlist.values().stream().map(new Function<SimpleMatrix, Double>() { ConcurrentMap<Integer, Double> dotPredictions = new MapMaker().concurrencyLevel(2).makeMap();
@Override Double largest = 10.0;
public Double apply(SimpleMatrix simpleSMX) { Double shortest = 100.0;
return predictions.dot(simpleSMX) * 100; for (SimpleMatrix simpleSMX : simpleSMXlist.values()) {
} double dotPrediction = predictions.dot(simpleSMX) * 100;
}).map(new Function<Double, Double>() { AccumulateDotMap.put(AccumulateDotMap.size() + 1, dotPrediction);
@Override double subtracter = dotPrediction > 50 ? dotPrediction - 100 : dotPrediction > 0 ? 100 - dotPrediction : 0;
public Double apply(Double dot) {
AccumulateDotMap.put(AccumulateDotMap.size() + 1, dot);
return dot > 50 ? dot - 100 : dot > 0 ? 100 - dot : 0;
}
}).map((subtracter) -> {
subtractorMap.put(subtractorMap.size() + 1, subtracter); subtractorMap.put(subtractorMap.size() + 1, subtracter);
subtracter *= 25; //25 if (!dotPredictions.values().contains(dotPrediction)) {
return subtracter; if (dotPrediction > largest) {
}).map(new Function<Double, Double>() { largest = dotPrediction;
@Override
public Double apply(Double subtracter) {
return subtracter;
}
}).reduce(score, new BinaryOperator<Double>() {
@Override
public Double apply(Double accumulator, Double _item) {
int accumulator1 = 0;
while (accumulator < 0) {
accumulator++;
accumulator1++;
} }
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; Double subTracPre = 0.0;
for (Double subtractors : subtractorMap.values()) { for (Double subtractors : subtractorMap.values()) {
if (Objects.equals(subTracPre, subtractors)) { if (Objects.equals(subTracPre, subtractors)) {
@ -271,41 +284,37 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
} }
subTracPre = subtractors; subTracPre = subtractors;
} }
score += simpleSMXlist.values().stream().map(new Function<SimpleMatrix, Double>() { ConcurrentMap<Integer, Double> DotOverTransfer = dotPredictions;
@Override dotPredictions = new MapMaker().concurrencyLevel(2).makeMap();
public Double apply(SimpleMatrix simpleSMX) { for (SimpleMatrix simpleSMX : simpleSMXlist.values()) {
return simpleSMX.dot(predictions) * 100; double dotPrediction = simpleSMX.dot(predictions) * 100;
} AccumulateDotMap.put(AccumulateDotMap.size() + 1, dotPrediction);
}).map(new Function<Double, Double>() { double subtracter = dotPrediction > 50 ? dotPrediction - 100 : dotPrediction > 0 ? 100 - dotPrediction : 0;
@Override subtractorMap.put(subtractorMap.size() + 1, subtracter);
public Double apply(Double dot) { if (!dotPredictions.values().contains(dotPrediction)) {
AccumulateDotMap.put(AccumulateDotMap.size() + 1, dot); subtracter *= 25;
return dot > 50 ? dot - 50 : dot > 0 ? 50 - dot : 0; int match = 0;
} for (Double transferDots : DotOverTransfer.values()) {
}).map((subtracter) -> { if (transferDots == dotPrediction) {
subtracter *= 25; //25 score += subtracter;
return subtracter; match++;
}).map(new Function<Double, Double>() { }
@Override
public Double apply(Double subtracter) {
return subtracter;
}
}).reduce(score, new BinaryOperator<Double>() {
@Override
public Double apply(Double accumulator, Double _item) {
int accumulator1 = 0;
while (accumulator < 0) {
accumulator++;
accumulator1++;
} }
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 preAccumulatorDot = 0.0;
Double postAccumulatorDot = 0.0; Double postAccumulatorDot = 0.0;
for (Double accumulators : AccumulateDotMap.values()) { for (Double accumulators : AccumulateDotMap.values()) {
if (preAccumulatorDot == accumulators) { if (Objects.equals(preAccumulatorDot, accumulators)) {
if (postAccumulatorDot == accumulators) { if (Objects.equals(postAccumulatorDot, accumulators)) {
score -= 4000; score -= 4000;
} }
postAccumulatorDot = accumulators; postAccumulatorDot = accumulators;
@ -334,7 +343,9 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
elementSum = Math.round(elementSum * 100.0) / 100.0; elementSum = Math.round(elementSum * 100.0) / 100.0;
elementSumCounter.put(elementSumCounter.size() + 1, elementSum); elementSumCounter.put(elementSumCounter.size() + 1, elementSum);
dotMap.put(dotMap.size() + 1, dot); dotMap.put(dotMap.size() + 1, dot);
if (dot < 0.1) { if (dot < 0.000) {
score += dot * 1500;
} else if (dot < 0.1) {
score += 256; score += 256;
} }
if (dot > 0.50) { if (dot > 0.50) {
@ -438,11 +449,13 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
if (deffLongest > deffshorter * 5) { if (deffLongest > deffshorter * 5) {
score -= 5500; score -= 5500;
} else if (deffLongest < (deffshorter * 2) - 1 && deffLongest - deffshorter <= 45) { } 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) { } else if (mainSentiment1 != mainSentiment2 && deffLongest - deffshorter > 20 && deffLongest - deffshorter < 45) {
score += (deffLongest - deffshorter) * 120; score += (deffLongest - deffshorter) * 120;
} else if (deffLongest - deffshorter < 2) { } else if (deffLongest - deffshorter < 2) {
score += (deffLongest + deffshorter) * 40; score += (deffLongest + deffshorter) * 40;
} else if (deffshorter * 2 >= deffLongest && deffshorter * 2 < deffLongest + 5) {
score += deffLongest * 160;
} else { } else {
score -= (deffLongest - deffshorter) * 50; score -= (deffLongest - deffshorter) * 50;
} }
@ -459,6 +472,8 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
int inflectedCounterNegative = 0; int inflectedCounterNegative = 0;
int MarkedContinuousCounter1 = 0; int MarkedContinuousCounter1 = 0;
int MarkedContinuousCounter2 = 0; int MarkedContinuousCounter2 = 0;
Integer MarkedContiniousCounter1Entries = 0;
Integer MarkedContiniousCounter2Entries = 0;
int UnmarkedPatternCounter = 0; int UnmarkedPatternCounter = 0;
ConcurrentMap<Integer, String> ITokenMapTag1 = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap<Integer, String> ITokenMapTag1 = new MapMaker().concurrencyLevel(2).makeMap();
ConcurrentMap<Integer, String> ITokenMapTag2 = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap<Integer, String> ITokenMapTag2 = new MapMaker().concurrencyLevel(2).makeMap();
@ -497,6 +512,7 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
ITokenMapTag1.put(ITokenMapTag1.size() + 1, tokens.getTag()); ITokenMapTag1.put(ITokenMapTag1.size() + 1, tokens.getTag());
for (String strtoken : tokens.getStems()) { for (String strtoken : tokens.getStems()) {
strTokenStems1.put(strTokenStems1.size() + 1, strtoken); strTokenStems1.put(strTokenStems1.size() + 1, strtoken);
MarkedContiniousCounter1Entries++;
} }
} }
tokensCounter1++; tokensCounter1++;
@ -527,6 +543,7 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
ITokenMapTag2.put(ITokenMapTag2.size() + 1, tokens.getTag()); ITokenMapTag2.put(ITokenMapTag2.size() + 1, tokens.getTag());
for (String strtoken : tokens.getStems()) { for (String strtoken : tokens.getStems()) {
strTokenStems2.put(strTokenStems2.size() + 1, strtoken); strTokenStems2.put(strTokenStems2.size() + 1, strtoken);
MarkedContiniousCounter2Entries++;
} }
} }
tokensCounter2++; tokensCounter2++;
@ -544,11 +561,18 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
} }
} }
if (UnmarkedPatternCounter > 0 && UnmarkedPatternCounter < 5) { if (UnmarkedPatternCounter > 0 && UnmarkedPatternCounter < 5) {
score += UnmarkedPatternCounter * 1600; score -= UnmarkedPatternCounter * 1600;
} }
if (MarkedContinuousCounter1 > 0 && MarkedContinuousCounter2 > 0) { if (MarkedContinuousCounter1 > 0 && MarkedContinuousCounter2 > 0) {
score += MarkedContinuousCounter1 > MarkedContinuousCounter2 ? (MarkedContinuousCounter1 - MarkedContinuousCounter2) * 500 if (!Objects.equals(MarkedContiniousCounter1Entries, MarkedContiniousCounter2Entries)
: (MarkedContinuousCounter2 - MarkedContinuousCounter1) * 500; && (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 strTokeniPart1 : strTokenGetiPart1.values()) {
for (String strTokeniPart2 : strTokenGetiPart2.values()) { for (String strTokeniPart2 : strTokenGetiPart2.values()) {
@ -602,8 +626,6 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
int elseint = tokensCounter1 >= tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500; int elseint = tokensCounter1 >= tokensCounter2 ? (tokensCounter1 - tokensCounter2) * 500 : (tokensCounter2 - tokensCounter1) * 500;
if (elseint > 0) { if (elseint > 0) {
score -= elseint * 2; score -= elseint * 2;
} else {
score -= 1500;
} }
} }
LevenshteinDistance leven = new LevenshteinDistance(str, str1); LevenshteinDistance leven = new LevenshteinDistance(str, str1);