Wor*_*ery 7 python string nlp linguistics nltk
我想用NLTK来识别日语中的特定汉字字符和汉语中的汉字字符之间的搭配.与单词搭配一样,一些汉字序列比其他序列更有可能.例如:中文和日文中的许多单词是双字符双字母 - 字符A和字符B(例如日本=日本,日语为ni-hon,中文为ri-ben).给定字符A(日),本身更有可能出现为字符B.所以字符日和本是搭配.
我想使用NLTK找出这些问题的答案:
(1)给定字符A,哪个字符最有可能是字符B?
(2)给定字符B,哪些字符最有可能是字符A?
(3)字符A和字符B在一个句子中出现的可能性有多大,即使它们不是并排显示的?
相关:如果我有一个汉字/汉字的频率列表,我可以强制NLTK搭配模块只查看我列表中的汉字/汉字之间的关系,忽略所有其他字符吗?这将过滤掉在可能的并置集合中考虑单个罗马字母(a,b,c等)或标点符号的结果.
不幸的是,nltk.collocations和NLTK Book的文档,操作方法和源代码只讨论英语NLP,可以理解的是没有解决单字符搭配的问题.nltk.collocations模块中的函数似乎内置了一个单词标记器,所以我认为它们默认忽略单个字符.
更新:以下代码似乎在正确的轨道上:
def main():
scorer = nltk.collocations.BigramAssocMeasures.likelihood_ratio
with open('sample_jp_text.txt', mode='r') as infile:
sample_text = infile.read()
bigram_measures = nltk.collocations.BigramAssocMeasures()
finder = BigramCollocationFinder.from_words(sample_text,window_size = 13)
#corpus = make_corpus()
print('\t', [' '.join(tup) for tup in finder.nbest(scorer, 15)])
Run Code Online (Sandbox Code Playgroud)
结果:
['? ?', '? ?', '? ?', '0 0', '? ?', '? ?', '? ?', '? 0', '2 0', '? ?', '0 ?', '? ?', '0 ?', '? ?', '? \n']
Run Code Online (Sandbox Code Playgroud)
因此,无论出于何种原因,BigramCollocationFinder似乎将我的日文示例文本中的单个字符视为bigram搭配的候选者.我仍然不确定如何从这个结果中采取下一步来回答上面提出的问题.
很可能您不关心任务的 ngram 部分,而是关心如何清理数据,以便从混乱的其他字符中获取汉字单词。
\n\n这是一个 hack,但它需要库charguana:
# -*- coding: utf-8 -*-\n\nfrom string import punctuation\n# Older version:\n#from charguana.cjk import get_charset\nfrom charguana import get_charset\n\n\nhiragana = list(get_charset(\'hiragana\'))\nkatakana = list(get_charset(\'katakana\'))\ncjk_punctuations = list(get_charset(\'punctuation\'))\nromanji = list(get_charset(\'romanji\'))\n\nmccarl_stoplist = [\'"\', \'#\', \'$\', \'%\', \'&\', "\'", \'(\', \')\', \'*\', \'+\', \'-\', \'.\', \'/\', \'0\', \'1\', \'2\', \'3\', \'4\', \'5\', \'6\', \'7\', \'8\', \'9\', \':\', \';\', \'<\', \'=\', \'>\', \'?\', \'@\', \'[\', \']\', \'^\', \'_\', \'`\', \'a\', \'A\', \'b\', \'B\', \'c\', \'C\', \'d\', \'D\', \'e\', \'E\', \'F\', \'f\', \'g\', \'G\', \'h\', \'H\', \'i\', \'I\', \'j\', \'J\', \'k\', \'K\', \'l\', \'L\', \'m\', \'M\', \'n\', \'N\', \'o\', \'O\', \'p\', \'P\', \'q\', \'Q\', \'r\', \'R\', \'s\', \'S\', \'t\', \'T\', \'u\', \'U\', \'v\', \'V\', \'w\', \'W\', \'x\', \'X\', \'y\', \'Y\', \'z\', \'Z\', \'{\', \'|\', \'}\', \'~\', \' \', \'\xc2\xa3\', \'\xc2\xa7\', \'\xc2\xae\', \'\xc2\xb0\', \'\xc2\xb1\', \'\xc2\xb2\', \'\xc2\xb4\', \'\xc2\xbf\', \'\xc3\x97\', \'\xc3\x9f\', \'\xe1\xba\x9e\', \'\xc3\x81\', \'\xc3\xa1\', \'\xc3\xa2\', \'\xc3\xa3\', \'\xc3\xa4\', \'\xc3\xa7\', \'\xc3\xa8\', \'\xc3\xa9\', \'\xc3\x89\', \'\xc3\xaa\', \'\xc3\xad\', \'\xc3\xae\', \'\xc3\xaf\', \'\xc3\xb1\', \'\xc3\x91\', \'\xc3\xb3\', \'\xc3\x93\', \'\xc3\xb4\', \'\xc3\x96\', \'\xc3\xb6\', \'\xc3\xb7\', \'\xc3\xba\', \'\xc3\xbc\', \'\xc3\x9c\', \'\xc3\xbd\', \'\xc3\xbe\', \'\xc4\x81\', \'\xc4\x80\', \'\xc4\x87\', \'\xc4\x8d\', \'\xc4\x8c\', \'\xc4\x8e\', \'\xc4\x9b\', \'\xc4\xab\', \'\xc4\xb1\', \'\xc5\x82\', \'\xc5\x84\', \'\xc5\x9b\', \'\xc5\xa5\', \'\xc5\xbb\', \'\xc5\xbd\', \'\xc6\x9b\', \'\xc9\xb1\', \'\xca\x8f\', \'\xca\x92\', \'\xca\xbb\', \'\xca\xbf\', \'\xcb\x9a\', \'\xcc\x81\', \'\xcc\x83\', \'\xce\xaf\', \'\xce\xb1\', \'\xce\xb2\', \'\xce\x94\', \'\xce\xb5\', \'\xce\xb6\', \'\xce\xb8\', \'\xce\xbb\', \'\xce\xbc\', \'\xce\xbd\', \'\xce\xbe\', \'\xce\xbf\', \'\xcf\x80\', \'\xcf\x82\', \'\xce\xa3\', \'\xcf\x83\', \'\xcf\x89\', \'\xce\xa9\', \'\xd0\xb0\', \'\xd0\x90\', \'\xd0\xb1\', \'\xd0\x91\', \'\xd0\x92\', \'\xd0\xb2\', \'\xd0\x93\', \'\xd0\xb3\', \'\xd0\xb4\', \'\xd0\xb5\', \'\xd0\x95\', \'\xd0\xb6\', \'\xd0\xb7\', \'\xd0\x97\', \'\xd0\xb8\', \'\xd0\x98\', \'\xd0\xb9\', \'\xd0\x9a\', \'\xd0\xba\', \'\xd0\xbb\', \'\xd0\x9b\', \'\xd0\x9c\', \'\xd0\xbc\', \'\xd0\xbd\', \'\xd0\x9e\', \'\xd0\xbe\', \'\xd0\x9f\', \'\xd0\xbf\', \'\xd0\xa0\', \'\xd1\x80\', \'\xd1\x81\', \'\xd0\xa1\', \'\xd1\x82\', \'\xd1\x83\', \'\xd0\xa4\', \'\xd1\x84\', \'\xd1\x85\', \'\xd1\x86\', \'\xd0\xa7\', \'\xd1\x87\', \'\xd1\x8a\', \'\xd1\x8b\', \'\xd1\x8c\', \'\xd0\xad\', \'\xd1\x8f\', \'\xd0\xaf\', \'\xd1\x92\', \'\xd3\x98\', \'\xd4\xbb\', \'\xd5\xb8\', \'\xd8\xa7\', \'\xd8\xb1\', \'\xd8\xb9\', \'\xd9\x83\', \'\xd9\x85\', \'\xd9\x88\', \'\xd9\x8f\', \'\xd9\xb9\', \'\xd9\xbd\', \'\xda\xaa\', \'\xdc\x95\', \'\xe0\xa4\x85\', \'\xe0\xa4\x9f\', \'\xe0\xa4\xa1\', \'\xe0\xa4\xa4\', \'\xe0\xa4\xa5\', \'\xe0\xa4\xa8\', \'\xe0\xa4\xae\', \'\xe0\xa4\xb2\', \'\xe0\xa4\xb5\', \'\xe0\xa4\xb6\', \'\xe0\xa4\xbe\', \'\xe0\xa5\x80\', \'\xe0\xa5\x87\', \'\xe0\xa5\x8b\', \'\xe0\xa5\x8d\', \'\xe0\xa6\x87\', \'\xe0\xa6\x97\', \'\xe0\xa6\xa7\', \'\xe0\xa6\xac\', \'\xe0\xa6\xb2\', \'\xe0\xa6\xb6\', \'\xe0\xa7\x87\', \'\xe0\xa8\xac\', \'\xe0\xaa\xad\', \'\xe0\xab\x80\', \'\xe0\xac\xad\', \'\xe0\xae\xa4\', \'\xe0\xb0\x9f\', \'\xe0\xb0\xb0\', \'\xe0\xb0\xb8\', \'\xe0\xb2\x9f\', \'\xe0\xb5\x8b\', \'\xe0\xb7\x84\', \'\xe0\xb8\x87\', \'\xe0\xb8\xa2\', \'\xe0\xb8\xab\', \'\xe0\xb8\xb4\', \'\xe0\xb8\xb9\', \'\xe0\xbb\x80\', \'\xe0\xbb\x81\', \'\xe0\xbd\x84\', \'\xe0\xbd\x86\', \'\xe0\xbd\xbc\', \'\xe0\xbe\xa9\', \'\xe1\x80\x94\', \'\xe1\x80\xb8\', \'\xe1\x83\x9e\', \'\xe1\x83\xac\', \'\xe1\x88\x88\', \'\xe1\x88\x9b\', \'\xe1\x89\xb1\', \'\xe1\x8a\xad\', \'\xe1\x8b\xb0\', \'\xe1\x9e\x81\', \'\xe1\x9e\xb9\', \'\xe1\xb8\xa1\', \'\xe1\xb8\xaa\', \'\xe1\xb8\xbb\', \'\xe1\xb9\x81\', \'\xe1\xb9\x83\', \'\xe1\xba\x90\', \'\xe1\xbb\x85\', \'\xe1\xbb\x89\', \'\xe1\xbb\xb1\', \'\xe1\xbd\xa9\', \'\xe1\xbf\xb6\', \'\xe2\x80\x90\', \'\xe2\x80\x93\', \'\xe2\x80\x94\', \'\xe2\x80\x95\', \'\xe2\x80\x98\', \'\xe2\x80\x99\', \'\xe2\x80\x9c\', \'\xe2\x80\x9d\', \'\xe2\x80\xa0\', \'\xe2\x80\xa5\', \'\xe2\x80\xa6\', \'\xe2\x80\xb2\', \'\xe2\x80\xbb\', \'\xe2\x82\xa3\', \'\xe2\x84\x83\', \'\xe2\x84\x93\', \'\xe2\x86\x90\', \'\xe2\x86\x91\', \'\xe2\x86\x92\', \'\xe2\x86\x93\', \'\xe2\x87\x92\', \'\xe2\x87\x94\', \'\xe2\x88\x83\', \'\xe2\x88\x88\', \'\xe2\x88\x92\', \'\xe2\x88\x97\', \'\xe2\x88\x9e\', \'\xe2\x88\xb4\', \'\xe2\x89\x88\', \'\xe2\x89\x92\', \'\xe2\x89\xa0\', \'\xe2\x89\xa1\', \'\xe2\x89\xa5\', \'\xe2\x8e\xb1\', \'\xe2\x90\x8f\', \'\xe2\x90\xa1\', \'\xe2\x91\xa0\', \'\xe2\x91\xa1\', \'\xe2\x91\xa2\', \'\xe2\x91\xa3\', \'\xe2\x91\xa4\', \'\xe2\x91\xb0\', \'\xe2\x94\x80\', \'\xe2\x94\x81\', \'\xe2\x94\x83\', \'\xe2\x94\x9b\', \'\xe2\x94\xab\', \'\xe2\x95\xb3\', \'\xe2\x96\xa0\', \'\xe2\x96\xa1\', \'\xe2\x96\xaa\', \'\xe2\x96\xb2\', \'\xe2\x96\xb3\', \'\xe2\x96\xbc\', \'\xe2\x96\xbd\', \'\xe2\x97\x8b\', \'\xe2\x97\x8e\', \'\xe2\x98\x85\', \'\xe2\x98\x86\', \'\xe2\x98\x93\', \'\xe2\x99\x82\', \'\xe2\x99\xa1\', \'\xe2\x99\xa2\', \'\xe2\x99\xa3\', \'\xe2\x99\xa5\', \'\xe2\x99\xaa\', \'\xe2\x99\xad\', \'\xe2\x9c\x95\', \'\xe2\x9c\x96\', \'\xe2\x9d\x9d\', \'\xe2\xb5\x83\', \'\xe2\xba\x8c\', \'\xe2\xba\x95\', \'\xe2\xba\xae\', \'\xe2\xba\xbc\', \'\xe2\xbb\x8c\', \'\xe2\xbb\x8e\', \'\\u3000\', \'\xe3\x80\x81\', \'\xe3\x80\x82\', \'\xe3\x80\x83\', \'\xe3\x80\x86\', \'\xe3\x80\x87\', \'\xe3\x80\x88\', \'\xe3\x80\x89\', \'\xe3\x80\x8a\', \'\xe3\x80\x8b\', \'\xe3\x80\x8c\', \'\xe3\x80\x8d\', \'\xe3\x80\x8e\', \'\xe3\x80\x8f\', \'\xe3\x80\x90\', \'\xe3\x80\x91\', \'\xe3\x80\x92\', \'\xe3\x80\x93\', \'\xe3\x80\x94\', \'\xe3\x80\x95\', \'\xe3\x80\x9c\', \'\xe3\x80\xa1\', \'\xe3\x80\xb3\', \'\xe3\x80\xb4\', \'\xe3\x80\xb5\', \'\xe3\x80\xbb\', \'\xe3\x82\x8e\', \'\xe3\x82\x90\', \'\xe3\x82\x91\', \'\xe3\x82\x94\', \'\xe3\x82\x95\', \'\xe3\x82\x96\', \'\xe3\x82\x99\', \'\xe3\x82\x9b\', \'\xe3\x82\x9c\', \'\xe3\x82\x9d\', \'\xe3\x82\x9e\', \'\xe3\x82\x9f\', \'\xe3\x83\xae\', \'\xe3\x83\xb7\', \'\xe3\x83\xb8\', \'\xe3\x83\xb9\', \'\xe3\x83\xba\', \'\xe3\x83\xbb\', \'\xe3\x83\xbc\', \'\xe3\x83\xbd\', \'\xe3\x83\xbe\', \'\xe3\x83\xbf\', \'\xe3\x87\xb0\', \'\xe3\x87\xb1\', \'\xe3\x87\xb2\', \'\xe3\x87\xb3\', \'\xe3\x87\xb4\', \'\xe3\x87\xb5\', \'\xe3\x87\xb6\', \'\xe3\x87\xb7\', \'\xe3\x87\xb8\', \'\xe3\x87\xb9\', \'\xe3\x87\xba\', \'\xe3\x87\xbb\', \'\xe3\x87\xbc\', \'\xe3\x87\xbd\', \'\xe3\x87\xbe\', \'\xe3\x87\xbf\', \'\xe3\x8b\x96\', \'\xe3\x8b\x9a\', \'\xe3\x8b\xa1\', \'\xe3\x8b\xa3\', \'\xe3\x8b\xa8\', \'\xe3\x8b\xaa\', \'\xe3\x8b\xae\', \'\xe3\x8b\xb2\', \'\xe3\x8b\xb9\', \'\xe3\x8c\x94\', \'\xe3\x8c\x98\', \'\xe3\x8c\xa2\', \'\xe3\x8c\xa3\', \'\xe3\x8c\xa6\', \'\xe3\x8c\xa7\', \'\xe3\x8c\xab\', \'\xe3\x8c\xbb\', \'\xe3\x8d\x89\', \'\xe3\x8d\x8d\', \'\xe3\x8d\x91\', \'\xe3\x8e\x9e\', \'\xe3\x8e\xa1\', \'\xe3\x8e\xa5\', \'\xe3\x90\x85\', \'\xeb\x82\x98\', \'\xeb\x94\x9c\', \'\xeb\xa5\xb4\', \'\xeb\xa6\xbc\', \'\xeb\xa7\x8c\', \'\xeb\xa9\x94\', \'\xeb\xac\xb8\', \'\xeb\xae\xa4\', \'\xec\x95\xbd\', \'\xec\x98\xa4\', \'\xec\x99\x95\', \'\xec\x9d\xb8\', \'\xec\x9e\x85\', \'\xec\x9f\x81\', \'\xec\xa0\x95\', \'\xed\x8e\x9c\', \'\xed\x95\xad\', \'\xed\x96\x88\', \'\xed\x98\x95\', \'\xed\x99\x94\', \'\xed\x9b\x88\', \'\xe8\x89\xb9\', \'\xe8\xbe\xb6\', \'\xef\xbc\x81\', \'\xef\xbc\x84\', \'\xef\xbc\x85\', \'\xef\xbc\x86\', \'\xef\xbc\x88\', \'\xef\xbc\x89\', \'\xef\xbc\x8a\', \'\xef\xbc\x8b\', \'\xef\xbc\x8c\', \'\xef\xbc\x8d\', \'\xef\xbc\x8e\', \'\xef\xbc\x8f\', \'\xef\xbc\x90\', \'\xef\xbc\x91\', \'\xef\xbc\x92\', \'\xef\xbc\x93\', \'\xef\xbc\x94\', \'\xef\xbc\x95\', \'\xef\xbc\x96\', \'\xef\xbc\x97\', \'\xef\xbc\x98\', \'\xef\xbc\x99\', \'\xef\xbc\x9a\', \'\xef\xbc\x9b\', \'\xef\xbc\x9c\', \'\xef\xbc\x9d\', \'\xef\xbc\x9e\', \'\xef\xbc\x9f\', \'\xef\xbc\xa0\', \'\xef\xbc\xbb\', \'\xef\xbc\xbd\', \'\xef\xbc\xbe\', \'\xef\xbc\xbf\', \'\xef\xbd\x80\', \'\xef\xbc\xa1\', \'\xef\xbd\x81\', \'\xef\xbd\x82\', \'\xef\xbc\xa2\', \'\xef\xbd\x83\', \'\xef\xbc\xa3\', \'\xef\xbd\x84\', \'\xef\xbc\xa4\', \'\xef\xbd\x85\', \'\xef\xbc\xa5\', \'\xef\xbc\xa6\', \'\xef\xbd\x87\', \'\xef\xbc\xa7\', \'\xef\xbd\x88\', \'\xef\xbc\xa8\', \'\xef\xbc\xa9\', \'\xef\xbd\x89\', \'\xef\xbd\x8a\', \'\xef\xbc\xaa\', \'\xef\xbd\x8b\', \'\xef\xbc\xab\', \'\xef\xbc\xac\', \'\xef\xbd\x8c\', \'\xef\xbd\x8d\', \'\xef\xbc\xad\', \'\xef\xbd\x8e\', \'\xef\xbc\xae\', \'\xef\xbc\xaf\', \'\xef\xbd\x8f\', \'\xef\xbd\x90\', \'\xef\xbc\xb0\', \'\xef\xbc\xb1\', \'\xef\xbd\x92\', \'\xef\xbc\xb2\', \'\xef\xbc\xb3\', \'\xef\xbd\x93\', \'\xef\xbc\xb4\', \'\xef\xbd\x94\', \'\xef\xbc\xb5\', \'\xef\xbd\x95\', \'\xef\xbd\x96\', \'\xef\xbc\xb6\', \'\xef\xbd\x97\', \'\xef\xbc\xb7\', \'\xef\xbc\xb8\', \'\xef\xbd\x98\', \'\xef\xbc\xb9\', \'\xef\xbd\x99\', \'\xef\xbc\xba\', \'\xef\xbd\x9a\', \'\xef\xbd\x9b\', \'\xef\xbd\x9c\', \'\xef\xbd\x9d\', \'\xef\xbd\x9e\', \'\xef\xbd\xa1\', \'\xef\xbd\xa2\', \'\xef\xbd\xa3\', \'\xef\xbd\xa4\', \'\xef\xbd\xa5\', \'\xef\xbd\xa6\', \'\xef\xbd\xa7\', \'\xef\xbd\xa8\', \'\xef\xbd\xa9\', \'\xef\xbd\xaa\', \'\xef\xbd\xab\', \'\xef\xbd\xac\', \'\xef\xbd\xad\', \'\xef\xbd\xae\', \'\xef\xbd\xaf\', \'\xef\xbd\xb0\', \'\xef\xbd\xb1\', \'\xef\xbd\xb2\', \'\xef\xbd\xb3\', \'\xef\xbd\xb4\', \'\xef\xbd\xb5\', \'\xef\xbd\xb6\', \'\xef\xbd\xb7\', \'\xef\xbd\xb8\', \'\xef\xbd\xb9\', \'\xef\xbd\xba\', \'\xef\xbd\xbb\', \'\xef\xbd\xbc\', \'\xef\xbd\xbd\', \'\xef\xbd\xbe\', \'\xef\xbd\xbf\', \'\xef\xbe\x80\', \'\xef\xbe\x81\', \'\xef\xbe\x82\', \'\xef\xbe\x83\', \'\xef\xbe\x84\', \'\xef\xbe\x85\', \'\xef\xbe\x86\', \'\xef\xbe\x87\', \'\xef\xbe\x88\', \'\xef\xbe\x89\', \'\xef\xbe\x8a\', \'\xef\xbe\x8b\', \'\xef\xbe\x8c\', \'\xef\xbe\x8d\', \'\xef\xbe\x8e\', \'\xef\xbe\x8f\', \'\xef\xbe\x90\', \'\xef\xbe\x91\', \'\xef\xbe\x92\', \'\xef\xbe\x93\', \'\xef\xbe\x94\', \'\xef\xbe\x95\', \'\xef\xbe\x96\', \'\xef\xbe\x97\', \'\xef\xbe\x98\', \'\xef\xbe\x99\', \'\xef\xbe\x9a\', \'\xef\xbe\x9b\', \'\xef\xbe\x9c\', \'\xef\xbe\x9d\', \'\xef\xbe\x9e\', \'\xef\xbe\x9f\', \'\xef\xbf\xa1\', \'\xef\xbf\xa3\', \'\xef\xbf\xa5\', \'\xef\xbf\xbc\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\xe9\xa6\xa7\']\n\nstopwords = list(punctuation) + hiragana + katakana + cjk_punctuations + romanji + mccarl_stoplist\nstopwords = set(stopwords)\n\nwith open(\'japanese_sample_text.txt\') as fin:\n for line in fin:\n # Remove stopwords.\n characters = [char if char not in stopwords else \'_\' for char in line.strip()]\n words = [kanjiword for kanjiword in \'\'.join(characters).split(\'_\') if kanjiword]\n if words:\n print (words)\nRun Code Online (Sandbox Code Playgroud)\n\n[在]:
\n\n\n\n\n\xe8\x8d\x92\xe5\xb7\x9d\xe6\x94\xaf\xe6\xb5\x81\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe6\xbb\x9d\xe5 \xb7\x9d\xe3\x81\xae\xe6\x94\xaf\xe6\xb5\x81\xe3\x81\xa8\xe3\x81\xaa\xe3\x81\xa3\xe3\x81\xa6\xe3\x81 \x84\xe3\x82\x8b\xe3\x80\x82\xe6\xb5\x81\xe8\xb7\xaf\xe5\xbb\xb6\xe9\x95\xb7\xe3\x81\xaf5.0\xe3\x82 \xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3\x83\x88\xe3\x83\xab\xe3\x80\x81\xe6\xb5\x81\xe5\x9f\x9f \xe9\x9d\xa2\xe7\xa9\x8d\xe3\x81\xaf9.8\xe5\xb9\xb3\xe6\x96\xb9\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1 \xe3\x83\xbc\xe3\x83\x88\xe3\x83\xab\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8b\xe3\x80\x82\xe6\xb5\x81\xe5 \x9f\x9f\xe3\x81\xaf\xe5\x85\xa8\xe3\x81\xa6\xe5\xb1\xb1\xe5\x9c\xb0\xe3\x81\xab\xe5\xb1\x9e\xe3\x81 \x97\xe3\x81\xa6\xe3\x81\x84\xe3\x82\x8b\xe3\x80\x82\xe5\xa5\xa5\xe7\xa7\xa9\xe7\x88\xb6\xe3\x82\x92 \xe4\xbb\xa3\xe8\xa1\xa8\xe3\x81\x99\xe3\x82\x8b\xe6\xb2\xa2\xe7\x99\xbb\xe3\x82\x8a\xe3\x82\xb9\xe3 \x83\x9d\xe3\x83\x83\xe3\x83\x88\xe3\x81\xa8\xe3\x81\xaa\xe3\x81\xa3\xe3\x81\xa6\xe3\x81\x84\xe3\x82 \x8b\xe3\x80\x82\xe6\xb5\x81\xe8\xb7\xaf\xe3\x81\xab\xe3\x81\xaf\xe3\x83\x9b\xe3\x83\x81\xe3\x81\xae \xe6\xbb\x9d\xe3\x83\xbb\xe3\x83\x88\xe3\x82\xaa\xe3\x81\xae\xe6\xbb\x9d\xe3\x81\xae\xe3\x81\xbb\xe3 \x81\x8b\xe3\x80\x81\xe9\x8d\xbe\xe4\xb9\xb3\xe6\xb4\x9e\xe3\x80\x8c\xe7\x80\xa7\xe8\xb0\xb7\xe6\xb4 \x9e\xe3\x80\x8d\xe3\x81\x8c\xe3\x81\x82\xe3\x82\x8b\xe3\x80\x82\xe6\x98\xad\xe5\x92\x8c\xe5\x88\x9d \xe6\x9c\x9f\xe3\x81\xab\xe3\x81\xaf\xe5\x8e\x9f\xe5\x85\xa8\xe6\x95\x99\xe3\x81\x8c\xe3\x80\x8c\xe5 \xa5\xa5\xe7\xa7\xa9\xe7\x88\xb6\xe3\x80\x8d\xe3\x81\xab\xe8\xb1\x86\xe7\x84\xbc\xe5\xb7\x9d\xe3\x81 \xae\xe7\xb4\x80\xe8\xa1\x8c\xe6\x96\x87\xe3\x82\x92\xe6\xae\x8b\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x84 \xe3\x82\x8b\xe3\x80\x82
\n
[出去]:
\n\n[\'\xe8\x8d\x92\xe5\xb7\x9d\xe6\x94\xaf\xe6\xb5\x81\', \'\xe6\xbb\x9d\xe5\xb7\x9d\', \'\xe6\x94\xaf\xe6\xb5\x81\', \'\xe6\xb5\x81\xe8\xb7\xaf\xe5\xbb\xb6\xe9\x95\xb7\', \'\xe6\xb5\x81\xe5\x9f\x9f\xe9\x9d\xa2\xe7\xa9\x8d\', \'\xe5\xb9\xb3\xe6\x96\xb9\', \'\xe6\xb5\x81\xe5\x9f\x9f\', \'\xe5\x85\xa8\', \'\xe5\xb1\xb1\xe5\x9c\xb0\', \'\xe5\xb1\x9e\', \'\xe5\xa5\xa5\xe7\xa7\xa9\xe7\x88\xb6\', \'\xe4\xbb\xa3\xe8\xa1\xa8\', \'\xe6\xb2\xa2\xe7\x99\xbb\', \'\xe6\xb5\x81\xe8\xb7\xaf\', \'\xe6\xbb\x9d\', \'\xe6\xbb\x9d\', \'\xe9\x8d\xbe\xe4\xb9\xb3\xe6\xb4\x9e\', \'\xe7\x80\xa7\xe8\xb0\xb7\xe6\xb4\x9e\', \'\xe6\x98\xad\xe5\x92\x8c\xe5\x88\x9d\xe6\x9c\x9f\', \'\xe5\x8e\x9f\xe5\x85\xa8\xe6\x95\x99\', \'\xe5\xa5\xa5\xe7\xa7\xa9\xe7\x88\xb6\', \'\xe8\xb1\x86\xe7\x84\xbc\xe5\xb7\x9d\', \'\xe7\xb4\x80\xe8\xa1\x8c\xe6\x96\x87\', \'\xe6\xae\x8b\']\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
543 次 |
| 最近记录: |