Re: [問題] 一個程式的比對問題
自己回^^
除了下列的方式寫法請問還有更簡單的或其它的方法嗎?@@
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章