use of opennlp.tools.namefind.NameFinderME in project textdb by TextDB.
the class NameFinderExample method main.
public static void main(String[] args) throws IOException {
String dataFile = "./src/main/resources/abstract_100.txt";
Scanner scan = new Scanner(new File(dataFile));
InputStream is = new FileInputStream("./src/main/java/edu/uci/ics/textdb/sandbox/OpenNLPexample/en-ner-location.bin");
TokenNameFinderModel model = new TokenNameFinderModel(is);
is.close();
NameFinderME nameFinder = new NameFinderME(model);
int counter = 0;
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
perfMon.start();
while (scan.hasNextLine()) {
String[] sentence = Tokenize(scan.nextLine());
Span[] spans = nameFinder.find(sentence);
perfMon.incrementCounter();
//Print out the tokens of the sentence
if (spans.length != 0) {
for (String s : sentence) {
System.out.print("[" + s + "] ");
}
System.out.println("/n");
}
//Print out the offset of each
for (Span s : spans) {
System.out.println(s.toString());
for (int i = s.getStart(); i < s.getEnd(); i++) {
System.out.println(sentence[i]);
counter++;
}
}
if (spans.length != 0)
System.out.println();
}
perfMon.stopAndPrintFinalResult();
System.out.println("Number of Results: " + counter);
scan.close();
}
use of opennlp.tools.namefind.NameFinderME in project tika by apache.
the class GeoParser method initialize.
/**
* Initializes this parser
* @param modelUrl the URL to NER model
*/
public void initialize(URL modelUrl) {
try {
if (this.modelUrl != null && this.modelUrl.toURI().equals(modelUrl.toURI())) {
return;
}
} catch (URISyntaxException e1) {
throw new RuntimeException(e1.getMessage());
}
this.modelUrl = modelUrl;
gazetteerClient = new GeoGazetteerClient(config);
// Check if the NER model is available, and if the
// lucene-geo-gazetteer is available
this.available = modelUrl != null && gazetteerClient.checkAvail();
if (this.available) {
try {
TokenNameFinderModel model = new TokenNameFinderModel(modelUrl);
this.nameFinder = new NameFinderME(model);
} catch (Exception e) {
LOG.warn("Named Entity Extractor setup failed: {}", e.getMessage(), e);
this.available = false;
}
}
initialized = true;
}
Aggregations