, .
private static ArrayList<Tree> findPro(Tree t) {
ArrayList<Tree> pronouns = new ArrayList<Tree>();
if (t.label().value().equals("PRP"))
pronouns.add(t);
else
for (Tree child : t.children())
pronouns.addAll(findPro(child));
return pronouns;
}
public static void main(String[] args) {
LexicalizedParser parser = LexicalizedParser.loadModel();
Tree x = parser.apply("The dog walks and he barks .");
System.out.println(x);
ArrayList<Tree> pronouns = findPro(x);
System.out.println("All Pronouns: " + pronouns);
}
:
(ROOT (S (S (NP (DT The) (NN dog)) (VP (VBZ walks))) (CC and) (S (NP (PRP he)) (VP (VBZ barks))) (. .)))
All Pronouns: [(PRP he)]