Last active
December 17, 2018 21:40
-
-
Save milindjagre/94117f86f39a37cb2f03973cd73f14c0 to your computer and use it in GitHub Desktop.
This method returns the people names from the input lyrics.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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