Skip to content

Instantly share code, notes, and snippets.

@milindjagre

milindjagre/getPeople.txt

Last active Dec 17, 2018
Embed
What would you like to do?
This method returns the people names from the input lyrics.
public static List<String> getPeople(String sentence) {
TokenNameFinderModel model = null;
try {
model = new TokenNameFinderModel(new File("C:\\en-ner-person.bin"));
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
NameFinderME finder = new NameFinderME(model);
Tokenizer tokenizer = SimpleTokenizer.INSTANCE;
String[] tokens = tokenizer.tokenize(sentence);
Span[] nameSpans = finder.find(tokens);
List<String> peopleNames = new ArrayList<String>();
String[] spanns = Span.spansToStrings(nameSpans, tokens);
for (int i = 0; i < spanns.length; i++) {
peopleNames.add(spanns[i]);
}
finder.clearAdaptiveData();
return peopleNames;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.