dex*_*dex 5 python text-processing nltk
我已阅读从text1.similar("怪物")和text1.concordance("怪物")此.
当我不能得到之间的差额满意的答复text1.concordance('monstrous'),并text1.similar('monstrous')在Python自然语言处理工具包.
那么请你详细解释一下这个例子吗?
Jam*_*mes 12
使用concordance(token)为您提供有关参数的上下文token.它会显示token出现的句子.
使用similar(token)返回与同一上下文中出现的单词列表token.在这种情况下,上下文就是直接在两边的单词token.
所以,看看Moby Dick的文字(text1).我们可以检查一致性'monstrous'
text1.concordance('monstrous')
# returns:
Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ... This came towards us ,
ON OF THE PSALMS . " Touching that monstrous bulk of the whale or ork we have r
ll over with a heathenish array of monstrous clubs and spears . Some were thick
d as you gazed , and wondered what monstrous cannibal and savage could ever hav
that has survived the flood ; most monstrous and most mountainous ! That Himmal
they might scout at Moby Dick as a monstrous fable , or still worse and more de
th of Radney .'" CHAPTER 55 Of the Monstrous Pictures of Whales . I shall ere l
ing Scenes . In connexion with the monstrous pictures of whales , I am strongly
ere to enter upon those still more monstrous stories of them which are to be fo
ght have been rummaged out of this monstrous cabinet there is no telling . But
of Whale - Bones ; for Whales of a monstrous size are oftentimes cast up dead u
Run Code Online (Sandbox Code Playgroud)
然后我们可以得到一个出现在类似上下文中的单词列表'monstrous'.第一个返回行的上下文是'most _____ size'.
text1.similar('monstrous')
# returns:
determined maddens contemptible modifies abundant tyrannical puzzled
trustworthy impalpable gamesome curious mean pitiable untoward
christian subtly passing domineering uncommon true
Run Code Online (Sandbox Code Playgroud)
如果我们接受这个词'true'并检查它的一致性,text.concordance('true')我们将取回87个用法中的前25个true.这并不是非常有用,但是NLTK确实提供了一种额外的方法common_contexts,可以在使用单词列表共享相同的周围单词时显示.
text1.common_contexts(['monstrous', 'true'])
# returns:
the_pictures
Run Code Online (Sandbox Code Playgroud)
这个结果告诉我们,短语"the monstrous pictures"和"the true pictures"两者都出现在Moby Dick中.