shoaib shaikh
shoaib shaikh

Reputation: 23

Using stanford I want to get all the adjectives and nouns in my sentence after doing the pos tagging and store them in separate strings

Using POS tagger I have tagged the sentence now I want to store the nouns and adjectives in separate strings.

How to do so?

Example: The/DT large/JJ photo/NN album/NN has/VBZ extra/JJ charges/NNS on/IN delivery/NN

Upvotes: 0

Views: 244

Answers (1)

Mayur Kulkarni
Mayur Kulkarni

Reputation: 1316

Just split the Strings first by space and then by "/"

public class Demo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        String a = "I like watching movies";
        MaxentTagger tagger =  new MaxentTagger("D:\\left3words-wsj-0-18.tagger");
        String tagged = tagger.tagString(a);
        System.out.println(tagged);
        String[] splitStrings = tagged.split(" ");
        String[] tagsOnly = new String[splitStrings.length];
        for (int i = 0; i < tagsOnly.length; i++) {
            tagsOnly[i] = splitStrings[i].split("/")[1];
        }
        System.out.println(Arrays.toString(tagsOnly));
    }
}

Upvotes: 1

Related Questions