由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 一个Perl 匹配问题
相关主题
Open Position - Research Scientist at McAfee Inc. (转载)perl help---many thanks
perl monk (ascii art)What language I should use?
Usage of Grep???help!!!how to verify X509 certificate in perl?
[转载] 在CGI程序中有何好方法返回HTMLPlease recommend a Perl editor for windows
perl array|hash questionhow to print 2 exponential digits in windows by using Perl
perl:里有象 c assert 的东西吗?如何控制输出的颜色?
请问perl程序能不能加运行参数?谁能说说Perl, Python, Tcl各自的优缺点?主要应用场合?
perl question请教一个变态的regular expression 替换
相关话题的讨论汇总
话题: nn话题: jj话题: np话题: nns话题: threat
进入Programming版参与讨论
1 (共1页)
L******r
发帖数: 199
1
对下列文本逐行处理,
主要目标是把 括号里包含有NN/JJ/NNS/VP的短语提取出来,存到一个数组里。
比如这行"(NP (JJ extreme) (NN fire) (NN threat)))"
要求处理后的数组为
@array==("(JJ extreme)","(NN fire)","(NN threat)")
我用
my $content_ALL = '.*(\(NNPS\s.+\)|\(NNP\s.+\)|\(NNS\s.+\)|\(NN\s.+\)|\(JJR\
s.+\)|\(JJS\s.+\)|\(JJ\s.+\)|\(VBZ\s.+\)|\(VBD\s.+\)|\(VBG\s.+\)|\(VBN\s.+\)
|\(VBP\s.+\)|\(VB\s.+\)|\(RBS\s.+\)|\(RBR\s.+\)|\(RB\s.+\))';
my @myp = $line =~/$content_ALL/g;
可是根本得不到要的效果。
谁给个方子?谢谢
(ROOT
(S
(NP
(NP (NNS Scores))
(PP (IN of)
w******p
发帖数: 166
2
this should work:
test.pl:
my $input = '(NP (JJ extreme) (NN fire) (NN threat)))';
my @result = $input =~ /(\(JJ[^)]*\))|(\(NN[^)]*\))/g;
map { print "$_\n" if $_ } @result;
$ perl test.pl
(JJ extreme)
(NN fire)
(NN threat)
L******r
发帖数: 199
3
thanks.

【在 w******p 的大作中提到】
: this should work:
: test.pl:
: my $input = '(NP (JJ extreme) (NN fire) (NN threat)))';
: my @result = $input =~ /(\(JJ[^)]*\))|(\(NN[^)]*\))/g;
: map { print "$_\n" if $_ } @result;
: $ perl test.pl
: (JJ extreme)
: (NN fire)
: (NN threat)

1 (共1页)
进入Programming版参与讨论
相关主题
请教一个变态的regular expression 替换perl array|hash question
perl beginner question "1;" ?perl:里有象 c assert 的东西吗?
perl: how to get the filename from the full path name请问perl程序能不能加运行参数?
A question about Perl/tk binding (转载)perl question
Open Position - Research Scientist at McAfee Inc. (转载)perl help---many thanks
perl monk (ascii art)What language I should use?
Usage of Grep???help!!!how to verify X509 certificate in perl?
[转载] 在CGI程序中有何好方法返回HTMLPlease recommend a Perl editor for windows
相关话题的讨论汇总
话题: nn话题: jj话题: np话题: nns话题: threat