[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Grammatica-users] basic question
From: |
Per Cederberg |
Subject: |
RE: [Grammatica-users] basic question |
Date: |
Sun, 20 Feb 2005 14:24:45 +0100 |
On sat, 2005-02-19 at 11:23 -0500, Leo Ferres wrote:
> How can I access each of the individual nodes of the generated tree? I'd
> like to do something like
>
>
> 0 Sentence
> 1 simpleSentence
> 2 PREDICATE "BLUE"
> 3 (
> 4 WORD "boy"
> 5 )
>
> node.get(2) to get the "PREDICATE "BLUE"" string.
There is no easy way to do exactly that. Each node in the parse
tree only allows retrieval of its direct children. But if this
is really what you want, I guess you could always create a list
with the nodes (in depth-first order):
private void buildList(Node node, List list) {
if (node != null) {
list.add(node);
for (int i = 0; i < node.getChildCount(); i++) {
buildList(node.getChildAt(i), list);
}
}
}
You'd then use it like this:
node = parser.parse();
list = new ArrayList();
buildList(node, list);
descendant = (Node) list.get(2);
Cheers,
/Per