javanlpstanford-nlp

How can I find whether a word is a noun or a verb using the Stanford parser?


I need to find whether a word is a verb, a noun, or it is both.

For example, the word is "search". It can be both a noun and a verb, but the Stanford parser gives the NN tag to it.

Is there a way that the Stanford parser will give that "search" is both a noun and a verb?

My current code is as follows:

public static String Lemmatize(String word) {
    WordTag w = new WordTag(word);
    w.setTag(POSTagWord(word));
    Morphology m = new Morphology();
    WordLemmaTag wT = m.lemmatize(w);

    return wT.lemma();
}

Solution

  • The Stanford Parser guesses the part-of-speech tag of a word based on context statistics. You should really pass in a complete sentence to determine whether, in that sentence, "search" is a noun or a verb.

    You don't need a full parser just to get part-of-speech tags. The Stanford POS Tagger is enough; it also includes the Morphology class, but it too takes context into account.

    If you want all part-of-speech tags that an English word can take on, without giving context, then WordNet is probably a better choice. It has several Java interfaces, including JWNL and JWI.