From 6d7a4e52ee1aa773341dc5b1b12921fa0d003830 Mon Sep 17 00:00:00 2001 From: christian Date: Thu, 9 Dec 2021 12:14:09 +0100 Subject: [PATCH] added lemma nullchecks to avoid nullpointers --- .../StanfordParser/SentimentAnalyzerTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java index 8b0f28a9..6b254390 100644 --- a/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java +++ b/ArtificialAutism/src/main/java/FunctionLayer/StanfordParser/SentimentAnalyzerTest.java @@ -887,7 +887,7 @@ public class SentimentAnalyzerTest { if (sentenceConstituencyParse2 != null && !sentenceConstituencyParse2.isEmpty()) { for (CoreLabel LBW : sentenceConstituencyParse1.taggedLabeledYield()) { for (CoreLabel LBW1 : sentenceConstituencyParse2.taggedLabeledYield()) { - if (LBW.lemma().equals(LBW1.lemma())) { + if (LBW.lemma() != null && LBW1.lemma() != null && LBW.lemma().equals(LBW1.lemma())) { boolean found = false; for (String str : filerTreeContent) { if (str.equals(LBW.lemma())) { @@ -895,7 +895,7 @@ public class SentimentAnalyzerTest { break; } } - if (!found) { + if (!found && LBW.lemma() != null) { filerTreeContent.add(LBW.lemma()); runCount1++; } @@ -2151,9 +2151,11 @@ public class SentimentAnalyzerTest { for (CoreLabel token : tokensSentiment) { Set stopWords = StopAnalyzer.ENGLISH_STOP_WORDS_SET; Set stopWordsCustom = StopwordAnnotator.getStopWordList(customStopWordList, true); - String lemma = token.lemma().toLowerCase(); - if (stopWords.contains(lemma) || stopWordsCustom.contains(lemma)) { - arrs.add(lemma); + if (token.lemma() != null) { + String lemma = token.lemma().toLowerCase(); + if (stopWords.contains(lemma) || stopWordsCustom.contains(lemma)) { + arrs.add(lemma); + } } } return arrs;