The following example shows how to use Standford POSTagger. What a POS Tagger does is tagging each word with its type such as verb, noun, etc. For example, if you want to find all verbs in a sentence, you can use Stanford POS Tagger.
Here are steps for using Stanford POSTagger in your Java project.
1. Download basic English Stanford Tagger version 3.1.3 [43 MB]
URL: http://nlp.stanford.edu/software/tagger.shtml
2. Find a folder called “models”, copy the model and its corresponding “.props†file to a directory you are comfortable with.
3. Create a Java project in your eclipse and add stanford-postagger.jar to your project build path
4. Here is the code to tag a sentence “I like watching movies”.
String a = "I like watching movies"; MaxentTagger tagger = new MaxentTagger("lib/tagger/taggers/english-left3words-distsim.tagger"); String tagged = tagger.tagString(a); System.out.println(tagged); |
Output:
I_PRP like_VBP watching_VBG movies_NNS
Thank you so much 🙂