Hello Monks
I am taking a sentence from a tagged text and splitting it in words/tag (It/PRP). Them I am taking the sequence of two pairs of words, and tags (separated) to compare the tag with some pattern.
My problem is the way I code it (clueless), the last word of the sentence repeats (no word to combine), e.g.
This is my input: It/PRP really/RB does/VBZ seem/VB to/TO violate/VB a/DT lot/NN of/IN boundaries/NNS
this is my wrong output:
PRP/RB
It really
RB/VBZ
really does
...
IN/NNS
of boundaries
NNS/NNS
boundaries boundaries
1. Please,.. Can somebody help me to solve this?!!
2. Can somebody tell me a better way to evaluate for a pair of consecutives word, and for non-consecutive pair of words given the Ns words in between XY word pair???
Thanks
my @wordarray = split /\s+/, $sentence;
chomp foreach(@wordarray);
@wordarray = grep {length} @wordarray;
for(my $wordindex=0; $wordindex <= $#wordarray; $wordindex ++){
my $word1 = $wordarray[$wordindex];
while ($word1 =~ /(.*?)\/([A-Z]+)/g){
$valueword1 = $1;
$keyword1 = $2;
}
my $word2 = $wordarray[$wordindex+1];
while ($word2 =~ /(.*?)\/([A-Z]+)/g){
$valueword2 = $1;
$keyword2 = $2;
}
$patternKey = join("/",$keyword1, $keyword2);
$patternValue = join(" ",$valueword1, $valueword2);
print "key $patternKey \n";
print "value $patternValue \n";
my $matchingKey = grep($patternKey, @PatternArray);
...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.