Java Reference
In-Depth Information
based on the model found in the en-ner-person.bin file. An instance of
TokenNameFinderModel is created from this file as follows:
TokenNameFinderModel model = new TokenNameFinderModel(
new File("C:\\OpenNLP Models", "en-ner-person.bin"));
The NameFinderME class will perform the actual task of finding the name. An instance
of this class is created using the TokenNameFinderModel instance, as shown here:
NameFinderME finder = new NameFinderME(model);
Use a for-each statement to process each sentence as shown in the following code se-
quence. The tokenize method will split the sentence into tokens and the find method
returns an array of Span objects. These objects store the starting and ending indexes for
the names identified by the find method:
for (String sentence : sentences) {
String[] tokens = tokenizer.tokenize(sentence);
Span[] nameSpans = finder.find(tokens);
System.out.println(Arrays.toString(
Span.spansToStrings(nameSpans, tokens)));
}
When executed, it will generate the following output:
[Tim, Bob Haywood, Adam]
The primary focus of Chapter 4 , Finding People and Things , is name recognition.
Search WWH ::




Custom Search