作者Yaowei (成就你的大事)
看板perl
标题[问题] 一个程式的比对问题
时间Mon Mar 26 02:01:04 2007
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.142.234