Akash
Akash

Reputation: 95

How to find a name Entity in a text in java

Following is the code written using opennlp in java to identify name entities

try {
        System.out.println("Input : Pierre Vinken is 61 years old");
        InputStream modelIn = new FileInputStream("en-ner-person.bin");
        TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
        NameFinderME nameFinder = new NameFinderME(model);
        String[] sentence = new String[]{
                "Pierre",
                "Vinken",
                "is",
                "61",
                "years",
                "old",
                "."
                };

            Span nameSpans[] = nameFinder.find(sentence);
            for(Span s: nameSpans)
                System.out.println("Name Entity : "+s.toString());
    }
    catch (IOException e) {
      e.printStackTrace();
    }

This gives output :

Input : Pierre Vinken is 61 years old

Name Entity : [0..2) person

But for any other entities like GPE (geo-graphical and political entity),its not identifying

Eg

Input : Taj Mahal is in India

It is neither identifying Taj Mahal nor India. What can be done ?

Upvotes: 0

Views: 423

Answers (1)

aab
aab

Reputation: 11474

As suggested in the filename, en-ner-person.bin only identifies persons. There are other available OpenNLP NER models for other kinds of entities.

Upvotes: 2

Related Questions