Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks I'm looking for some ideas or tutorials or documents about working with trees. I search the web a lot but not convincing what module to used for my purplish. since usual here does not make me disappointed i came to ask for your help. my main purpose is that I want to change convert a syntactic parsed text to a tree (Possibly xml but not necessarily) and then implement the Tree Edit Distance on it. The parser output could be like this:
(ROOT (S (NP (DT this)) (VP (VBZ is) (ADVP (RB just)) (NP (DT a) (NN test))) (. .)))
while i want to convert it to tree structure and then mainly use post order traversal for implementing TED algorithms. so i prefer something more convinient for labeling the nodes and finding the key nodes of the tree and/or comparing them and what so ever. All your suggestions is really appreciated. Best Regards and thanks in advance ...

Replies are listed 'Best First'.
Re: PERL and TREE
by Fletch (Bishop) on Feb 11, 2009 at 13:15 UTC

    If Data::SExpression doesn't do what you need you at least now have a better search term ("s-expression") with which to google.

    Update: Heh, just over a year since I last mentioned that module . . .

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: PERL and TREE
by dHarry (Abbot) on Feb 11, 2009 at 12:32 UTC

    How about CPAN? There are also lots of parsers on CPAN. Probably a lot simpler then drumming it up yourself. Or "Super Search" the Monastery. If you want to know more about trees & Perl take a look at Mastering Algorithms with Perl.

      Sure I have gone to CPAN but looking for a convenient module for dealing with parsing nested parenthesis to structured tree ... as I explained ... any idea?
Re: PERL and TREE
by ELISHEVA (Prior) on Feb 11, 2009 at 14:17 UTC
    I'm not clear - are you building the tree from pre-parsed text (i.e. word's part of speech is already assigned?) or are you trying to parse the text and put it in a tree structure?

    If you are primarily concerned with building and navigating a tree structure, you might want to check out Tree::MultiNode and search CPAN for the keyword Tree if that does not suit.

    If actually parsing and assigning words to parts of speech is your goal, you have your work cut out for you, but there are also some natural language processing modules on CPAN as well. Searching for NLP (natural language processing), I found modules that interface with Alvis and Ogmios. You might also want to check out Lingua::YaTeA. However, this only handles noun phrases and outputs in Head-Modifier format

    Also you might want to say a bit more about what you are trying to do. For example, word distance is often part of search algorithms. If that is your goal, I imagine there are a few search experts who are lurking and might be helpful.

    Best, beth

      Thanks for your reply, indeed I'm building the tree from pre-parsed text, indeed i parse the text and then wanna build a tree on based. in other words, my problem is to convert the parsed text with nested parenthesis to tree structure.