blacklisted entities are now in the configuration file
[pnews.git] / war / src / main / java / pnews / OpenNLP.java
index 07fbba5..c383cee 100644 (file)
@@ -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<String> classify(String str, List<String> entities) throws IOException {
-                classify(str, getOrganizationModel(), entities);
+        public static List<String> classify(String str, List<String> 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<String> classify(String str, TokenNameFinderModel model, List<String> entities) throws IOException {
+        private static List<String> classify(String str, TokenNameFinderModel model, List<String> entities, Config config) throws IOException {
                 String entity;
                 
                 NameFinderME nameFinder = new NameFinderME(model);
@@ -95,7 +96,7 @@ public class OpenNLP {
                                         entity += " " + tokens[i];
                                 
                         LOG.finest(entity + " " + s.getProb() + " " + s.toString());
-                        if (!entities.contains(entity))
+                        if (!config.isBlacklistedEntity(entity) && !entities.contains(entity))
                                 entities.add(entity);
                 }