Re: [問題] 一個程式的比對問題

看板Perl作者 (成就你的大事)時間18年前 (2007/03/26 15:53), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
自己回^^ 除了下列的方式寫法請問還有更簡單的或其它的方法嗎?@@ 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
文章代碼(AID): #161tlcI6 (Perl)
討論串 (同標題文章)
文章代碼(AID): #161tlcI6 (Perl)