Tag none using stanford nlp - Java Natural Language Processing

Java examples for Natural Language Processing:stanford nlp

Description

Tag none using stanford nlp

Demo Code



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

import java.io.IOException;

public class NounTagger {
    public static void main(String[] args) throws IOException,
            ClassNotFoundException {

        // Initialize the tagger
        MaxentTagger tagger = new MaxentTagger("english-bidirectional-distsim.tagger");

        // The sample string
        String sample = "yes this is it.\n"
                + ", The Post and Courier---RT @brindge: this is a sentence and this is a test\n"
                + "]'";

        // The tagged string
        String tagged = tagger.tagString(sample);

        // Output the result
        System.out.println(tagged);

        String findStr = "_NN";
        int lastIndex = 0;
        int count = 0;

        while (lastIndex != -1) {

            lastIndex = tagged.indexOf(findStr, lastIndex);

            if (lastIndex != -1) {
                count++;/*from  w w w. j a va 2 s. c  om*/
                lastIndex += findStr.length();
            }
        }
        System.out.println(count);
        System.out.println("Done");

    }

}

Related Tutorials