2017-04-16 3 views
0

thisからtext1.similar( "monstrous")とtext1.concordance( "monstrous")を読みました。nltkのsimilar()とconcordanceの相違点

ここでは、Pythonの自然言語処理ツールキットのtext1.concordance('monstrous')text1.similar('monstrous')の違いについて満足のいく答えを得ることができませんでした。

例を詳しく説明してください。

答えて

1

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 

の一致を確認することができますそして、我々は'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 

私たちは言葉'true'を取ると、それは我々が単語「true」の最初の25 87の使用を取り戻すだろうtext.concordance('true')との一致です確認してください。これは非常に有用ではありませんが、NLTKでは、単語リストの使用が同じ周囲の単語をいつ使用するかを示すcommon_contextsという追加の方法を提供しています。

text1.common_contexts(['monstrous', 'true']) 

# returns: 
the_pictures 

この結果は、フレーズ"the monstrous pictures""the true pictures"両方が白鯨に表示されていることを教えてくれる。

+0

あなたの優れた説明をありがとうございます。しかし、私は同様のことについて完全にはっきりしていませんので、試してみてください。 @ジェームス – dex