in reply to Re: parsing a sentence?
in thread parsing a sentence?

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.

Replies are listed 'Best First'.
Re: Re: Re: parsing a sentence?
by Roger (Parson) on Mar 01, 2004 at 23:48 UTC
    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