Hi,
I have a bunch of sentences in a file and I want to match the Nouns Phrases, which are between these delimiters <NP#>...</NP>
and substitute (delete) -in the noun phrase-, all the tags, to add only one tag "/NP" on the last word of the phrase.
This for each sentence...
<S> Who/WP is/VBZ <NP1> the/DT author/NN </NP> of/IN <NP2> the/DT book
+/NN </NP> ,/,/*comma* "/"/*\
quote* <NP3> The/DT Iron/NNP Lady/NNP </NP> :/: <NP4> A/DT Biography/N
+NP of/IN \Margaret/NNP That\
cher/NNP </NP> "/"/*quote* ?/./*end-of-sentence*</S>
Result:
<S> Who/WP is/VBZ the author/NP of/IN the book/NP ,/, The Iron Lady
+/NP :/: A Biography of Margaret That\
cher/NP "/"...
So far, I am getting nothing with the match, no even with the replacement
if ($sentence =~ / (<NP\d*>) ([a-zA-Z0-9.-_]+)\/([A-Z]+) ([^ ]+) (<\/
+NP>) /) {
$text="NounPhrase"; # to test the match to replace
$result =~ s/$question/$text/;
print "$result";};
Thanks in advance for your help
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.