turning more annotations to use compact for supposedly saving memory, added a relation containment based on first response evalutation and hopefully fixed integernames

This commit is contained in:
jenzur 2019-08-07 14:00:00 +02:00
parent cc2ca64ad5
commit 09d5d3534d
3 changed files with 38 additions and 8 deletions

View File

@ -61,7 +61,6 @@ public class Datahandler {
public static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(10, TimeUnit.MINUTES); 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 final long EXPIRE_TIME_IN_SECONDS1 = TimeUnit.SECONDS.convert(10, TimeUnit.HOURS);
public static Datahandler instance = new Datahandler(); public static Datahandler instance = new Datahandler();
private static volatile Double minDistance;
private static Annotation strAnno; private static Annotation strAnno;
private static Annotation strAnnoSentiment; private static Annotation strAnnoSentiment;
private static Annotation strAnnoJMWE; private static Annotation strAnnoJMWE;
@ -222,7 +221,7 @@ public class Datahandler {
hlStatsMessages.put(str, hlStatsMessages.size()); hlStatsMessages.put(str, hlStatsMessages.size());
} }
} }
int capacity = 2500; int capacity = 50;
hlStatsMessages.keySet().forEach(str -> { hlStatsMessages.keySet().forEach(str -> {
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) { if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null); String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null);
@ -248,17 +247,22 @@ public class Datahandler {
ConcurrentMap<String, Annotation> AnnotationspipelineSentiment = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap<String, Annotation> AnnotationspipelineSentiment = new MapMaker().concurrencyLevel(2).makeMap();
stringCache.values().parallelStream().forEach(str -> { stringCache.values().parallelStream().forEach(str -> {
Annotation strAnno = new Annotation(str); Annotation strAnno = new Annotation(str);
strAnno.compact();
Annotationspipeline.put(str, strAnno); Annotationspipeline.put(str, strAnno);
Annotation strAnno2 = new Annotation(str); Annotation strAnno2 = new Annotation(str);
strAnno2.compact();
AnnotationspipelineSentiment.put(str, strAnno2); AnnotationspipelineSentiment.put(str, strAnno2);
}); });
ConcurrentMap<String, CoreDocument> coreDocumentpipelineMap = getMultipleCoreDocumentsWaySuggestion(stringCache.values(), pipeline); ConcurrentMap<String, CoreDocument> coreDocumentpipelineMap = getMultipleCoreDocumentsWaySuggestion(stringCache.values(), pipeline);
pipeline.annotate(Annotationspipeline.values()); pipeline.annotate(Annotationspipeline.values());
pipelineSentiment.annotate(AnnotationspipelineSentiment.values()); pipelineSentiment.annotate(AnnotationspipelineSentiment.values());
Annotationspipeline.entrySet().forEach(pipelineEntry -> { Annotationspipeline.entrySet().forEach(pipelineEntry -> {
//relatively experimental change
pipelineEntry.getValue().compact();
pipelineAnnotationCache.put(pipelineEntry.getKey(), pipelineEntry.getValue()); pipelineAnnotationCache.put(pipelineEntry.getKey(), pipelineEntry.getValue());
}); });
AnnotationspipelineSentiment.entrySet().forEach(pipelineEntry -> { AnnotationspipelineSentiment.entrySet().forEach(pipelineEntry -> {
pipelineEntry.getValue().compact();
pipelineSentimentAnnotationCache.put(pipelineEntry.getKey(), pipelineEntry.getValue()); pipelineSentimentAnnotationCache.put(pipelineEntry.getKey(), pipelineEntry.getValue());
}); });
coreDocumentpipelineMap.entrySet().stream().forEach(CD -> { coreDocumentpipelineMap.entrySet().stream().forEach(CD -> {
@ -486,19 +490,34 @@ public class Datahandler {
} }
} }
StringBuilder SB = new StringBuilder(); StringBuilder SB = new StringBuilder();
double randomLenghtPermit = strF.length() * (Math.random() * 1.5); double randomLenghtPermit = strF.length() * (Math.random() * 2.0);
Collections.reverse(concurrentRelations); Collections.reverse(concurrentRelations);
String firstRelation = concurrentRelations.get(0);
for (String secondaryRelation : concurrentRelations) { for (String secondaryRelation : concurrentRelations) {
if (SB.toString().length() > randomLenghtPermit && !SB.toString().isEmpty()) { if (SB.toString().length() > randomLenghtPermit && !SB.toString().isEmpty()) {
break; break;
} }
System.out.println("relation secondary: " + secondaryRelation + "\n"); System.out.println("relation secondary: " + secondaryRelation + "\n");
boolean append = appendToString(firstRelation, secondaryRelation);
if (append) {
SB.append(secondaryRelation).append(" "); SB.append(secondaryRelation).append(" ");
} }
}
System.out.println("Reached end SB: " + SB.toString() + "\n"); System.out.println("Reached end SB: " + SB.toString() + "\n");
return SB.toString(); return SB.toString();
} }
private boolean appendToString(String firstRelation, String secondaryRelation) {
if (firstRelation.equals(secondaryRelation)) {
return true;
}
Double scoreRelationStrF = getScoreRelationStrF(firstRelation, secondaryRelation);
if (scoreRelationStrF > 1900) {
return true;
}
return false;
}
private double overAllOldScoreRelations(String strF) { private double overAllOldScoreRelations(String strF) {
if (!conversationUserMatchMap.keySet().contains(strF)) { if (!conversationUserMatchMap.keySet().contains(strF)) {
conversationUserMatchMap.put(strF, conversationUserMatchMap.size()); conversationUserMatchMap.put(strF, conversationUserMatchMap.size());
@ -520,13 +539,16 @@ public class Datahandler {
public void getSingularAnnotation(String str) { public void getSingularAnnotation(String str) {
strAnno = new Annotation(str); strAnno = new Annotation(str);
strAnno.compact();
pipeline.annotate(strAnno); pipeline.annotate(strAnno);
strAnnoSentiment = new Annotation(str); strAnnoSentiment = new Annotation(str);
strAnnoSentiment.compact();
pipelineSentiment.annotate(strAnnoSentiment); pipelineSentiment.annotate(strAnnoSentiment);
List<String> notactualList = new ArrayList(); List<String> notactualList = new ArrayList();
notactualList.add(str); notactualList.add(str);
ConcurrentMap<String, Annotation> jmweAnnotation = PipelineJMWESingleton.INSTANCE.getJMWEAnnotation(notactualList); ConcurrentMap<String, Annotation> jmweAnnotation = PipelineJMWESingleton.INSTANCE.getJMWEAnnotation(notactualList);
strAnnoJMWE = jmweAnnotation.values().iterator().next(); strAnnoJMWE = jmweAnnotation.values().iterator().next();
strAnnoJMWE.compact();
CoreDocument coreDocument = new CoreDocument(str); CoreDocument coreDocument = new CoreDocument(str);
pipeline.annotate(coreDocument); pipeline.annotate(coreDocument);
coreDoc = coreDocument; coreDoc = coreDocument;
@ -811,14 +833,12 @@ public class Datahandler {
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
} }
ConcurrentMap<String, CoreDocument> annotationreturnMap = new MapMaker().concurrencyLevel(6).makeMap(); ConcurrentMap<String, CoreDocument> annotationreturnMap = new MapMaker().concurrencyLevel(6).makeMap();
int iterator = 0;
for (Annotation ann : annCollector.annotationsT) { for (Annotation ann : annCollector.annotationsT) {
if (ann != null) { if (ann != null) {
ann.compact(); ann.compact();
CoreDocument CD = new CoreDocument(ann); CoreDocument CD = new CoreDocument(ann);
annotationreturnMap.put(CD.text(), CD); annotationreturnMap.put(CD.text(), CD);
//System.out.println("CD text:" + CD.text() + "\niterator: " + iterator + "\nsize: " + annCollector.annotationsT.size()); //System.out.println("CD text:" + CD.text() + "\niterator: " + iterator + "\nsize: " + annCollector.annotationsT.size());
iterator++;
} }
} }
return annotationreturnMap; return annotationreturnMap;

View File

@ -11,6 +11,8 @@ import edu.stanford.nlp.pipeline.CoreEntityMention;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* *
@ -65,6 +67,7 @@ public class MessageResponseHandler {
CoreDocument pipelineCoreDcoumentLastMsg = new CoreDocument(userLastMessage); CoreDocument pipelineCoreDcoumentLastMsg = new CoreDocument(userLastMessage);
Datahandler.getPipeline().annotate(pipelineCoreDcoument); Datahandler.getPipeline().annotate(pipelineCoreDcoument);
Datahandler.getPipeline().annotate(pipelineCoreDcoumentLastMsg); Datahandler.getPipeline().annotate(pipelineCoreDcoumentLastMsg);
String regex = "(.*?\\d){10,}";
try { try {
for (CoreEntityMention em : pipelineCoreDcoument.entityMentions()) { for (CoreEntityMention em : pipelineCoreDcoument.entityMentions()) {
String entityType = em.entityType(); String entityType = em.entityType();
@ -72,7 +75,10 @@ public class MessageResponseHandler {
try { try {
String str = strreturn; String str = strreturn;
String emText = em.text(); String emText = em.text();
if (!emText.equals(personName)) { Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(personName);
boolean isMatched = matcher.matches();
if (!emText.equals(personName) && !isMatched) {
for (CoreEntityMention emLastMsg : pipelineCoreDcoumentLastMsg.entityMentions()) { for (CoreEntityMention emLastMsg : pipelineCoreDcoumentLastMsg.entityMentions()) {
if (!emText.equals(emLastMsg.text())) { if (!emText.equals(emLastMsg.text())) {
str = strreturn.replaceFirst(emText, emLastMsg.text()); str = strreturn.replaceFirst(emText, emLastMsg.text());

View File

@ -449,7 +449,11 @@ public class SentimentAnalyzerTest implements Callable<SimilarityMatrix> {
if (dotPrediction2 > 30 && dotPrediction2 < 60) { if (dotPrediction2 > 30 && dotPrediction2 < 60) {
if (dotpredictionTransfer != 0.0 && (subtracter2 / dotPrediction2 < 1.3 || (subtracter2 / dotPrediction2 > 1.9 if (dotpredictionTransfer != 0.0 && (subtracter2 / dotPrediction2 < 1.3 || (subtracter2 / dotPrediction2 > 1.9
&& subtracter2 / dotPrediction2 < 1.99))) { && subtracter2 / dotPrediction2 < 1.99))) {
if (subtracter2 / dotPrediction2 < 1.248 && subtracter2 / dotPrediction2 > 1.238) {
score -= 2500;
} else {
score += 4500; score += 4500;
}
} else if (dotpredictionTransfer != 0.0 && subtracter2 / dotPrediction2 > 1.6 && subtracter2 / dotPrediction2 < 1.95) { } else if (dotpredictionTransfer != 0.0 && subtracter2 / dotPrediction2 > 1.6 && subtracter2 / dotPrediction2 < 1.95) {
if (subtracter2 > 61.1 && subtracter2 < 61.9 && dotPrediction2 > 37.5 && dotPrediction2 < 38.2) { if (subtracter2 > 61.1 && subtracter2 < 61.9 && dotPrediction2 > 37.5 && dotPrediction2 < 38.2) {
score += 4500; score += 4500;