简单疑问词提取,依据疑问词词根提取
# -*- coding: utf-8 -*- import sys # 用法示例:python3 filter_kw.py 关键词.txt 结果.txt # 获取命令行参数,分别获取关键词文件和结果文件名 kwfile, retfile = sys.argv[-2:] filters = {'难道','岂','居然','竟然','究竟','简直','难怪','反倒','何尝','何必','吗','呢','吧','啊','怎','么','如何','什么','谁','何','哪','几时','多少','那','多久','嘛',} ret = open(retfile, mode='w', encoding='utf-8') with open(kwfile, encoding='utf-8') as f: for line in f: for w in filters: if w in line: ret.write(line) break ret.flush() ret.close()