X-Git-Url: https://wpitchoune.net/gitweb/?a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2FOpenNLP.java;h=e158a00b07d13ef27b937b1179bf3b80a02affb7;hb=9ff314621235d6b748abb128edf0331480d0eaaf;hp=07fbba5603211b04f6936d66837b695712b133cb;hpb=c6f5722d9572158f0d561819f080f8ccf4e3c7d9;p=pnews.git diff --git a/war/src/main/java/pnews/OpenNLP.java b/war/src/main/java/pnews/OpenNLP.java index 07fbba5..e158a00 100644 --- a/war/src/main/java/pnews/OpenNLP.java +++ b/war/src/main/java/pnews/OpenNLP.java @@ -10,6 +10,7 @@ import opennlp.tools.namefind.TokenNameFinderModel; import opennlp.tools.tokenize.TokenizerME; import opennlp.tools.tokenize.TokenizerModel; import opennlp.tools.util.Span; +import pnews.servlet.Config; /** http://www.devglan.com/artificial-intelligence/opennlp-named-entity-recognition-example **/ public class OpenNLP { @@ -21,13 +22,13 @@ public class OpenNLP { private static TokenNameFinderModel timeModel; private static TokenizerModel tokenModel; - public static List classify(String str, List entities) throws IOException { - classify(str, getOrganizationModel(), entities); + public static List classify(String str, List entities, Config config) throws IOException { + classify(str, getOrganizationModel(), entities, config); - classify(str, getPersonModel(), entities); - classify(str, getLocationModel(), entities); + classify(str, getPersonModel(), entities, config); + classify(str, getLocationModel(), entities, config); - classify(str, getTimeModel(), entities); + classify(str, getTimeModel(), entities, config); return entities; } @@ -76,7 +77,7 @@ public class OpenNLP { return timeModel; } - private static List classify(String str, TokenNameFinderModel model, List entities) throws IOException { + private static List classify(String str, TokenNameFinderModel model, List entities, Config config) throws IOException { String entity; NameFinderME nameFinder = new NameFinderME(model); @@ -95,8 +96,8 @@ public class OpenNLP { entity += " " + tokens[i]; LOG.finest(entity + " " + s.getProb() + " " + s.toString()); - if (!entities.contains(entity)) - entities.add(entity); + if (!config.isBlacklistedEntity(entity) && !entities.contains(entity)) + entities.add(config.getEntityAlias(entity)); } return entities;