[問題] 一個程式的比對問題
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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章