Sietse
Sietse

Reputation: 250

OpenNLP find() method

At the moment im trying to find names inside a document. Im using the following method to find the names:

find(String[] tokens)

I also found this method below:

find(String[] tokens,String[][] additionalContext)

what can I do with this method and how do I use it ?

Upvotes: 1

Views: 98

Answers (1)

marcelovca90
marcelovca90

Reputation: 2804

According to opennlp.tools.namefind.NameFinderME apidocs:

public Span[] find(String[] tokens, String[][] additionalContext)

Generates name tags for the given sequence, typically a sentence, returning token spans for any identified names.

Parameters:

  • tokens - an array of the tokens or words of the sequence, typically a sentence.
  • additionalContext - features which are based on context outside of the sentence but which should also be used.

Returns: an array of spans for each of the names identified.

That being said, consider your tokens are:

String[] tokens = { "lorem", "ipsum", "dolor", "sit", "amet", "adipiscing", "elit" };

But you also want to take into account the following features, "which are based on context outside of the sentence but which should also be used":

String[][] additionalContext = { 
    { "nullam", "fermentum", "justo", "non", "leo", "rhoncus", "blandit" },
    { "phasellus", "at", "diam", "mattis", "arcu", "congue", "consequat" },
    { "integer", "at", "tincidunt", "turpis", "eget", "pulvinar", "nisl" } };

This way you can call find(tokens, additionalContext).

Note that, according to the code on GitHub, find(String[] tokens) is actually find(tokens, EMPTY) (and String[][] EMPTY = new String[0][0]).

Upvotes: 2

Related Questions