added openlp support
[pnews.git] / war / src / main / java / pnews / NER.java
index f8238c1..ac34c08 100644 (file)
@@ -14,19 +14,19 @@ public class NER {
         private static final String CLASS_NAME = NER.class.getName();
         private static final Logger LOG = Logger.getLogger(CLASS_NAME); 
         
-        public static String[] classify(String str) throws ClassCastException, ClassNotFoundException, IOException {
+        public static List<String> classify(String str, List<String> entities) throws ClassCastException, ClassNotFoundException, IOException {
                 CRFClassifier<CoreLabel> classifier;
                 List<List<CoreLabel>> out;
                 String cat, w;
-                List<String> entities;
                 final String FUNCTION_NAME = "classify";                
                 
                 LOG.entering(CLASS_NAME, FUNCTION_NAME, str);
+
+                OpenNLP.classify(str, entities);
                 
                 classifier = CRFClassifier.getDefaultClassifier();
                 out = classifier.classify(str);
                 
-                entities = new ArrayList<>();
                 for (List<CoreLabel> labels: out)
                         for (CoreLabel l: labels) {
                                 cat = l.getString(AnswerAnnotation.class);
@@ -35,12 +35,17 @@ public class NER {
                                         entities.add(w);
                         }
                 
+                entities.remove("CNET");
+                entities.remove("Read More");
+                entities.remove("New");
+                entities.remove("App");
+                
                 LOG.exiting(CLASS_NAME, FUNCTION_NAME, entities);
                 
-                return entities.toArray(new String[0]);
+                return entities;
         }
         
         public static void main(String[] args) throws Exception {
-                classify("I live in Washington.");
+                classify("I live in Washington.", new ArrayList<>());
         }
 }
\ No newline at end of file