作者Yaowei (成就你的大事)
看板perl
标题Re: [问题] 一个程式的比对问题
时间Mon Mar 26 15:53:06 2007
自己回^^
除了下列的方式写法请问还有更简单的或其它的方法吗?@@
open(LINE,$file) or die "$!";
while(<LINE>){
chomp;
while(/\s?(\w+)\/(JJ|RB|DET|CD)\s?/g){
s/$&/ /g unless($1=~ /($ActionPattern)/);
}
print "最终结果:$_\n";
print "----------End----------\n";
}
close(LINE);
※ 引述《Yaowei (成就你的大事)》之铭言:
: Q.若我想将档案A中的文字中出现的 /JJ /DET /CD /RB 将含有这些字的词拿掉?
: 但若出现某些字则不进行取代的动作(在此假设不只三个而)
: ex: binding interact bound
: 某一个档案A内有下列的资料:
: binds/NNS to/TO kissing/JJ
: -/PPS rich/JJ region/NN presumably/RB derepresses/NNS
: from/IN the/DET PTN/NNP interaction/NN site/NN
: the/DET two/CD PTN/NNP -/PPS binding/JJ sites/NNS
: ------------------------------------------------------------------
: 希望处理後:
: binds/NNS to/TO
: -/PPS region/NN presumably/RB derepresses/NNS
: from/IN PTN/NNP interaction/NN site/NN
: PTN/NNP -/PPS binding/JJ sites/NNS <--此处没删掉binding/JJ
: 是因为出现了binding interact bound
: --------------------------------------
: 目前的想法是先进行档案A的读入後进行比对动作
: open(LINE,$file) or die "No file";
: $ActionPattern="binding|interact|bound";
: while(<LINE>){
: if($_=~ /(w+)(\/JJ|\/RB|\/DET|\/CD)/g){ #先进行句中有些其中的字词比对
: #如果$1则写入档案,但要如何在这边加入s///g;取代的动作呢?
: print NEWLINE "$_" unless($1=~ /\b($ActionPattern)\b/g) ;
: }
: else{
: print NEWLINE "$_";
: }
: }
: 或者是大家还有其它的方法或意见,可供参考的吗^^?
: 不好意思又来让大家动动脑筋了^^
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.96.202