Hello,

you can parse a parse tree string, like the one below, with
Parse.parseString which returns you a Parse object tree.

Is that what you are looking for?

HTH,
Jörn

On 02/07/2014 10:36 PM, Carlos Scheidecker wrote:
Tim & Boris,

Thanks for the reply. Couldn't find the reply. Thought there was something
wrong.

What I want to do is to get a Sentence String and convert it to a Tree
object.

So, if you have this:

Statement : On Tuesday, John Smith bought a Honda Accord

(TOP (SBAR (IN On) (S (NP (NNP Tuesday,) (NNP John) (NNP Smith)) (VP (VBD
bought) (NP (DT a) (NNP Honda) (NNP Accord))))))

Then, I would like that the following resulting string of the tree
representation "(TOP (SBAR (IN On) (S (NP (NNP Tuesday,) (NNP John) (NNP
Smith)) (VP (VBD bought) (NP (DT a) (NNP Honda) (NNP Accord))))))" and
convert it to a Tree object that I can traverse.

cheers,

Carlos.






On Wed, Feb 5, 2014 at 1:37 PM, Tim Miller <
[email protected]> wrote:

Carlos,
I am not sure I totally understand your question, but I think you're
asking how to get a tree structure from a Parse object? In which case the
answer is that the Parse object is a tree structure (with a bunch of other
stuff). You can use getChildCount(), getChildren(), getType(), etc. to
navigate the tree. If you want to see an example look at this class from
cTAKES:

https://svn.apache.org/repos/asf/ctakes/trunk/ctakes-
constituency-parser/src/main/java/org/apache/ctakes/
constituency/parser/util/TreeUtils.java

where in the recursivelyCreateStructure() method I translate from the
Parse data structure into a tree in the ctakes typesystem.

Tim


On 02/05/2014 03:28 PM, Carlos Scheidecker wrote:

Hello all,

If you have something like this:

Statement : On Tuesday, John Smith bought a Honda Accord

(TOP (SBAR (IN On) (S (NP (NNP Tuesday,) (NNP John) (NNP Smith)) (VP (VBD
bought) (NP (DT a) (NNP Honda) (NNP Accord))))))

I have generated that from the Parse class Show() method as bellow:

   /**
     * Displays this parse using Penn Treebank-style formatting.
     */
    public void show() {
      StringBuffer sb = new StringBuffer(text.length()*4);
      show(sb);
      System.out.println(sb);
    }


My question is: How can I translate (TOP (SBAR (IN On) (S (NP (NNP
Tuesday,) (NNP John) (NNP Smith)) (VP (VBD bought) (NP (DT a) (NNP Honda)
(NNP Accord)))))) into a tree object?

I think I would parse that with ( -> new node, (-> new child, ) -> end
node.

I was thinking on doing something like this, but instead of returning a
string buffer I would return a tree object:

/**
     * Appends the specified string buffer with a string representation of
this parse.
     *
     * @param sb A string buffer into which the parse string can be
appended.
     */
    public void show(StringBuffer sb) {
      int start;
      start = span.getStart();
      if (!type.equals(AbstractBottomUpParser.TOK_NODE)) {
        sb.append("(");
        sb.append(type).append(" ");
        //System.out.print(label+" ");
        //System.out.print(head+" ");
        //System.out.print(df.format(prob)+" ");
      }
      for (Iterator<Parse> i = parts.iterator(); i.hasNext();) {
        Parse c = i.next();
        Span s = c.span;
        if (start < s.getStart()) {
          //System.out.println("pre "+start+" "+s.getStart());
          sb.append(encodeToken(text.substring(start, s.getStart())));
        }
        c.show(sb);
        start = s.getEnd();
      }
      if (start < span.getEnd()) {
        sb.append(encodeToken(text.substring(start, span.getEnd())));
      }
      if (!type.equals(AbstractBottomUpParser.TOK_NODE)) {
        sb.append(")");
      }
    }

But is there some example that someone might have already done and you
could refer to me?

Thanks,

Carlos.



Reply via email to