使用 stanford 我想在进行 pos 标记后获取句子中的所有形容词和名词,并将它们存储在单独的字符串中

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

使用 POS 标记器,我已经标记了句子,现在我想将名词和形容词存储在单独的字符串中。

如何操作?

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

只需先用 space 拆分字符串,然后再用“/”拆分字符串

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));
    }
}