From d62cdf3aeb928c7b32134c7dd20a409776162e11 Mon Sep 17 00:00:00 2001 From: jenzur Date: Sat, 3 Aug 2019 14:35:09 +0200 Subject: [PATCH] some bot overhauls --- .../main/java/DataLayer/DBCPDataSource.java | 4 +- .../src/main/java/DataLayer/DataMapper.java | 83 +-- .../main/java/FunctionLayer/Datahandler.java | 262 ++++----- .../FunctionLayer/MessageResponseHandler.java | 5 +- .../java/FunctionLayer/SimilarityMatrix.java | 26 +- .../StanfordParser/SentimentAnalyzerTest.java | 502 +++++++++--------- .../StanfordParser/SentimentValueCache.java | 188 +++---- .../PresentationLayer/DiscordHandler.java | 15 +- 8 files changed, 491 insertions(+), 594 deletions(-) diff --git a/ArtificialAutism/src/main/java/DataLayer/DBCPDataSource.java b/ArtificialAutism/src/main/java/DataLayer/DBCPDataSource.java index f9752479..38ef83f8 100644 --- a/ArtificialAutism/src/main/java/DataLayer/DBCPDataSource.java +++ b/ArtificialAutism/src/main/java/DataLayer/DBCPDataSource.java @@ -20,9 +20,9 @@ public class DBCPDataSource { static { try { ds.setDriver(new com.mysql.cj.jdbc.Driver()); - ds.setUrl("jdbc:mysql://104.248.40.216:3306/ArtificialAutism?useLegacyDatetimeCode=false&serverTimezone=UTC"); + ds.setUrl("jdbc:mysql://163.172.84.14:3306/ArtificialAutism?useLegacyDatetimeCode=false&serverTimezone=UTC"); ds.setUsername("root"); - ds.setPassword("fb345972349fnsDW234/ยค)#2"); + ds.setPassword("FJEF23423u5r9BFhBFEBFIB234h29"); ds.setMaxTotal(-1); ds.setMinIdle(5); ds.setMaxIdle(-1); diff --git a/ArtificialAutism/src/main/java/DataLayer/DataMapper.java b/ArtificialAutism/src/main/java/DataLayer/DataMapper.java index 96a234fa..40965470 100644 --- a/ArtificialAutism/src/main/java/DataLayer/DataMapper.java +++ b/ArtificialAutism/src/main/java/DataLayer/DataMapper.java @@ -38,12 +38,6 @@ public class DataMapper { + "ENGINE = InnoDB;"; l_pStatement = l_cCon.prepareStatement(l_sSQL); l_pStatement.execute(); - l_sSQL = "CREATE TABLE IF NOT EXISTS `ArtificialAutism`.`WordMatrix` (`Str1` VARCHAR(254) NOT NULL, `Str2` VARCHAR(254) NOT NULL,\n" - + " `Distance` DOUBLE NOT NULL, `ID` INT NOT NULL AUTO_INCREMENT,\n" - + " PRIMARY KEY (`ID`))\n" - + "ENGINE = InnoDB;"; - l_pStatement = l_cCon.prepareStatement(l_sSQL); - l_pStatement.execute(); } catch (SQLException ex) { throw new CustomError("failed in DataMapper " + ex.getMessage()); } finally { @@ -87,7 +81,7 @@ public class DataMapper { java.sql.ResultSet.CONCUR_READ_ONLY); l_pStatement.setFetchSize(Integer.MIN_VALUE); for (String str1 : str.values()) { - System.out.println("adding str1: " + str1 + "\n"); + //System.out.println("adding str1: " + str1 + "\n"); l_pStatement.setString(1, str1); l_pStatement.addBatch(); } @@ -99,81 +93,6 @@ public class DataMapper { } } - public static int getSementicsDBRows() { - int count = 0; - try (Connection l_cCon = DBCPDataSource.getConnection()) { - try (Statement s = l_cCon.createStatement(); - ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM WordMatrix")) { - r.next(); - count = r.getInt("rowcount"); - } - } catch (SQLException ex) { - Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex); - } - return count; - } - - public static void insertSementicMatrixes(ConcurrentMap WS4JListUpdate) throws CustomError { - Connection l_cCon = null; - PreparedStatement l_pStatement = null; - ResultSet l_rsSearch = null; - String l_sSQL = "INSERT IGNORE `WordMatrix` (`Str1`,`Str2`,`Distance`) VALUES (?, ?, ?)"; - try { - l_cCon = DBCPDataSource.getConnection(); - l_pStatement = l_cCon.prepareStatement(l_sSQL, java.sql.ResultSet.TYPE_FORWARD_ONLY, - java.sql.ResultSet.CONCUR_READ_ONLY); - l_pStatement.setFetchSize(0); - System.out.println("Matrix update size: " + WS4JListUpdate.size()); - for (SimilarityMatrix ws4j : WS4JListUpdate.values()) { - l_pStatement.setString(1, ws4j.getPrimaryString()); - l_pStatement.setString(2, ws4j.getSecondaryString()); - l_pStatement.setDouble(3, ws4j.getDistance()); - l_pStatement.addBatch(); - } - l_pStatement.executeBatch(); - } catch (SQLException ex) { - throw new CustomError("failed in DataMapper " + ex.getMessage()); - } finally { - CloseConnections(l_pStatement, l_rsSearch, l_cCon); - } - } - /* - public static LinkedHashMap> getAllRelationScores() { - int count = getSementicsDBRows(); - LinkedHashMap> LHMSMX = new LinkedHashMap(); - try (Connection l_cCon = DBCPDataSource.getConnection()) { - l_cCon.setAutoCommit(false); - String l_sSQL = "SELECT * FROM `WordMatrix`"; - try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL, java.sql.ResultSet.TYPE_FORWARD_ONLY, - java.sql.ResultSet.CONCUR_READ_ONLY)) { - l_pStatement.setFetchSize(0); - try (ResultSet l_rsSearch = l_pStatement.executeQuery()) { - l_rsSearch.setFetchSize(0); - int i = 0; - LinkedHashMap LHMLocal = new LinkedHashMap(); - while (l_rsSearch.next()) { - String str1 = l_rsSearch.getString(1); - String str2 = l_rsSearch.getString(2); - Double score = l_rsSearch.getDouble(3); - LHMLocal.put(str2, score); - while (l_rsSearch.next() && str1.equals(l_rsSearch.getString(1))) { - str2 = l_rsSearch.getString(2); - score = l_rsSearch.getDouble(3); - LHMLocal.put(str2, score); - i++; - } - LHMSMX.put(str1, LHMLocal); - System.out.println("i: " + i + "\n" + "free memory: " + Runtime.getRuntime().freeMemory() + "\n"); - i++; - } - } - } - } catch (SQLException ex) { - Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex); - } - return LHMSMX; - } - */ public static ConcurrentMap getHLstatsMessages() { ConcurrentMap hlStatsMessages = new MapMaker().concurrencyLevel(2).makeMap(); try (Connection l_cCon = DBCPDataSourceHLstats.getConnection()) { diff --git a/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java b/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java index edd8f350..bcbc7708 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +import java.util.ListIterator; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -37,15 +38,19 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; import java.util.concurrent.Future; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @@ -62,19 +67,15 @@ public class Datahandler { private static Annotation strAnnoJMWE; private static CoreDocument coreDoc; private static final ConcurrentMap stringCache = new MapMaker().concurrencyLevel(2).makeMap(); - private static int positiveRelationCounter = 0; - private static int negativeRelationCounter = 0; + private static int RelationCounter = 0; private static ConcurrentMap pipelineAnnotationCache; private static ConcurrentMap pipelineSentimentAnnotationCache; private static ConcurrentMap jmweAnnotationCache; 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 LinkedHashMap> lHMSMX = new LinkedHashMap(); private final Stopwatch stopwatch; - private static final ForkJoinPool executor = instantiateExecutor(); private static String similar = ""; private static String shiftReduceParserPath = "edu/stanford/nlp/models/srparser/englishSR.ser.gz"; private static String sentimentModel = "edu/stanford/nlp/models/sentiment/sentiment.ser.gz"; @@ -102,7 +103,6 @@ public class Datahandler { this.pipelineAnnotationCache = new MapMaker().concurrencyLevel(4).makeMap(); this.pipelineSentimentAnnotationCache = new MapMaker().concurrencyLevel(4).makeMap(); this.coreDocumentAnnotationCache = new MapMaker().concurrencyLevel(5).makeMap(); - this.conversationMatchMap = new MapMaker().concurrencyLevel(4).makeMap(); this.conversationUserMatchMap = new MapMaker().concurrencyLevel(4).makeMap(); } @@ -182,13 +182,6 @@ public class Datahandler { } } - 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; } @@ -229,7 +222,7 @@ public class Datahandler { hlStatsMessages.put(str, hlStatsMessages.size()); } } - int capacity = 9550; + int capacity = 1500; 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); @@ -274,146 +267,115 @@ public class Datahandler { } } - private ConcurrentMap futuresReturnOverallEvaluation(ConcurrentMap> entries, String str, + private ConcurrentMap futuresReturnOverallEvaluation(List similarityMatrixes, ConcurrentMap strmapreturn) { - for (Entry> entrySet : entries.entrySet()) { - String transmittedStr = entrySet.getKey(); - SimilarityMatrix getSMX = retrieveFutureSMX(entrySet.getValue()); - int handleRetrievedSMX = handleRetrievedSMX(getSMX, transmittedStr); - System.out.println("handleRetrievedSMX: " + handleRetrievedSMX + "\n"); - if (handleRetrievedSMX == 2) { - strmapreturn.put(strmapreturn.size(), str); - break; - } else if (handleRetrievedSMX == 1) { - break; + String newPrimary = similarityMatrixes.get(0).getPrimaryString(); + int evaluationCap = 50000; + boolean hitCap = false; + for (SimilarityMatrix SMX : similarityMatrixes) { + if (!newPrimary.equals(SMX.getPrimaryString())) { + newPrimary = SMX.getPrimaryString(); + strmapreturn = addSMXToMapReturn(strmapreturn, SMX); + hitCap = false; } - if (getSMX != null) { - 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()); + if (!hitCap) { + final Double scoreRelationNewMsgToRecentMsg = SMX.getDistance(); + RelationCounter += scoreRelationNewMsgToRecentMsg > 0 ? scoreRelationNewMsgToRecentMsg * 2 : scoreRelationNewMsgToRecentMsg; + if (RelationCounter > evaluationCap) { + strmapreturn = addSMXToMapReturn(strmapreturn, SMX); + hitCap = true; + } else if (RelationCounter < evaluationCap * -1) { + addSMXToMapReturn(strmapreturn, SMX); + hitCap = true; } } } return strmapreturn; } - private int handleRetrievedSMX(SimilarityMatrix getSMX, 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"); - if (scoreRelationNewMsgToRecentMsg >= 200.0) { - positiveRelationCounter++; - if (positiveRelationCounter >= relationCap) { - return 2; - } - } else if (scoreRelationNewMsgToRecentMsg <= -6000.0) { - negativeRelationCounter += 1; + private ConcurrentMap addSMXToMapReturn(ConcurrentMap strmapreturn, SimilarityMatrix SMX) { + System.out.println("RelationCounter cap: " + RelationCounter); + boolean related = RelationCounter > 0; + if (related) { + strmapreturn.put(strmapreturn.size(), SMX.getPrimaryString()); + String transmittedStr = SMX.getSecondaryString(); + SentimentValueCache cacheValue1 = SMX.getCacheValue1(); + SentimentValueCache cacheValue2 = SMX.getCacheValue2(); + if (cacheValue1 != null && !sentimentCachingMap.keySet().contains(SMX.getPrimaryString())) { + sentimentCachingMap.put(SMX.getPrimaryString(), SMX.getCacheValue1()); } - } else { - Integer getCounts = locateFaultySentences.getOrDefault(transmittedStr, null); - if (getCounts == null) { - locateFaultySentences.put(transmittedStr, 0); - } else { - locateFaultySentences.put(transmittedStr, getCounts + 1); + if (cacheValue2 != null && !sentimentCachingMap.keySet().contains(transmittedStr)) { + sentimentCachingMap.put(transmittedStr, SMX.getCacheValue2()); } } - if (negativeRelationCounter >= relationCap) { - return 1; - } - return 0; + RelationCounter = 0; + return strmapreturn; } - private Entry>, ConcurrentMap> StrComparringNoSentenceRelationMap( + private List 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 -> { - Integer getFaultyOccurences = locateFaultySentences.getOrDefault(e, null); - if (getFaultyOccurences == null || getFaultyOccurences <= 20) { - return false; - } - return true; - }); SentimentValueCache sentimentCacheStr = sentimentCachingMap.getOrDefault(str, null); + List smxReturnList = new ArrayList(); + ExecutorService smxService = Executors.newFixedThreadPool(6); for (String str1 : strCacheLocal.values()) { - //experimental change - if (!str.equals(str1) && !futures.keySet().contains(str1)) { - final SimilarityMatrix SMX = new SimilarityMatrix(str, str1); + if (!str.equals(str1)) { + SimilarityMatrix SMXInit = new SimilarityMatrix(str, str1); SentimentValueCache sentimentCacheStr1 = sentimentCachingMap.getOrDefault(str1, null); - final Callable worker; + Callable worker; if (stringCache.size() < 150) { - worker = new SentimentAnalyzerTest(str, str1, SMX, + worker = new SentimentAnalyzerTest(str, str1, SMXInit, localJMWEMap.get(str), localJMWEMap.get(str1), localPipelineAnnotation.get(str), localPipelineAnnotation.get(str1), localPipelineSentimentAnnotation.get(str), localPipelineSentimentAnnotation.get(str1), localCoreDocumentMap.get(str), localCoreDocumentMap.get(str1), sentimentCacheStr, sentimentCacheStr1); } else { - worker = new SentimentAnalyzerTest(str, str1, SMX, + worker = new SentimentAnalyzerTest(str, str1, SMXInit, localJMWEMap.get(str), jmweAnnotationCache.get(str1), localPipelineAnnotation.get(str), pipelineAnnotationCache.get(str1), localPipelineSentimentAnnotation.get(str), pipelineSentimentAnnotationCache.get(str1), localCoreDocumentMap.get(str), coreDocumentAnnotationCache.get(str1), sentimentCacheStr, sentimentCacheStr1); } - futures.put(str1, executor.submit(worker)); + Future future = smxService.submit(worker); + try { + SimilarityMatrix SMX = future.get(); + if (SMX != null) { + smxReturnList.add(SMX); + } + } catch (InterruptedException | ExecutionException ex) { + //System.out.println("failed future get"); + } } } - Map.Entry>, ConcurrentMap> mapreturn - = new AbstractMap.SimpleEntry(futures, strCacheLocal); - return mapreturn; + return smxReturnList; } private ConcurrentMap stringIteratorComparator(ConcurrentMap strmap, ConcurrentMap strCacheLocal, ConcurrentMap localJMWEMap, ConcurrentMap localPipelineAnnotation, ConcurrentMap localPipelineSentimentAnnotation, ConcurrentMap localCoreDocumentMap) { - int i = 0; - ConcurrentMap strmapreturn = new MapMaker().concurrencyLevel(4).makeMap(); + ConcurrentMap strmapreturn = new MapMaker().concurrencyLevel(6).makeMap(); + List strSenseRelationMap = new ArrayList(); for (String str : strmap.values()) { - Integer getFaultyOccurences = locateFaultySentences.getOrDefault(str, null); - if (getFaultyOccurences == null || getFaultyOccurences <= 20) { - positiveRelationCounter = 0; - negativeRelationCounter = 0; - Entry>, ConcurrentMap> strRelationMap - = StrComparringNoSentenceRelationMap(strCacheLocal, str, localJMWEMap, localPipelineAnnotation, localPipelineSentimentAnnotation, - localCoreDocumentMap); - strCacheLocal = strRelationMap.getValue(); - final ConcurrentMap> futures = strRelationMap.getKey(); - strmapreturn = futuresReturnOverallEvaluation(futures, str, strmapreturn); - System.out.println("overall advancement of future iterator: " + i + "\nFullMapsize: " + strmap.values().size() - + "\nstrmapreturn size: " + strmapreturn.size() + "\nlocateFaultySentences size: " + locateFaultySentences.size() + "\n"); - i++; + List localNoSentenceRelationList = StrComparringNoSentenceRelationMap(strCacheLocal, str, + localJMWEMap, localPipelineAnnotation, localPipelineSentimentAnnotation, localCoreDocumentMap); + for (SimilarityMatrix SMX : localNoSentenceRelationList) { + strSenseRelationMap.add(SMX); } } + Collections.sort(strSenseRelationMap, (e1, e2) -> e1.getPrimaryString().compareTo(e2.getPrimaryString())); + strmapreturn = futuresReturnOverallEvaluation(strSenseRelationMap, strmapreturn); return strmapreturn; } - private final ConcurrentMap removeNonSensicalStrings(ConcurrentMap strmap) { + private ConcurrentMap removeNonSensicalStrings(ConcurrentMap strmap) { final ConcurrentMap strCacheLocal = stringCache.size() < 150 ? strmap : stringCache; final ConcurrentMap localJMWEMap = getMultipleJMWEAnnotation(strmap.values()); final ConcurrentMap localPipelineAnnotation = getMultiplePipelineAnnotation(strmap.values()); final ConcurrentMap localPipelineSentimentAnnotation = getMultiplePipelineSentimentAnnotation(strmap.values()); final ConcurrentMap localCoreDocumentMap = getMultipleCoreDocumentsWaySuggestion(strmap.values(), pipeline); - System.out.println("finished removeNonSensicalStrings annotations \n"); return stringIteratorComparator(strmap, strCacheLocal, localJMWEMap, localPipelineAnnotation, localPipelineSentimentAnnotation, localCoreDocumentMap); } - private static SimilarityMatrix retrieveFutureSMX(Future future) { - try { - // 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(); @@ -422,7 +384,6 @@ public class Datahandler { str = removeSlacks(str); System.out.println("finished removeSlacks \n" + str.size() + "\n"); str = removeNonSensicalStrings(str); - System.out.println("POST removeNonSensicalStrings size: " + str.size() + "\n"); str = annotationCacheUpdate(str); System.out.println("annotationCacheUpdate str size POST: " + str.size() + "\n"); ConcurrentMap strf = str; @@ -461,7 +422,7 @@ public class Datahandler { return str; } - private String getResponseFutures(String strF) { + private String getResponseFutures(String strF, ConcurrentMap mostRecentMsgMap) { ConcurrentMap strCache = stringCache; double preRelationUserCounters = -6500.0; //WHY THE FUCK CANT YOU JUST TRANSFER A SimilarityMatrix OBJECT LIST LIKE ANY OTHER NORMAL COLLECTION, WHY DOES IT HAVE TO BE A FUCKING STRING LIST @@ -475,9 +436,17 @@ public class Datahandler { pipelineSentimentAnnotationCache.get(str1), coreDoc, coreDocumentAnnotationCache.get(str1), null, sentimentCacheStr1); try { SimilarityMatrix getSMX = worker.call(); - //SimilarityMatrix getSMX = executor.submit(worker).get(5, TimeUnit.SECONDS); if (getSMX != null) { + Integer repeatedSentences = mostRecentMsgMap.getOrDefault(getSMX.getSecondaryString(), null); Double scoreRelationLastUserMsg = getSMX.getDistance(); + /* + double oldRelation = overAllOldScoreRelations(getSMX.getSecondaryString()); + if (oldRelation < 0 && conversationUserMatchMap.size() > 1) { + conversationUserMatchMap.clear(); + } else if (oldRelation > 0) { + scoreRelationLastUserMsg += oldRelation; + } + */ if (scoreRelationLastUserMsg > preRelationUserCounters) { preRelationUserCounters = scoreRelationLastUserMsg; concurrentRelations.add(getSMX.getSecondaryString()); @@ -493,7 +462,7 @@ public class Datahandler { } } StringBuilder SB = new StringBuilder(); - double randomLenghtPermit = strF.length() * (Math.random() * 5.5); + double randomLenghtPermit = strF.length() * (Math.random() * 1.5); Collections.reverse(concurrentRelations); for (String secondaryRelation : concurrentRelations) { if (SB.toString().length() > randomLenghtPermit && !SB.toString().isEmpty()) { @@ -506,41 +475,23 @@ public class Datahandler { return SB.toString(); } - private double setupScoreRelationtoRecent(String strF, ConcurrentMap getPrimaryLocal) { - double scoreRelationNewMsgToRecentMsg = 0.0; - for (String conversationStr : conversationMatchMap.values()) { - Double getSecondary = 0.0; - getSecondary = getPrimaryLocal.get(conversationStr); - if (getSecondary == null) { - getSecondary = getScoreRelationStrF(strF, conversationStr); - } - scoreRelationNewMsgToRecentMsg += getSecondary; - System.out.println("scoreRelationNewMsgToRecentMsg: " + scoreRelationNewMsgToRecentMsg + "\n"); - } - return scoreRelationNewMsgToRecentMsg; - } - - private double setupScoreRelationOld(String strF, ConcurrentMap getPrimaryLocal) { - double scoreRelationOldUserMsg = 0.0; - for (String conversationUserStr : conversationUserMatchMap.keySet()) { - if (!strF.equals(conversationUserStr)) { - double getSecondary = getScoreRelationStrF(strF, conversationUserStr); - scoreRelationOldUserMsg += getSecondary; - } - } - return scoreRelationOldUserMsg; - } - - public synchronized String getResponseMsg(String str, String MostRecent) throws CustomError { - String strF = trimString(str); - getSingularAnnotation(strF); - if (!conversationMatchMap.values().contains(MostRecent) && !MostRecent.isEmpty()) { - conversationMatchMap.put(conversationMatchMap.size(), MostRecent); - } + private double overAllOldScoreRelations(String strF) { if (!conversationUserMatchMap.keySet().contains(strF)) { conversationUserMatchMap.put(strF, conversationUserMatchMap.size()); } - return getResponseFutures(strF); + double sentenceContinuity = -500.0; + for (String conversationUserStr : conversationUserMatchMap.keySet()) { + if (!strF.equals(conversationUserStr)) { + sentenceContinuity += getScoreRelationStrF(strF, conversationUserStr); + } + } + return sentenceContinuity; + } + + public synchronized String getResponseMsg(String str, ConcurrentMap mostRecentMsgMap) throws CustomError { + String strF = trimString(str); + getSingularAnnotation(strF); + return getResponseFutures(strF, mostRecentMsgMap); } public void getSingularAnnotation(String str) { @@ -767,7 +718,7 @@ public class Datahandler { } if (!tooclosematch) { strreturn.put(strreturn.size() + 1, str1); - System.out.println("adding strreturn str1: " + str1 + "\n"); + //System.out.println("adding strreturn str1: " + str1 + "\n"); } }); return strreturn; @@ -814,42 +765,35 @@ public class Datahandler { private static class AnnotationCollector implements Consumer { private static int i = 0; - private final List annotationsT = new ArrayList(); + private List annotationsT = new ArrayList(); @Override - public final void accept(T ann) { + public void accept(T ann) { + //System.out.println("adding ann: " + ann.toString()); annotationsT.add(ann); } } public static ConcurrentMap getMultipleCoreDocumentsWaySuggestion(Collection str, StanfordCoreNLP localNLP) { AnnotationCollector annCollector = new AnnotationCollector(); - System.out.println("processing multiple coreDocuments Annotation: \n"); for (final String exampleString : str) { - //System.out.println("exampleString: " + exampleString + "\n"); + // System.out.println("exampleString: " + exampleString + "\n"); localNLP.annotate(new Annotation(exampleString), annCollector); annCollector.i++; - //System.out.println("iterator: " + annCollector.i + "\nstr size: " + str.size() + "\n"); + // System.out.println("iterator: " + annCollector.i + "\nstr size: " + str.size() + "\n"); } try { - Thread.sleep(10000); + Thread.sleep(4000); } catch (InterruptedException ex) { Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex); } - ConcurrentMap annotationreturnMap = new MapMaker().concurrencyLevel(2).makeMap(); - List coreDocs = annCollector.annotationsT.stream().map(ann -> { - try { - return new CoreDocument(ann); - } catch (Exception ex) { - System.out.println(ex.getLocalizedMessage()); - return null; - } - }).collect(Collectors.toList()); - coreDocs.stream().forEach(CD -> { - if (CD != null) { + ConcurrentMap annotationreturnMap = new MapMaker().concurrencyLevel(6).makeMap(); + for (Annotation ann : annCollector.annotationsT) { + if (ann != null) { + CoreDocument CD = new CoreDocument(ann); annotationreturnMap.put(CD.text(), CD); } - }); + } return annotationreturnMap; } } diff --git a/ArtificialAutism/src/main/java/FunctionLayer/MessageResponseHandler.java b/ArtificialAutism/src/main/java/FunctionLayer/MessageResponseHandler.java index 1c18b0f5..776193d4 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/MessageResponseHandler.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/MessageResponseHandler.java @@ -41,7 +41,8 @@ public class MessageResponseHandler { } } - public synchronized static String selectReponseMessage(String toString, String mostRecentMsg, String personName) throws CustomError { + public synchronized static String selectReponseMessage(String toString, ConcurrentMap mostRecentMsgMap, + String personName) throws CustomError { ConcurrentMap str1 = new MapMaker().concurrencyLevel(2).makeMap(); str1.put(str1.size() + 1, toString); str1 = Datahandler.cutContent(str1, false); @@ -51,7 +52,7 @@ public class MessageResponseHandler { strreturn = str; } } - String getResponseMsg = Datahandler.instance.getResponseMsg(strreturn, mostRecentMsg); + String getResponseMsg = Datahandler.instance.getResponseMsg(strreturn, mostRecentMsgMap); getResponseMsg = checkPersonPresentInSentence(personName, getResponseMsg, strreturn); return getResponseMsg; } diff --git a/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java b/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java index 7ec62657..6fbe8599 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/SimilarityMatrix.java @@ -13,19 +13,11 @@ import FunctionLayer.StanfordParser.SentimentValueCache; */ public class SimilarityMatrix { - private static String PrimaryString; - private static String SecondaryString; - private static double distance; - private static SentimentValueCache cacheValue1; - private static SentimentValueCache cacheValue2; - - public final SentimentValueCache getCacheValue2() { - return cacheValue2; - } - - public final void setCacheValue2(SentimentValueCache cacheValue2) { - SimilarityMatrix.cacheValue2 = cacheValue2; - } + private String PrimaryString; + private String SecondaryString; + private double distance; + private SentimentValueCache cacheValue1; + private SentimentValueCache cacheValue2; public final double getDistance() { return distance; @@ -70,4 +62,12 @@ public class SimilarityMatrix { this.cacheValue1 = cacheValue1; } + public final SentimentValueCache getCacheValue2() { + return cacheValue2; + } + + public final void setCacheValue2(SentimentValueCache cacheValue2) { + this.cacheValue2 = cacheValue2; + } + } diff --git a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java index 581f2c69..5387a2aa 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java @@ -77,8 +77,8 @@ public class SentimentAnalyzerTest implements Callable { private final Annotation pipelineAnnotation2Sentiment; private final CoreDocument pipelineCoreDcoument1; private final CoreDocument pipelineCoreDcoument2; - private static SentimentValueCache cacheSentiment1; - private static SentimentValueCache cacheSentiment2; + private SentimentValueCache cacheSentiment1; + private SentimentValueCache cacheSentiment2; public final SentimentValueCache getCacheSentiment1() { return cacheSentiment1; @@ -122,7 +122,11 @@ public class SentimentAnalyzerTest implements Callable { private int tokenizeCounting(List> taggedwordlist) { int counter = 0; - return taggedwordlist.stream().map((taggedlist2) -> taggedlist2.size()).reduce(counter, Integer::sum); + Collection taggedCollection = new ArrayList(); + for (List taggedList : taggedwordlist) { + counter += taggedList.size(); + } + return counter; } private ConcurrentMap retrieveTGWListIndex(List> taggedwordlist) { @@ -137,7 +141,11 @@ public class SentimentAnalyzerTest implements Callable { return tgwlistIndex; } - private final Double iterateTrees(ConcurrentMap sentenceConstituencyParseList2, ConcurrentMap sentenceConstituencyParseList1, Double score) { + private Double iterateTrees(ConcurrentMap sentenceConstituencyParseList2, ConcurrentMap sentenceConstituencyParseList1, + Double score) { + double preConstituentsScore = score; + ConcurrentMap constituentsMap = new MapMaker().concurrencyLevel(4).makeMap(); + int constituencySize = sentenceConstituencyParseList1.size() + sentenceConstituencyParseList2.size(); for (final Tree sentenceConstituencyParse2 : sentenceConstituencyParseList2.values()) { int constiRelationsize = 0; for (final Tree sentenceConstituencyParse1 : sentenceConstituencyParseList1.values()) { @@ -154,17 +162,63 @@ public class SentimentAnalyzerTest implements Callable { } 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; + constituentsMap.put(constituentsMap.size(), constituents1); + constituentsMap.put(constituentsMap.size(), constituents2); + constituentsMap.put(constituentsMap.size(), constiRelationsize); + if (constituentsMap.size() < 4) { + if ((constituents1 * 5 < constituents2 || constituents2 * 5 < constituents1) && constituents1 > 0 && constituents2 > 0) { + score -= (constituents1 + constituents2) * 200; + } else if ((constituents1 == 0 || constituents2 == 0) && (constituents1 >= constituents2 + 4 || constituents2 >= constituents1 + 4)) { + score -= constituents1 > constituents2 ? constituents1 * 500 : constituents2 * 500; + } else if (constiRelationsize >= constituents1 + constituents2 && (constituents1 > 2 && constituents2 > 2)) { + score += (constiRelationsize + constituents1 + constituents2) * 350; + } else if (constituents1 >= 2 && constituents2 >= 2 && constituents1 * 1.5 > constituents2 && constituents2 * 1.5 > constituents1) { + if (constituents1 == constituents2 && constiRelationsize - constituents1 == 1) { + score += (constiRelationsize + constituents1 + constituents2) * 1550; + } else if (constiRelationsize >= constituents1 && constituents1 == constituents2) { + score -= (constiRelationsize + constituents1 + constituents2) * 550; + } else if (constiRelationsize < constituents1 && constiRelationsize < constituents2) { + score += 800; + } else if ((constiRelationsize == constituents1 || constiRelationsize == constituents2) && constituents1 * 1.5 > constituents2 + && constituents2 * 1.5 > constituents1) { + score += (constiRelationsize + constituents1 + constituents2) * 350; + } + } else if (constiRelationsize > constituents1 + constituents2) { + score += 2500; + } else if (constiRelationsize * 5 < constituents1 || constiRelationsize * 5 < constituents2) { + score -= (constituents1 + constituents2) * 400; + } } else { - score += constiRelationsize * 160; - //System.out.println("score post constiRelationsize: " + score + "\nconstituents1: " + constituents1 - // + "\nconstituents2: " + constituents2 + "\nconstiRelationsize: " + constiRelationsize + "\n"); + score = preConstituentsScore; + int n1 = constituentsMap.get(0); + int n2 = constituentsMap.get(1); + int n3 = constituentsMap.get(2); + int cap = 0; + if (n1 > n2 && n1 > n3) { + cap = n1; + } else if (n2 > n3 && n2 > n1) { + cap = n2; + } else { + cap = n3; + } + int overheat = 0; + for (int iterator = 3; iterator < constituentsMap.size(); iterator++) { + Integer getConstituent = constituentsMap.get(iterator); + if (getConstituent > cap) { + overheat++; + } + } + if (overheat > 1) { + score -= overheat * 800; + } else { + score += 1300; + } } } } + if (constituencySize > 10) { + score -= constituencySize * 400; + } return score; } @@ -177,67 +231,67 @@ public class SentimentAnalyzerTest implements Callable { int relationApplicable2 = 0; int grammaticalRelation1 = 0; int grammaticalRelation2 = 0; - //believe in faith + List treeCollectionGramatical = new ArrayList(); + List treeCollectionReln = new ArrayList(); 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)) { + if (grammaticalRelation.isApplicable(sentenceConstituencyParse2) && !treeCollectionGramatical.contains(sentenceConstituencyParse2)) { score += 700; - // System.out.println("grammaticalRelation applicable score: " + score + "\n"); grammaticalRelation1++; + treeCollectionGramatical.add(sentenceConstituencyParse2); } GrammaticalRelation reln = TDY1.reln(); - //sentenceConstituencyParse1 - if (reln.isApplicable(sentenceConstituencyParse2)) { + if (reln.isApplicable(sentenceConstituencyParse2) && !treeCollectionReln.contains(sentenceConstituencyParse2)) { score += 525; - // System.out.println("reln1 applicable score: " + score + "\n"); relationApplicable1++; + treeCollectionReln.add(sentenceConstituencyParse2); } } } } + treeCollectionGramatical = new ArrayList(); + treeCollectionReln = new ArrayList(); 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)) { + if (grammaticalRelation.isApplicable(sentenceConstituencyParse1) && !treeCollectionGramatical.contains(sentenceConstituencyParse1)) { score += 700; - // System.out.println("grammaticalRelation applicable score: " + score + "\n"); grammaticalRelation2++; + treeCollectionGramatical.add(sentenceConstituencyParse1); } GrammaticalRelation reln = TDY.reln(); //sentenceConstituencyParse1 - if (reln.isApplicable(sentenceConstituencyParse1)) { + if (reln.isApplicable(sentenceConstituencyParse1) && !treeCollectionReln.contains(sentenceConstituencyParse1)) { score += 525; - // System.out.println("reln2 applicable score: " + score + "\n"); relationApplicable2++; + treeCollectionReln.add(sentenceConstituencyParse1); } } } } - // System.out.println("\ngrammaticalRelation1: " + grammaticalRelation1 + "\ngrammaticalRelation2: " + grammaticalRelation2 + "\n"); if ((grammaticalRelation1 == 0 && grammaticalRelation2 > 4) || (grammaticalRelation2 == 0 && grammaticalRelation1 > 4)) { score -= 3450; - // System.out.println("grammaticalRelation score trim: " + score + "\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) { + if (allTypeDep1 > 0 && allTypeDep2 > 0 && (allTypeDep1 >= 5 || allTypeDep2 >= 5)) { + if ((allTypeDep1 + 1 == allTypeDep2 || allTypeDep2 + 1 == allTypeDep1)) { score += allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 160 : (allTypeDep2 - allTypeDep1) * 160; - // System.out.println(" allTypeDep plus score: " + score + "\nallTypeDep1: " + allTypeDep1 + "\nallTypeDep2: " - // + allTypeDep2 + "\n"); + } else if (allTypeDep1 * 2.5 >= allTypeDep2 && allTypeDep2 * 2.5 >= allTypeDep1) { + score += allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 260 : (allTypeDep2 - allTypeDep1) * 260; + } else if (allTypeDep1 >= 5 && allTypeDep1 <= 10 && allTypeDep2 >= 5 && allTypeDep2 <= 10) { + score += allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 260 : (allTypeDep2 - allTypeDep1) * 260; } else { score -= allTypeDep1 > allTypeDep2 ? (allTypeDep1 - allTypeDep2) * 600 : (allTypeDep2 - allTypeDep1) * 600; - // System.out.println(" allTypeDep minus score: " + score + "\nallTypeDep1: " + allTypeDep1 + "\nallTypeDep2: " - // + allTypeDep2 + "\n"); } alltypeDepsSizeMap.put(alltypeDepsSizeMap.size() + 1, allTypeDep1); alltypeDepsSizeMap.put(alltypeDepsSizeMap.size() + 1, allTypeDep2); @@ -251,43 +305,32 @@ public class SentimentAnalyzerTest implements Callable { && !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) { - score += 1500; - // System.out.println("score relationApplicable equal: " + score + "\n"); + score += 600; } 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); @@ -305,7 +348,6 @@ public class SentimentAnalyzerTest implements Callable { } } score += runCount1.get() * 250; - //System.out.println("score pre typeSizeSmallest: " + score + "\n"); int typeSizeSmallest = 100; int typeSizeLargest = 0; for (Integer i : alltypeDepsSizeMap.values()) { @@ -336,6 +378,11 @@ public class SentimentAnalyzerTest implements Callable { } private Double simpleRNNMatrixCalculations(Double score, ConcurrentMap simpleSMXlist1, ConcurrentMap simpleSMXlist2) { + List iteratedDoubleList = new ArrayList(); + List iterateddotPredictions = new ArrayList(); + double dotpredictionTransfer = 0.0; + int iterationOverHeat = 0; + double scoreFallback = score; for (SimpleMatrix simpleSMX2 : simpleSMXlist2.values()) { ConcurrentMap AccumulateDotMap = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap subtractorMap = new MapMaker().concurrencyLevel(2).makeMap(); @@ -353,25 +400,20 @@ public class SentimentAnalyzerTest implements Callable { 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: " + dotPrediction1 + "\n"); + dotpredictionTransfer = dotPrediction1; 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 + "\n"); } - // System.out.println("transferDots: " + transferDots + "\n"); } DotOverTransfer.put(DotOverTransfer.size(), dotPrediction1); } else { - // System.out.println("subtracter1 pre: " + subtracter1 + "\n"); subtracter1 -= 100; subtracter1 *= 25; score += subtracter1 * dotPrediction1; - // System.out.println("subtracter1 post: " + subtracter1 + "\n"); - // System.out.println("score minus subtracter * dotPrediction 2: " + score + "\ndotPrediction1: " + dotPrediction1 + "\n"); } dotPredictions.put(dotPredictions.size() + 1, dotPrediction1); if (!dotPredictions.values().contains(dotPrediction2)) { @@ -380,9 +422,7 @@ public class SentimentAnalyzerTest implements Callable { totalSubtraction += transferDots; } else { score -= subtracter1 * 25; - // System.out.println("score minus subtracter: " + score + "\n"); } - // System.out.println("transferDots: " + transferDots + "\n"); } DotOverTransfer.put(DotOverTransfer.size(), dotPrediction2); if (dotPrediction2 > largest) { @@ -393,58 +433,81 @@ public class SentimentAnalyzerTest implements Callable { } 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 + "\nsubtracter2: " + subtracter2 + "\n"); } } } else { score -= subtracter2 / 10; } - } else if (dotPrediction2 < 22.0 || dotPrediction2 > 40.0) { - //System.out.println("subtracter2: " + subtracter2 + "\n"); + } else { if (subtracter2 > 55.0 && subtracter2 < 82.0) { - score += subtracter2 * dotPrediction2; - // System.out.println("score: " + score + "\ndotPrediction2: " + dotPrediction2 + "\n"); + if (dotPrediction2 > 30 && dotPrediction2 < 60) { + if (dotpredictionTransfer != 0.0 && (subtracter2 / dotPrediction2 < 1.3 || (subtracter2 / dotPrediction2 > 1.9 + && subtracter2 / dotPrediction2 < 1.99))) { + score += 4500; + } 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) { + score += 4500; + } else { + score -= 4500; + } + } else if (!iterateddotPredictions.contains(dotPrediction2)) { + score -= subtracter2 * dotPrediction2; // += + iterateddotPredictions.add(dotPrediction2); + } else { + score -= 550; + } + } else if (dotPrediction2 < 25 && subtracter2 < 75) { + score -= dotPrediction2 * 250; + } else if (subtracter2 > 75.0) { + if (dotPrediction2 > 20.0 && dotPrediction2 < 23.0) { + score += 3500; + } else { + if (subtracter2 < 75.9 && dotPrediction2 > 24.0 && dotPrediction2 < 24.9) { + score += (subtracter2 * dotPrediction2) * 5; + } else { + score -= 4500; + } + } + } } } dotPredictions.put(dotPredictions.size() + 1, dotPrediction2); + iterationOverHeat++; } - // System.out.println("score post subtracter1: " + score + "\n"); Double subTracPre = 0.0; for (Double subtractors : subtractorMap.values()) { - if (Objects.equals(subTracPre, subtractors) && subTracPre < 70.0 && subTracPre > 20.0) { - score += (subTracPre * 10) / subtractorMap.values().size(); - // System.out.println("score subTracPre plus equals: " + score + "\nsubTracPre: " + subTracPre + "\n"); - } else { - if (subTracPre > 0.0) { - score -= (subTracPre * 50) / subtractorMap.values().size(); - } else { - score += (subTracPre * 50) / subtractorMap.values().size(); + if (Objects.equals(subTracPre, subtractors)) { + if (subTracPre > 43.5 && subTracPre < 50.0) { + score += (subTracPre * 15) / subtractorMap.values().size(); + } else if (subTracPre > 60.0 && subTracPre < 66.5) { + score += (subTracPre * 15) / subtractorMap.values().size(); } - // System.out.println("score subTracPre minus equals: " + score + "\nsubTracPre: " + subTracPre + "\n"); + } else if (subTracPre > 75.0 && subTracPre < 90.0) { + score += (subTracPre * 50) / subtractorMap.values().size(); + } else if (subTracPre >= 55.0) { + score -= 2800; + } else if (subTracPre < -25.0 && subTracPre > -45.0) { + score += subTracPre * 100; } 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; - // System.out.println("score minus postAccumulatorDot: " + score + "\n"); } postAccumulatorDot = accumulators; } @@ -452,23 +515,32 @@ public class SentimentAnalyzerTest implements Callable { } subTracPre = 0.0; for (Double subtractors : subtractorMap.values()) { - if (Objects.equals(subTracPre, subtractors)) { - score += 500; - // System.out.println("score minus subTracPre: " + score + "\n"); + if (Objects.equals(subTracPre, subtractors) && subTracPre != 0.0) { + if (!iteratedDoubleList.contains(subTracPre)) { + score += 500; + iteratedDoubleList.add(subTracPre); + } else { + score -= 150; + } } subTracPre = subtractors; } } + if (iterationOverHeat > 12) { + score = scoreFallback; + score -= 2500; + } 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(); + private Double simpleRNNMaxtrixVectors(Double score, ConcurrentMap simpleSMXlistVector1, ConcurrentMap simpleSMXlistVector2) { + ConcurrentMap elementSumCounter = new MapMaker().concurrencyLevel(3).makeMap(); + ConcurrentMap dotMap = new MapMaker().concurrencyLevel(3).makeMap(); + ConcurrentMap elementSumMap = new MapMaker().concurrencyLevel(3).makeMap(); + ConcurrentMap dotSumMap = new MapMaker().concurrencyLevel(3).makeMap(); Double preDot = 0.0; Double postDot = 0.0; + int iterateSize = simpleSMXlistVector1.values().size() + simpleSMXlistVector2.values().size(); for (SimpleMatrix simpleSMX2 : simpleSMXlistVector2.values()) { for (SimpleMatrix simpleSMX1 : simpleSMXlistVector1.values()) { double dot2 = simpleSMX2.dot(simpleSMX1); @@ -496,73 +568,69 @@ public class SentimentAnalyzerTest implements Callable { elementSumCounter.put(elementSumCounter.size() + 1, elementSum2); dotMap.put(dotMap.size() + 1, dot2); if (!dotSumMap.values().contains(dot1)) { - if (dot1 < 0.1) { + if (dot1 < 0.1 && dot1 > 0.050) { score += 256; - //System.out.println("score dot < 0.1: " + score + "\ndot: " - // + dot + "\n"); } - if (dot1 > 0.50) { - score -= 1400; + if (dot1 > 0.44 && dot1 < 0.60) { + score -= 2400; + } else if (dot1 > 0.40 && dot1 < 0.445) { + score += 3600; } dotSumMap.put(dotSumMap.size() + 1, dot1); } else { - score -= 250; + score -= 50; } 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; + score -= 50; } 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 if (dot2 > 0.050 && dot2 < 0.10) { + score -= 350; } else { - score -= 250; + score = score > 0 ? score - dot2 * 1200 : score + dot2 * 1200; } 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 if (elementSum2 > 0.050 && elementSum2 < 0.10) { + score += 750; } else { - score -= 250; + score = score > 0 ? score - elementSum2 * 1200 : score + elementSum2 * 1200; } } } + if (iterateSize > 5) { + score -= iterateSize * 400; + } 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"); + private Double elementsAndDotsRelation(Double score, ConcurrentMap dotMap, ConcurrentMap elementSumCounter) { OptionalDouble minvalueDots = dotMap.values().stream().mapToDouble(Double::doubleValue).min(); OptionalDouble maxvalueDots = dotMap.values().stream().mapToDouble(Double::doubleValue).max(); double total = minvalueDots.getAsDouble() + maxvalueDots.getAsDouble(); @@ -572,41 +640,44 @@ public class SentimentAnalyzerTest implements Callable { } 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) { + if (maxvalueDots.getAsDouble() > minvalueDots.getAsDouble() * 10 && (dotsVariance < 0.40 + || dotsVariance > 0.60)) { 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; + } else if (minvalueDots.getAsDouble() * 2 > maxvalueDots.getAsDouble()) { + score -= 3500; } } - //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; + if (elementsVariance != 0.0) { + if (elementsVariance <= 0.01 && maxvalueElements.getAsDouble() <= 0.02) { + if (maxvalueElements.getAsDouble() < 0.01 && minvalueElements.getAsDouble() > -0.02 && minvalueElements.getAsDouble() < 0.0) { + score += 6500; + } else { + score -= 5500; + } + } else if (minvalueElements.getAsDouble() < 0.0 && minvalueElements.getAsDouble() - maxvalueElements.getAsDouble() < 0.50) { + score -= 4500; + } else if (elementsVariance * 2 >= maxvalueElements.getAsDouble() && elementsVariance < 0.1) { + score -= elementsVariance * 86000; + } + } else if (maxvalueElements.getAsDouble() == minvalueElements.getAsDouble() && maxvalueElements.getAsDouble() > 0.40 + && maxvalueElements.getAsDouble() < 0.60) { + score += 600; + } else if (maxvalueElements.getAsDouble() < 0.20 && minvalueElements.getAsDouble() >= 0.15) { + score += 2600; + } else if (maxvalueElements.getAsDouble() == minvalueElements.getAsDouble() && minvalueElements.getAsDouble() == 0.12) { + score += 2600; } return score; } - private final Double sentimentMatrixVariances(Double score, int longest1, int longest2, int mainSentiment1, int mainSentiment2) { - //System.out.println("score post pipelineAnnotation2Sentiment: " + score + "\n"); + private Double sentimentMatrixVariances(Double score, int longest1, int longest2, int mainSentiment1, int mainSentiment2) { if (longest1 != longest2) { long deffLongest = longest1 > longest2 ? longest1 : longest2; long deffshorter = longest1 < longest2 ? longest1 : longest2; @@ -624,7 +695,19 @@ public class SentimentAnalyzerTest implements Callable { score -= (deffLongest - deffshorter) * 50; } if (deffLongest - deffshorter <= 5) { - score += 250; + if (deffLongest < 24 && deffshorter > 20) { + score += 4500; + } else if (deffLongest - deffshorter == 5 && deffshorter >= 19 && deffLongest <= 24) { + score += 4500; + } else { + if (deffshorter > 26 && deffLongest < 35) { + score += 3900; + } else if (deffLongest - deffshorter == 1 && deffshorter > 15 && deffLongest < 25) { + score += 4900; + } else { + score -= 1900; + } + } } } return score; @@ -649,23 +732,20 @@ public class SentimentAnalyzerTest implements Callable { return entry; } - private final Double entryCountsRelation(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + private 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 >= entry2 * 2 || entry2 >= entry1 * 2) && entry1 * 2 >= entry2 && entry2 * 2 >= entry1) { + score -= entry1 > entry2 ? (entry1 - entry2) * 450 : (entry2 - entry1) * 450; + } else if (entry1 * 3 >= entry2 && entry2 * 3 >= entry1) { + score += entry1 > entry2 ? (entry1 - entry2) * 550 : (entry2 - entry1) * 550; } 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; @@ -766,14 +846,11 @@ public class SentimentAnalyzerTest implements Callable { for (int counts : cacheSentimentLocal1.getEntryCounts().values()) { for (int counts1 : cacheSentimentLocal2.getEntryCounts().values()) { if (counts > 0 && counts1 > 0) { - //System.out.println("counts1: " + counts + "\ncounts2: " + counts1 + "\n"); if (counts == counts1 && !countsMap.values().contains(counts)) { score += (counts * 250) / totalsize; - // System.out.println("score post counts plus: " + score + "\ntotalsize: " + totalsize + "\n"); countsMap.put(countsMap.size() + 1, counts); } else if (counts * 3 < counts1 || counts1 * 3 < counts) { score -= 600; - // System.out.println("score post counts minus: " + score + "\n"); } } } @@ -787,7 +864,6 @@ public class SentimentAnalyzerTest implements Callable { for (String strTokenPos2 : cacheSentimentLocal2.getstrTokenEntryPOS().values()) { if (strTokenPos1.equals(strTokenPos2)) { score += 500; - // System.out.println("strTokenEntryPOS score: " + score + "\n"); } } } @@ -795,9 +871,7 @@ public class SentimentAnalyzerTest implements Callable { int posEntrySize2 = cacheSentimentLocal2.getstrTokenEntryPOS().values().size(); if (posEntrySize1 * 3 > posEntrySize2 && posEntrySize2 * 3 > posEntrySize1) { score += posEntrySize1 > posEntrySize2 ? (posEntrySize1 - posEntrySize2) * 700 : (posEntrySize2 - posEntrySize1) * 700; - //System.out.println("posEntrySize plus score: " + score + "\n"); } - // System.out.println("posEntrySize1: " + posEntrySize1 + "\nposEntrySize2: " + posEntrySize2 + "\n"); } return score; } @@ -805,19 +879,15 @@ public class SentimentAnalyzerTest implements Callable { private Double unmarkedPatternCounterScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { int UnmarkedPatternCounter1 = cacheSentimentLocal1.getUnmarkedPatternCounter(); int UnmarkedPatternCounter2 = cacheSentimentLocal2.getUnmarkedPatternCounter(); - // System.out.println("UnmarkedPatternCounter1: " + UnmarkedPatternCounter1 + "\nUnmarkedPatternCounter2: " + UnmarkedPatternCounter2 + "\n"); if (UnmarkedPatternCounter1 > 0 && UnmarkedPatternCounter2 > 0) { if (UnmarkedPatternCounter1 < 100 && UnmarkedPatternCounter2 < 100) { if (UnmarkedPatternCounter1 * 2 > UnmarkedPatternCounter2 && UnmarkedPatternCounter2 * 2 > UnmarkedPatternCounter1) { score += 2500; - // System.out.println("score plus UnmarkedPattern: " + score + "\n"); } else if (UnmarkedPatternCounter1 * 5 < UnmarkedPatternCounter2 || UnmarkedPatternCounter2 * 5 < UnmarkedPatternCounter1) { score -= 4000; - // System.out.println("score minus UnmarkedPattern: " + score + "\n"); } - } else { - score -= 2500; - // System.out.println("score minus UnmarkedPattern10>: " + score + "\n"); + } else if (UnmarkedPatternCounter1 > 500 && UnmarkedPatternCounter2 > 500) { + score -= UnmarkedPatternCounter1 >= UnmarkedPatternCounter2 ? UnmarkedPatternCounter1 * 3 : UnmarkedPatternCounter2 * 3; } } return score; @@ -831,7 +901,6 @@ public class SentimentAnalyzerTest implements Callable { 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)) { @@ -850,7 +919,6 @@ public class SentimentAnalyzerTest implements Callable { || MarkedContiniousCounter2Entries * 5 < MarkedContinuousCounter1 || MarkedContiniousCounter2Entries * 5 < MarkedContinuousCounter2) { score -= MarkedContinuousCounter1 > MarkedContinuousCounter2 ? MarkedContinuousCounter1 * 400 : MarkedContinuousCounter2 * 400; - //System.out.println("score post MarkedContinuousCounter: " + score + "\n"); } } } @@ -864,7 +932,6 @@ public class SentimentAnalyzerTest implements Callable { if (strTokeniPart1.equals(strTokeniPart2) && !strtokensMap.values().contains(strTokeniPart2)) { strtokensMap.put(strtokensMap.size() + 1, strTokeniPart2); score += 800; - // System.out.println("score minus strTokenGetiPart: " + score + "\n"); } } } @@ -874,12 +941,8 @@ public class SentimentAnalyzerTest implements Callable { if (tokenIPartSize1 * 2 > tokenIPartSize2 && tokenIPartSize2 * 2 > tokenIPartSize1) { score += tokenIPartSize1 > tokenIPartSize2 ? (tokenIPartSize1 - tokenIPartSize2) * 700 : (tokenIPartSize2 - tokenIPartSize1) * 700; score += strTokenMapSize * 600; - //System.out.println("tokenIPartSize plus score: " + score + "\ntokenIPartSize1: " + tokenIPartSize1 + "\ntokenIPartSize2: " - // + tokenIPartSize2 + "\nstrTokenMapSize: " + strTokenMapSize + "\n"); } else if (tokenIPartSize1 > 0 && tokenIPartSize2 > 0) { score -= tokenIPartSize1 > tokenIPartSize2 ? (tokenIPartSize1 - tokenIPartSize2) * 700 : (tokenIPartSize2 - tokenIPartSize1) * 700; - // System.out.println("tokenIPartSize minus score: " + score + "\ntokenIPartSize1: " + tokenIPartSize1 + "\ntokenIPartSize2: " - // + tokenIPartSize2 + "\n"); } return score; } @@ -900,7 +963,6 @@ public class SentimentAnalyzerTest implements Callable { score += boundaryLeaks ? 2500 : 2500 / 2; } else if (!boundaryLeaks) { score -= 450; - //System.out.println("boundariyLeacks score: " + score + "\n"); } else { remnantCounter++; } @@ -908,7 +970,6 @@ public class SentimentAnalyzerTest implements Callable { entryTokenMap.put(entryTokenMap.size() + 1, strTokenEntry2); } } - //System.out.println("score pre remnantCounter: " + score + "\n"); score += remnantCounter * 250; return score; } @@ -918,7 +979,7 @@ public class SentimentAnalyzerTest implements Callable { for (String strmapTag : cacheSentimentLocal1.getITokenMapTag().values()) { for (String strmapTag1 : cacheSentimentLocal2.getITokenMapTag().values()) { if (strmapTag.equals(strmapTag1) && !iTokenMapTagsMap.values().contains(strmapTag1)) { - score += 1450; + score -= 1450; iTokenMapTagsMap.put(iTokenMapTagsMap.size() + 1, strmapTag); } } @@ -926,14 +987,13 @@ public class SentimentAnalyzerTest implements Callable { int mapTagsize1 = cacheSentimentLocal1.getITokenMapTag().values().size(); int mapTagsize2 = cacheSentimentLocal2.getITokenMapTag().values().size(); int tokenTagMapSize = iTokenMapTagsMap.values().size(); - if (mapTagsize1 * 2 > mapTagsize2 && mapTagsize2 * 2 > mapTagsize1) { - score += mapTagsize1 > mapTagsize2 ? (mapTagsize1 - mapTagsize2) * 700 : (mapTagsize2 - mapTagsize1) * 700; - score += tokenTagMapSize * 600; - // System.out.println("tokenIPartSize 2 plus score: " + score + "\n"); - //System.out.println("mapTagsize1: " + mapTagsize1 + "\nmapTagsize2: " + mapTagsize2 + "\ntokenTagMapSize: " - // + tokenTagMapSize + "\n"); - } else { - score -= mapTagsize1 > mapTagsize2 ? (mapTagsize1 - mapTagsize2) * 700 : (mapTagsize2 - mapTagsize1) * 700;; + if (mapTagsize1 != 0 && mapTagsize2 != 0) { + if (mapTagsize1 * 2 > mapTagsize2 && mapTagsize2 * 2 > mapTagsize1) { + score += mapTagsize1 > mapTagsize2 ? (mapTagsize1 - mapTagsize2) * 700 : (mapTagsize2 - mapTagsize1) * 700; + score += tokenTagMapSize * 600; + } else { + score -= mapTagsize1 > mapTagsize2 ? (mapTagsize1 - mapTagsize2) * 700 : (mapTagsize2 - mapTagsize1) * 700; + } } return score; } @@ -949,7 +1009,6 @@ public class SentimentAnalyzerTest implements Callable { score -= 1600; } else { score += 500; - //System.out.println("tokenform1size score500: " + score + "\n"); } } } @@ -959,8 +1018,6 @@ public class SentimentAnalyzerTest implements Callable { } 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; @@ -971,9 +1028,8 @@ public class SentimentAnalyzerTest implements Callable { for (String strTokenStem : cacheSentimentLocal1.getstrTokenStems().values()) { for (String strTokenStem1 : cacheSentimentLocal2.getstrTokenStems().values()) { if (strTokenStem.equals(strTokenStem1) && !tokenStemmingMap.values().contains(strTokenStem)) { - score -= 4500; + score += 500; tokenStemmingMap.put(tokenStemmingMap.size() + 1, strTokenStem); - // System.out.println("score minus strTokenStem: " + score + "\n"); } } } @@ -986,38 +1042,33 @@ public class SentimentAnalyzerTest implements Callable { int inflectedCounterNegative = cacheSentimentLocal1.getInflectedCounterNegative() > cacheSentimentLocal2.getInflectedCounterNegative() ? cacheSentimentLocal1.getInflectedCounterNegative() - cacheSentimentLocal2.getInflectedCounterNegative() : cacheSentimentLocal2.getInflectedCounterNegative() - cacheSentimentLocal1.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 && inflectedCounterNegative > 0) { score += ((inflectedCounterPositive1 + inflectedCounterPositive2) * 150) - (inflectedCounterNegative * 10); - // 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"); } } + if (inflectedCounterPositive1 >= 15 && inflectedCounterPositive2 >= 15) { + score -= 4000; + } 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; @@ -1026,26 +1077,29 @@ public class SentimentAnalyzerTest implements Callable { 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 && tokensCounter1 < 4 && tokensCounter2 < 4) { - //8000 score hardcap - score += (tokensCounter1 + tokensCounter2) * 400; - // System.out.println("score plus tokensCounter: " + score + "\n"); + if (tokensCounter1 > tokensCounter2 / 2 && tokensCounter2 > tokensCounter1 / 2 && tokensCounter1 < 10 && tokensCounter2 < 10) { + score += (tokensCounter1 + tokensCounter2) * 500; } else { - score -= 3500; - //System.out.println("score minus tokensCounter: " + score + "\n"); + score -= 500; } } 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"); + if (elseint > 500 && elseint < 2000) { + score += elseint * 10; + } else { + score -= elseint * 15; + } + } else { + if (elseint > 0 && elseint < 1500 && (tokensCounter1 > 0 || tokensCounter2 > 0) && tokensCounter1 <= 2 && tokensCounter2 <= 2) { + score -= elseint * 1.5; + } else if (tokensCounter1 < 5 && tokensCounter2 < 5) { + score -= elseint * (tokensCounter1 + tokensCounter2); + } } } return score; @@ -1078,31 +1132,22 @@ public class SentimentAnalyzerTest implements Callable { } private Double nerEntitiesAndTokenScoring(Double score, SentimentValueCache cacheSentimentLocal1, SentimentValueCache cacheSentimentLocal2) { + List entsCollection = new ArrayList(); for (String strEnts1 : cacheSentimentLocal1.getnerEntities1().values()) { - Collection values = cacheSentimentLocal2.getnerEntities1().values(); - for (String strEnts2 : values) { - if (strEnts1.equalsIgnoreCase(strEnts2)) { + for (String strEnts2 : cacheSentimentLocal2.getnerEntities2().values()) { + if (strEnts1.equalsIgnoreCase(strEnts2) && !entsCollection.contains(strEnts1)) { score += 2500; - //System.out.println("score strEnts1 plus: " + score + "\n"); - } else { - score -= 150; + entsCollection.add(strEnts1); } } } - 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; - } - } + entsCollection = new ArrayList(); 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; + for (String strToken1 : cacheSentimentLocal2.getnerEntityTokenTags().values()) { + if (strToken.equalsIgnoreCase(strToken1) && !entsCollection.contains(strToken)) { + score += 2000; + entsCollection.add(strToken); + } } } return score; @@ -1126,26 +1171,26 @@ public class SentimentAnalyzerTest implements Callable { 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) { + Collection stopWordCollection = new ArrayList(); 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"); + if (stopwords1.equals(stopwords2) && !stopWordCollection.contains(stopwords1)) { + score -= 50; + stopWordCollection.add(stopwords1); } } } + stopWordCollection = new ArrayList(); 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"); + if (stopwords1.equals(stopwords2) && !stopWordCollection.contains(stopwords1)) { + score -= 50; + stopWordCollection.add(stopwords1); } } } @@ -1158,21 +1203,26 @@ public class SentimentAnalyzerTest implements Callable { int stopwordsize2 = cacheSentimentLocal2.getStopwordTokens().values().size(); if (stopwordsize1 * 5 < stopwordsize2 || stopwordsize2 * 5 < stopwordsize1) { score -= stopwordsize1 > stopwordsize2 ? (stopwordsize1 - stopwordsize2) * 850 : (stopwordsize2 - stopwordsize1) * 850; + } else if (stopwordsize1 == stopwordsize2 && stopwordsize1 > 1) { + score -= stopwordsize1 * 450; + } else if ((stopwordsize1 / 2 == stopwordsize2 || stopwordsize2 / 2 == stopwordsize1) && stopwordsize1 + stopwordsize2 >= 4) { + score -= 2500; } else { - score += stopwordsize1 > stopwordsize2 ? (stopwordsize1 - stopwordsize2) * 850 : (stopwordsize2 - stopwordsize1) * 850;; + 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) { + if (pairCounter1 * 5 <= pairCounter2 || pairCounter2 * 5 <= pairCounter1) { score -= pairCounter1 > pairCounter2 ? (pairCounter1 - pairCounter2) * 1500 : (pairCounter2 - pairCounter1) * 1500; + } else if (pairCounter1 == pairCounter2 && pairCounter1 > 1) { + score -= pairCounter1 * 450; + } else if ((pairCounter1 / 2 == pairCounter2 || pairCounter2 / 2 == pairCounter1) && pairCounter1 + pairCounter2 >= 4) { + score -= 2500; } else { score += pairCounter1 > pairCounter2 ? (pairCounter1 - pairCounter2) * 700 : (pairCounter2 - pairCounter1) * 700; } - //System.out.println("score post pairCounter: " + score + "\npairCounter1: " + pairCounter1 + "\npairCounter2: " + pairCounter2 + "\n"); } return score; } @@ -1220,7 +1270,6 @@ public class SentimentAnalyzerTest implements Callable { } score = tgwListScoreIncrementer(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2); - //System.out.println("score post tgwListScoreIncrementer: " + score + "\n"); if (cacheSentiment1 == null) { cacheSentimentLocal1 = GrammaticStructureSetup(cacheSentimentLocal1, pipelineAnnotation1); } @@ -1232,7 +1281,6 @@ public class SentimentAnalyzerTest implements Callable { ConcurrentMap sentenceConstituencyParseList1 = cacheSentiment1 == null ? cacheSentimentLocal1.getSentenceConstituencyParseList() : cacheSentiment1.getSentenceConstituencyParseList(); score = iterateTrees(sentenceConstituencyParseList2, sentenceConstituencyParseList1, score); - //System.out.println("score post iterateTrees: " + score + "\n"); Collection allTypedDependencies2 = cacheSentiment2 == null ? cacheSentimentLocal2.getAllTypedDependencies() : cacheSentiment2.getAllTypedDependencies(); Collection allTypedDependencies1 = cacheSentiment1 == null ? cacheSentimentLocal1.getAllTypedDependencies() @@ -1241,7 +1289,6 @@ public class SentimentAnalyzerTest implements Callable { ConcurrentMap grammaticalMap2 = cacheSentiment2 == null ? cacheSentimentLocal2.getGs() : cacheSentiment2.getGs(); score = typeDependenciesGrammaticalRelation(allTypedDependencies1, allTypedDependencies2, score, grammaticalMap1, grammaticalMap2, sentenceConstituencyParseList1, sentenceConstituencyParseList2); - // System.out.println("score post typeDependenciesGrammaticalRelation: " + score + "\n"); if (cacheSentiment1 == null) { cacheSentimentLocal1 = sentimentCoreAnnotationSetup(pipelineAnnotation1Sentiment, cacheSentimentLocal1); } @@ -1256,13 +1303,10 @@ public class SentimentAnalyzerTest implements Callable { ? cacheSentimentLocal1.getSimpleSMXlistVector() : cacheSentiment1.getSimpleSMXlistVector(); final ConcurrentMap simpleSMXlistVector2 = cacheSentiment2 == null ? cacheSentimentLocal2.getSimpleSMXlistVector() : cacheSentiment2.getSimpleSMXlistVector(); - //System.out.println("score pre simpleRNNMatrixCalculations: " + score + "\n"); score = simpleRNNMatrixCalculations(score, simpleSMXlist1, simpleSMXlist2); - //System.out.println("score pre simpleRNNMaxtrixVectors: " + score + "\n"); 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 pre sentiment trim: " + score + "\n"); score -= (sentiment1 > sentiment2 ? sentiment1 - sentiment2 : sentiment2 - sentiment1) * 500; Map.Entry> classifyRawEvaluationEntry = classifyRawEvaluation(score, cacheSentimentLocal1, cacheSentimentLocal2); @@ -1273,7 +1317,6 @@ public class SentimentAnalyzerTest implements Callable { if (cacheSentiment2 == null) { cacheSentimentLocal2 = classifyRawEvaluationEntry.getValue().getValue(); } - //System.out.println("score post classifyRaw: " + score + "\n"); if (cacheSentiment1 == null) { cacheSentimentLocal1 = setupMainSentimentandLongestVal(pipelineAnnotation1Sentiment, cacheSentimentLocal1); } @@ -1293,31 +1336,18 @@ public class SentimentAnalyzerTest implements Callable { SentimentValueCache scoringCache1 = cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1; SentimentValueCache scoringCache2 = cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2; score = entryCountsRelation(score, scoringCache1, scoringCache2); - //System.out.println("score post entryCountsRelation: " + score + "\n"); score = entryCountsScoring(score, scoringCache1, scoringCache2); - // System.out.println("score post entryCountsScoring: " + score + "\n"); score = tokenEntryPosScoring(score, scoringCache1, scoringCache2); - //System.out.println("score post tokenEntryPosScoring: " + score + "\n"); score = unmarkedPatternCounterScoring(score, scoringCache1, scoringCache2); - // System.out.println("score post UnmarkedPatternCounter: " + score + "\n"); score = markedContiniousCounterScoring(score, scoringCache1, scoringCache2); - // System.out.println("score post markedContiniousCounterScoring: " + score + "\n"); score = strTokensMapScoring(score, scoringCache1, scoringCache2); - // System.out.println("score post strTokensMapScoring: " + score + "\n"); score = strTokenEntryScoring(score, scoringCache1, scoringCache2); - //System.out.println("score post strTokenEntryScoring: " + score + "\n"); 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); - //System.out.println("Score pre annotatorCountScoring: " + score + "\n"); score = annotatorCountScoring(score, scoringCache1, scoringCache2); - //System.out.println("Score pre tokensCounterScoring: " + score + "\n"); 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; @@ -1328,10 +1358,8 @@ public class SentimentAnalyzerTest implements Callable { if (cacheSentiment2 == null) { cacheSentimentLocal2 = setupNEREntitiesAndTokenTags(pipelineCoreDcoument2, cacheSentimentLocal2); } - //System.out.println("score post SentenceScoreDiff trim: " + score + "\n"); score = nerEntitiesAndTokenScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2); - //System.out.println("score post nerEntitiesAndTokenScoring: " + score + "\n"); if (cacheSentiment1 == null) { cacheSentimentLocal1 = setupStoWordTokensLemma(pipelineAnnotation1Sentiment, cacheSentimentLocal1); } @@ -1340,10 +1368,8 @@ public class SentimentAnalyzerTest implements Callable { } score = stopWordTokenLemmaScoring(score, cacheSentiment1 == null ? cacheSentimentLocal1 : cacheSentiment1, cacheSentiment2 == null ? cacheSentimentLocal2 : cacheSentiment2); - //System.out.println("score post stopWordTokenLemmaScoring: " + score + "\n"); 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); diff --git a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java index 5b2efd2e..9efb0aae 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentValueCache.java @@ -21,11 +21,11 @@ import org.ejml.simple.SimpleMatrix; * * @author install1 */ -public final class SentimentValueCache { +public class SentimentValueCache { - private final String sentence; - private static int counter; - private static List> taggedwordlist = new ArrayList(); + private String sentence; + private int counter; + private 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(); @@ -33,17 +33,17 @@ public final class SentimentValueCache { 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 List classifyRaw; + private int mainSentiment = 0; + private int longest = 0; + private int tokensCounter = 0; + private int anotatorcounter = 0; + private int inflectedCounterPositive = 0; + private int inflectedCounterNegative = 0; + private int MarkedContinuousCounter = 0; + private int MarkedContiniousCounterEntries = 0; + private int UnmarkedPatternCounter = 0; + private 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(); @@ -57,261 +57,261 @@ public final class SentimentValueCache { private final ConcurrentMap stopwordTokens = new MapMaker().concurrencyLevel(2).makeMap(); private final ConcurrentMap stopWordLemma = new MapMaker().concurrencyLevel(2).makeMap(); - public final int getPairCounter() { + public int getPairCounter() { return pairCounter; } - public final void setPairCounter(int pairCounter) { - SentimentValueCache.pairCounter = pairCounter; + public void setPairCounter(int pairCounter) { + this.pairCounter = pairCounter; } - public final void addStopWordLemma(String str) { + public void addStopWordLemma(String str) { stopWordLemma.put(stopWordLemma.size(), str); } - public final void addstopwordTokens(String str) { + public void addstopwordTokens(String str) { stopwordTokens.put(stopwordTokens.size(), str); } - public final ConcurrentMap getStopwordTokens() { + public ConcurrentMap getStopwordTokens() { return stopwordTokens; } - public final ConcurrentMap getStopWordLemma() { + public ConcurrentMap getStopWordLemma() { return stopWordLemma; } - public final void addnerEntityTokenTags(String str) { + public void addnerEntityTokenTags(String str) { nerEntityTokenTags.put(nerEntityTokenTags.size(), str); } - public final ConcurrentMap getnerEntityTokenTags() { + public ConcurrentMap getnerEntityTokenTags() { return nerEntityTokenTags; } - public final ConcurrentMap getnerEntities1() { + public ConcurrentMap getnerEntities1() { return nerEntities1; } - public final ConcurrentMap getnerEntities2() { + public ConcurrentMap getnerEntities2() { return nerEntities2; } - public final void addNEREntities1(String str) { + public void addNEREntities1(String str) { nerEntities1.put(nerEntities1.size(), str); } - public final void addNEREntities2(String str) { + public void addNEREntities2(String str) { nerEntities2.put(nerEntities2.size(), str); } - public final void setTaggedwords(List> twlist) { + public void setTaggedwords(List> twlist) { taggedwordlist = twlist; } - public final List> getTaggedwordlist() { + public List> getTaggedwordlist() { return taggedwordlist; } - public final void addEntryCounts(int counts) { + public void addEntryCounts(int counts) { entryCounts.put(entryCounts.size(), counts); } - public final ConcurrentMap getEntryCounts() { + public ConcurrentMap getEntryCounts() { return entryCounts; } - public final void addstrTokenEntryPOS(String str) { + public void addstrTokenEntryPOS(String str) { strTokenEntryPOS.put(strTokenEntryPOS.size(), str); } - public final ConcurrentMap getstrTokenEntryPOS() { + public ConcurrentMap getstrTokenEntryPOS() { return strTokenEntryPOS; } - public final void addstrTokenGetiPart(String str) { + public void addstrTokenGetiPart(String str) { strTokenGetiPart.put(strTokenGetiPart.size(), str); } - public final ConcurrentMap getstrTokenGetiPart() { + public ConcurrentMap getstrTokenGetiPart() { return strTokenGetiPart; } - public final ConcurrentMap getstrTokenGetEntry() { + public ConcurrentMap getstrTokenGetEntry() { return strTokenGetEntry; } - public final void addstrTokenGetEntry(String str) { + public void addstrTokenGetEntry(String str) { strTokenGetEntry.put(strTokenGetEntry.size(), str); } - public final ConcurrentMap getstrTokenForm() { + public ConcurrentMap getstrTokenForm() { return strTokenForm; } - public final void addstrTokenForm(String str) { + public void addstrTokenForm(String str) { strTokenForm.put(strTokenForm.size(), str); } - public final ConcurrentMap getstrTokenStems() { + public ConcurrentMap getstrTokenStems() { return strTokenStems; } - public final void addstrTokenStems(String str) { + public void addstrTokenStems(String str) { strTokenStems.put(strTokenStems.size(), str); } - public final ConcurrentMap getITokenMapTag() { + public ConcurrentMap getITokenMapTag() { return ITokenMapTag; } - public final void addITokenMapTag(String str) { + public void addITokenMapTag(String str) { ITokenMapTag.put(ITokenMapTag.size(), str); } - public final int getUnmarkedPatternCounter() { + public int getUnmarkedPatternCounter() { return UnmarkedPatternCounter; } - public final void setUnmarkedPatternCounter(int UnmarkedPatternCounter) { - SentimentValueCache.UnmarkedPatternCounter = UnmarkedPatternCounter; + public void setUnmarkedPatternCounter(int UnmarkedPatternCounter) { + this.UnmarkedPatternCounter = UnmarkedPatternCounter; } - public final int getMarkedContiniousCounterEntries() { + public int getMarkedContiniousCounterEntries() { return MarkedContiniousCounterEntries; } - public final void setMarkedContiniousCounterEntries(int MarkedContiniousCounterEntries) { - SentimentValueCache.MarkedContiniousCounterEntries = MarkedContiniousCounterEntries; + public void setMarkedContiniousCounterEntries(int MarkedContiniousCounterEntries) { + this.MarkedContiniousCounterEntries = MarkedContiniousCounterEntries; } - public final int getMarkedContinuousCounter() { + public int getMarkedContinuousCounter() { return MarkedContinuousCounter; } - public final void setMarkedContinuousCounter(int MarkedContinuousCounter) { - SentimentValueCache.MarkedContinuousCounter = MarkedContinuousCounter; + public void setMarkedContinuousCounter(int MarkedContinuousCounter) { + this.MarkedContinuousCounter = MarkedContinuousCounter; } - public final int getInflectedCounterNegative() { + public int getInflectedCounterNegative() { return inflectedCounterNegative; } - public final void setInflectedCounterNegative(int inflectedCounterNegative) { - SentimentValueCache.inflectedCounterNegative = inflectedCounterNegative; + public void setInflectedCounterNegative(int inflectedCounterNegative) { + this.inflectedCounterNegative = inflectedCounterNegative; } - public final int getInflectedCounterPositive() { + public int getInflectedCounterPositive() { return inflectedCounterPositive; } - public final void setInflectedCounterPositive(int inflectedCounterPositive) { - SentimentValueCache.inflectedCounterPositive = inflectedCounterPositive; + public void setInflectedCounterPositive(int inflectedCounterPositive) { + this.inflectedCounterPositive = inflectedCounterPositive; } - public final int getAnotatorcounter() { + public int getAnotatorcounter() { return anotatorcounter; } - public final void setAnotatorcounter(int anotatorcounter) { - SentimentValueCache.anotatorcounter = anotatorcounter; + public void setAnotatorcounter(int anotatorcounter) { + this.anotatorcounter = anotatorcounter; } - public final int getTokensCounter() { + public int getTokensCounter() { return tokensCounter; } - public final void setTokensCounter(int tokensCounter) { - SentimentValueCache.tokensCounter = tokensCounter; + public void setTokensCounter(int tokensCounter) { + this.tokensCounter = tokensCounter; } - public final int getMainSentiment() { + public int getMainSentiment() { return mainSentiment; } - public final void setMainSentiment(int mainSentiment) { - SentimentValueCache.mainSentiment = mainSentiment; + public void setMainSentiment(int mainSentiment) { + this.mainSentiment = mainSentiment; } - public final int getLongest() { + public int getLongest() { return longest; } - public final void setLongest(int longest) { - SentimentValueCache.longest = longest; + public void setLongest(int longest) { + this.longest = longest; } - public final List getClassifyRaw() { + public List getClassifyRaw() { return classifyRaw; } - public final void setClassifyRaw(List classifyRaw) { - SentimentValueCache.classifyRaw = classifyRaw; + public void setClassifyRaw(List classifyRaw) { + this.classifyRaw = classifyRaw; } - public final ConcurrentMap getRnnPrediectClassMap() { + public ConcurrentMap getRnnPrediectClassMap() { return rnnPredictClassMap; } - public final void addRNNPredictClass(int rnnPrediction) { + public void addRNNPredictClass(int rnnPrediction) { rnnPredictClassMap.put(rnnPredictClassMap.size(), rnnPrediction); } - public final void addSimpleMatrix(SimpleMatrix SMX) { + public void addSimpleMatrix(SimpleMatrix SMX) { simpleSMXlist.put(simpleSMXlist.size(), SMX); } - public final void addSimpleMatrixVector(SimpleMatrix SMX) { + public void addSimpleMatrixVector(SimpleMatrix SMX) { simpleSMXlistVector.put(simpleSMXlistVector.size(), SMX); } - public final ConcurrentMap getGsMap() { + public ConcurrentMap getGsMap() { return gsMap; } - public final ConcurrentMap getSimpleSMXlist() { + public ConcurrentMap getSimpleSMXlist() { return simpleSMXlist; } - public final ConcurrentMap getSimpleSMXlistVector() { + public ConcurrentMap getSimpleSMXlistVector() { return simpleSMXlistVector; } - public final ConcurrentMap getGs() { + public ConcurrentMap getGs() { return gsMap; } - public final int getCounter() { + public int getCounter() { return counter; } - public final void addGS(GrammaticalStructure gs) { + public void addGS(GrammaticalStructure gs) { gsMap.put(gsMap.size(), gs); } - public final Collection getAllTypedDependencies() { + public Collection getAllTypedDependencies() { return allTypedDependencies; } - public final void addTypedDependencies(Collection TDPlist) { + public void addTypedDependencies(Collection TDPlist) { for (TypedDependency TDP : TDPlist) { allTypedDependencies.add(TDP); } } - public final ConcurrentMap getSentenceConstituencyParseList() { + public ConcurrentMap getSentenceConstituencyParseList() { return sentenceConstituencyParseList; } - public final void addSentenceConstituencyParse(Tree tree) { + public void addSentenceConstituencyParse(Tree tree) { sentenceConstituencyParseList.put(sentenceConstituencyParseList.size(), tree); } - public final void setCounter(int counter) { - SentimentValueCache.counter = counter; + public void setCounter(int counter) { + counter = counter; } - public final String getSentence() { + public String getSentence() { return sentence; } @@ -320,12 +320,12 @@ public final class SentimentValueCache { this.counter = counter; } - public final ConcurrentMap getTgwlistIndex() { + public ConcurrentMap getTgwlistIndex() { return tgwlistIndex; } - public final void addTgwlistIndex(String str) { - tgwlistIndex.put(tgwlistIndex.size(), str); + public void addTgwlistIndex(String str) { + tgwlistIndex.put(tgwlistIndex.size(), str); } public SentimentValueCache(String str) { diff --git a/ArtificialAutism/src/main/java/PresentationLayer/DiscordHandler.java b/ArtificialAutism/src/main/java/PresentationLayer/DiscordHandler.java index 2ad087ff..64d1d930 100644 --- a/ArtificialAutism/src/main/java/PresentationLayer/DiscordHandler.java +++ b/ArtificialAutism/src/main/java/PresentationLayer/DiscordHandler.java @@ -18,9 +18,11 @@ import FunctionLayer.CustomError; import FunctionLayer.Datahandler; import FunctionLayer.MessageResponseHandler; import FunctionLayer.PipelineJMWESingleton; +import com.google.common.collect.MapMaker; import java.io.IOException; import java.sql.SQLException; import java.util.List; +import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; import java.util.logging.Logger; import org.javacord.api.DiscordApi; @@ -33,7 +35,7 @@ import org.javacord.api.entity.user.User; */ public class DiscordHandler { - private static String MostRecentMsg = ""; + private static ConcurrentMap responseTrackerMap = new MapMaker().concurrencyLevel(6).makeMap(); public static void main(String[] args) { System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15"); @@ -83,14 +85,19 @@ public class DiscordHandler { } if (event.getMessage().getMentionedUsers().contains(api.getYourself()) || event.getServerTextChannel().get().toString().contains("general-autism")) { - String ResponseStr; try { + String ResponseStr; String person = event.getMessageAuthor().getName(); - ResponseStr = MessageResponseHandler.selectReponseMessage(event.getMessage().toString(), MostRecentMsg, person); + ResponseStr = MessageResponseHandler.selectReponseMessage(event.getMessage().toString(), responseTrackerMap, person); if (!ResponseStr.isEmpty()) { System.out.print("\nResponseStr3: " + ResponseStr + "\n"); event.getChannel().sendMessage(ResponseStr); - MostRecentMsg = ResponseStr; + Integer responseTracker = responseTrackerMap.getOrDefault(ResponseStr, null); + if (responseTracker == null) { + responseTrackerMap.put(ResponseStr, 0); + } else { + responseTrackerMap.put(ResponseStr, responseTracker + 1); + } } } catch (CustomError ex) { Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);