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 {
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;
}
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);
entity += " " + tokens[i];
LOG.finest(entity + " " + s.getProb() + " " + s.toString());
- if (!entities.contains(entity))
+ if (!config.isBlacklistedEntity(entity) && !entities.contains(entity))
entities.add(entity);
}