我正在寻找一个解析器或脚本来删除文件中的停用词。
这是示例文件:
entities_0_confidence|entities_0_name|entities_0_entity|entities_1_confidence|relation_relation|
-1.1956528741743269|ellen brown|Ellen_Brown|-3.9166730593775214|WOULD ATTORNEY FROM|||||||||||||||||||||
-2.3889038197374015|rick santorum|Rick_Santorum||CRITICIZED|||||||||||||||||||||
-1.5485422793287602|thomas jefferson|Thomas_Jefferson|-1.7299349891097682||IS LETTER TO|||||||||||||||||||||
-1.229126527004769|lewis powell|Lewis_Powell_%28conspirator%29|-3.024385187632112|IS JUSTICE OF|||||||||||||||||||||
-2.2268355006701155|michael bloomberg|Michael_Bloomberg|-2.1242762129476493|WON MAYOR OF À|||||||||||||||||||||
这是停止单词列表:
IS, OF ,WITH ,WON,WOULD,X,©,® FOR BEST ACTRESS PRESENTING,À,È,ÉS,ŞI,АND,И
我只想删除每行中的单词而不是整行。我目前的脚本也是从其他单词中删除这些单词。
例如:
我的文件/数据集包含70,000个条目。
答案 0 :(得分:1)
代码将替换在fields变量中传递的列号之间的开头/结尾/中间的停用词。
fields="col_num=1“ #pass the column you want to remove stop words from
while word i;
do
str=“word=$i";
cat file | 'BEGIN{'$str';'$fields'} {gsub("^'$word'[ ]|[ ]'$word'$|^'$word'$",X,$col_num); gsub("[ ]'$word'[ ]", " ",$col_num); gsub(/^ /,X,$col_num); gsub(/ $/,X,$col_num); print}' > file".temp";
mv file".temp" file;
done < stop_words.txt
希望有所帮助!!