public void NameFinder() { using var modelIn = new java.io.FileInputStream(GetModel("en-ner-person.bin")); var model = new opennlp.tools.namefind.TokenNameFinderModel(modelIn); var nameFinder = new opennlp.tools.namefind.NameFinderME(model); var sentence = new[] { "Pierre", "Vinken", "is", "61", "years", "old", "." }; var nameSpans = nameFinder.find(sentence); System.Console.WriteLine(string.Join(";", nameSpans.Select(x => x.toString()))); Assert.AreEqual(1, nameSpans.Length); }
public void FindNer(string context) { if (locationNameFinder == null) { Initial(); } var tokens = regex.Split(context); // Find location names var locations = new List <string>(); opennlp.tools.util.Span[] locationSpan = locationNameFinder.find(tokens); //important: clear adaptive data in the feature generators or the detection rate will decrease over time. locationNameFinder.clearAdaptiveData(); locations.AddRange(opennlp.tools.util.Span.spansToStrings(locationSpan, tokens).AsEnumerable()); // Find person names var persons = new List <string>(); opennlp.tools.util.Span[] personSpan = personNameFinder.find(tokens); //important: clear adaptive data in the feature generators or the detection rate will decrease over time. personNameFinder.clearAdaptiveData(); persons.AddRange(opennlp.tools.util.Span.spansToStrings(personSpan, tokens).AsEnumerable()); // Find organization names var organizations = new List <string>(); opennlp.tools.util.Span[] organizationSpan = organizationNameFinder.find(tokens); //important: clear adaptive data in the feature generators or the detection rate will decrease over time. organizationNameFinder.clearAdaptiveData(); organizations.AddRange(opennlp.tools.util.Span.spansToStrings(organizationSpan, tokens).AsEnumerable()); entities = new List <pml.type.Pair <string, string> >(); foreach (var location in locations) { entities.Add(new pml.type.Pair <string, string>(location, "LOCATION")); } foreach (var person in persons) { entities.Add(new pml.type.Pair <string, string>(person, "PERSON")); } foreach (var organization in organizations) { entities.Add(new pml.type.Pair <string, string>(organization, "ORGANIZATION")); } }