Stanford POS tagger Tutorial | Extracting Adjective using Stanford POS tagger

Inroduction
Inroduction

print the adjectives in one more sentence. This shows how to get at words and tags in a tagged sentence.

Filtering Adjectives
Filtering Adjectives

package com.interviewBubble.pos;

import java.io.OutputStreamWriter;

import java.io.PrintWriter;

import java.util.List;

import edu.stanford.nlp.ling.SentenceUtils;

import edu.stanford.nlp.ling.TaggedWord;

import edu.stanford.nlp.ling.HasWord;

import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class TaggerDemo2  {

private TaggerDemo2() {}

public static void main(String[] args) throws Exception {

MaxentTagger tagger = new MaxentTagger(“/Users/admin/LearningSourceControl/CoreNLP/taggers/models/english-left3words-distsim.tagger”);

PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, “utf-8”));

// print the adjectives in one more sentence. This shows how to get at words and tags in a tagged sentence.

List<HasWord> sent = SentenceUtils.toWordList(“The”, “slimy”, “slug”, “crawled”, “over”, “the”, “long”, “,”, “green”, “grass”, “.”);

List<TaggedWord> taggedSent = tagger.tagSentence(sent);

for (TaggedWord tw : taggedSent) {

if (tw.tag().startsWith(“JJ”)) {

pw.println(tw.word());

}

}

pw.close();

}

}