From: <dfl...@us...> - 2013-09-09 10:10:58
|
Revision: 4097 http://sourceforge.net/p/dl-learner/code/4097 Author: dfleischhacker Date: 2013-09-09 10:10:55 +0000 (Mon, 09 Sep 2013) Log Message: ----------- Fix NPE Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/LinguisticUtil.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/LinguisticUtil.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/LinguisticUtil.java 2013-09-06 14:10:41 UTC (rev 4096) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/LinguisticUtil.java 2013-09-09 10:10:55 UTC (rev 4097) @@ -6,7 +6,6 @@ import org.dllearner.algorithms.isle.WordNet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; /** @@ -27,6 +26,15 @@ return instance; } + public LinguisticUtil() { + try { + lemmatizer = new DefaultLemmatizer(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + /** * Processes the given string and puts camelCased words into single words. * @param camelCase the word containing camelcase to split @@ -119,7 +127,7 @@ boolean first = true; ArrayList<String> singleWords = new ArrayList<String>(); - Collections.addAll(singleWords, word.split(" ")); + Collections.addAll(singleWords, word.trim().split(" ")); for (String w : singleWords) { try { @@ -129,20 +137,29 @@ else { res.append(" "); } - if (lemmatizer == null) { - res.append(w); - } - else { - res.append(lemmatizer.lemmatize(w)); - } + res.append(lemmatizeSingleWord(word)); } catch (Exception e) { - e.printStackTrace(); + throw new RuntimeException(e); } } return res.toString(); } + private String lemmatizeSingleWord(String word) { + try { + if (lemmatizer == null) { + return word; + } + else { + return lemmatizer.lemmatize(word); + } + } + catch (NullPointerException e) { + return word; + } + } + public static void main(String[] args) { System.out.println(LinguisticUtil.getInstance().getNormalizedForm("going")); for (String s : LinguisticUtil.getInstance().getWordsFromCamelCase("thisIsAClassWith1Name123")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |