Skip to content

Instantly share code, notes, and snippets.

@milindjagre
Last active December 17, 2018 21:40
Show Gist options
  • Select an option

  • Save milindjagre/94117f86f39a37cb2f03973cd73f14c0 to your computer and use it in GitHub Desktop.

Select an option

Save milindjagre/94117f86f39a37cb2f03973cd73f14c0 to your computer and use it in GitHub Desktop.
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