From feaf9b0adcce4bec725114595c0ff2ff13b499ec Mon Sep 17 00:00:00 2001 From: jenzur Date: Fri, 29 Mar 2019 13:19:09 +0100 Subject: [PATCH] minor fix --- .../main/java/FunctionLayer/Datahandler.java | 99 +++++++++---------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java b/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java index 05b8722c..44a08fc2 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/Datahandler.java @@ -297,71 +297,66 @@ public class Datahandler { selectUpdate = secondaryIterator; secondaryIterator += iteratorCap; } - final ConcurrentMap getStringCacheMap = new MapMaker().concurrencyLevel(2).makeMap(); - for (int i = 0; i < iteratorCap; i++) { - getStringCacheMap.put(i, stringCachelocal.get(selectUpdate)); - selectUpdate++; - } + String getStringCacheStr = stringCachelocal.get(selectUpdate); ConcurrentMap matrixUpdateMap = new MapMaker().concurrencyLevel(2).makeMap(); ConcurrentMap> futures = new MapMaker().concurrencyLevel(2).makeMap(); - getStringCacheMap.values().forEach((getStringCacheStr) -> { - stringCachelocal.values().forEach((str1) -> { - if (!getStringCacheStr.equals(str1)) { - boolean present = false; - LinkedHashMap orDefault = lHMSMX.getOrDefault(getStringCacheStr, null); + stringCachelocal.values().forEach((str1) -> { + if (!getStringCacheStr.equals(str1)) { + boolean present = false; + LinkedHashMap orDefault = lHMSMX.getOrDefault(getStringCacheStr, null); + if (orDefault != null) { + Collection strkeys = orDefault.keySet(); + for (String strkey : strkeys) { + if (strkey.equals(str1)) { + present = true; + break; + } + } + } + if (!present) { + orDefault = lHMSMX.getOrDefault(str1, null); if (orDefault != null) { Collection strkeys = orDefault.keySet(); for (String strkey : strkeys) { - if (strkey.equals(str1)) { + if (strkey.equals(getStringCacheStr)) { present = true; break; } } } - if (!present) { - orDefault = lHMSMX.getOrDefault(str1, null); - if (orDefault != null) { - Collection strkeys = orDefault.keySet(); - for (String strkey : strkeys) { - if (strkey.equals(getStringCacheStr)) { - present = true; - break; - } - } - } - } - if (!present) { - LinkedHashMap orDefault1 = lHMSMX.getOrDefault(getStringCacheStr, null); - if (orDefault1 == null) { - orDefault1 = new LinkedHashMap(); - } - orDefault1.put(str1, 0.0); - lHMSMX.put(getStringCacheStr, orDefault1); - SimilarityMatrix SMX = new SimilarityMatrix(getStringCacheStr, str1); - Callable worker = new SentimentAnalyzerTest(getStringCacheStr, str1, SMX, jmweAnnotationCache.get(getStringCacheStr), - jmweAnnotationCache.get(str1), pipelineAnnotationCache.get(getStringCacheStr), pipelineAnnotationCache.get(str1), - pipelineSentimentAnnotationCache.get(getStringCacheStr), pipelineSentimentAnnotationCache.get(str1)); - futures.put(futures.size() + 1, executor.submit(worker)); + } + if (!present) { + LinkedHashMap orDefault1 = lHMSMX.getOrDefault(getStringCacheStr, null); + if (orDefault1 == null) { + orDefault1 = new LinkedHashMap(); } + orDefault1.put(str1, 0.0); + lHMSMX.put(getStringCacheStr, orDefault1); + SimilarityMatrix SMX = new SimilarityMatrix(getStringCacheStr, str1); + Callable worker = new SentimentAnalyzerTest(getStringCacheStr, str1, SMX, jmweAnnotationCache.get(getStringCacheStr), + jmweAnnotationCache.get(str1), pipelineAnnotationCache.get(getStringCacheStr), pipelineAnnotationCache.get(str1), + pipelineSentimentAnnotationCache.get(getStringCacheStr), pipelineSentimentAnnotationCache.get(str1)); + futures.put(futures.size() + 1, executor.submit(worker)); } - }); - System.out.println("finished worker assignment, futures size: " + futures.size() + "\n"); - futures.values().parallelStream().forEach((future) -> { - SimilarityMatrix SMX = new SimilarityMatrix("", ""); - try { - SMX = future.get(5, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException ex) { - Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex); - SMX = null; - } - if (SMX != null) { - LinkedHashMap getFuture = lHMSMX.getOrDefault(SMX.getPrimaryString(), null); - getFuture.put(SMX.getSecondaryString(), SMX.getDistance()); - lHMSMX.put(SMX.getPrimaryString(), getFuture); - matrixUpdateMap.put(matrixUpdateMap.size() + 1, SMX); - } - }); + } }); + System.out.println("finished worker assignment, futures size: " + futures.size() + "\n"); + futures.values().parallelStream().forEach((future) -> { + SimilarityMatrix SMX = new SimilarityMatrix("", ""); + try { + SMX = future.get(5, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException ex) { + Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex); + SMX = null; + } + if (SMX != null) { + LinkedHashMap getFuture = lHMSMX.getOrDefault(SMX.getPrimaryString(), null); + getFuture.put(SMX.getSecondaryString(), SMX.getDistance()); + lHMSMX.put(SMX.getPrimaryString(), getFuture); + matrixUpdateMap.put(matrixUpdateMap.size() + 1, SMX); + } + }); + new Thread(() -> { try { if (!matrixUpdateMap.isEmpty()) {