I've been playing with the lingua link parser. It looks like the author for the perl mod has included overloading as suggested by this site http://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0010.html I pulled some code from here http://improvist.org/Projects/Technology/Papers/LinkParser/tpj0503-0010a.html and I'm having trouble getting it to work. My OO knowledge is iffy.. Feel like more of a procedural guy. What am I doing wrong? I can't seem to get any output from $linkage.
#!/usr/bin/perl -w # For this to work, the overload parameter in ::Linkage and # ::Sublinkage must point to "new_as_string". use Lingua::LinkParser; use strict; my $parser = new Lingua::LinkParser; $parser->opts('disjunct_cost' => 2); $parser->opts('linkage_limit' => 101); while (1) { print "Enter a sentence> "; my $input = <STDIN>; my $sentence = $parser->create_sentence($input); my $linkage = $sentence->linkage(1); # computing the union and then using the last sublinkage # permits conjunctions. $linkage->compute_union; my $sublinkage = $linkage->sublinkage($linkage->num_sublinkages); my $what_rocks = 'S[s|p]' . # match the link label '(?:[\w\*]{1,2})*'.# match any optional subscrip +ts '\:(\d+)\:' . # match number of the word '(\w+(?:\.\w)*)'; # match and save the word its +elf my $other_stuff = '[^\)]+'; # match other stuff within pa +renthesis my $rocks = '\"(rock[s|ed]*).v\"'; # match and store verb my $no_objects = '[^(?:O.{1,2}\:' . # don't match objects '\d+\:\w+(?:\.\w)*)]*\)'; my $pattern = "$what_rocks $other_stuff $rocks $no_objects"; if ( $sublinkage =~ /$pattern/mx ) { my $wordobj = $sublinkage->word($1); my $wordtxt = $2; my $verb = $3; my @wordlist = (); # we could put all of the below functionality in the regex abo +ve. foreach my $link ($wordobj->links) { # proper nouns, noun modifiers, pre-noun adjectives if ($link->linklabel =~ /^G|AN|A/) { $wordlist[$link->linkposition] = $link->linkword; } # possessive pronouns, via a noun determiner if ($link->linklabel =~ /^D[s|m]/) { my $wword = $sublinkage->word($link->linkposition); foreach my $llink ($wword->links) { if ($llink->linklabel =~ /^YS/) { $wordlist[$llink->linkposition] = $llink->link +word; $wordlist[$link->linkposition] = $link->linkw +ord; my $wwword = $sublinkage->word($llink->linkpos +ition); foreach my $lllink ($wwword->links) { if ($lllink->linklabel =~ /^G|AN/) { $wordlist[$lllink->linkposition] = $ll +link->linkword; } } } } } } print " -> ", join (" ", @wordlist, $wordtxt); } }

In reply to LinkParser new_as_string by rael438

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.