in reply to parsing a sentence?

my $str = "It/PRP really/RB does/VBZ seem/VB to/TO violate/VB a/DT lot +/NN of/IN boundaries/NNS"; my @pairs = map { [ split /\// ] } split /\s+/, $str; for (0..$#pairs-1) { print $pairs[$_][1], "/", $pairs[$_+1][1], "\n"; print $pairs[$_][0], " ", $pairs[$_+1][0], "\n"; }

Replies are listed 'Best First'.
Re: Re: parsing a sentence?
by Anonymous Monk on Mar 01, 2004 at 23:39 UTC
    Thank you Roger

    I tried and it works, well it is not repeating the last word pair, but I need to keep the format I have, I cannot take anything that is before or after the / , it has to be words, number.. now it is taking puntuaction marks :(. Let me adapt it.
      You mean something like this?
      my $str = "It/PRP really/RB does/VBZ seem/VB to/TO violate/VB a/DT lot +/NN of/IN boundaries!/NNS"; my @pairs = map { [ m!(\w+).*?/(\w+)! ] } split /\s+/, $str; for (0..$#pairs-1) { print $pairs[$_][0], " ", $pairs[$_+1][0], "\n"; }

      To handle non-consecutive pairs of words:
      $nth = 2; # every 2nd words for (0..$#pairs-$nth) { print $pairs[$_][0], " ", $pairs[$_+$nth][0], "\n"; }

        Yes, I meant that,..now that part is working!
        Thank you Robert
        Great, thanks for your help!!
        Let me try