擅长:python、mysql、java
<p>在您发送的链接中,它表示此函数是一个功能提取器,它只检查给定文档中是否存在这些单词。</p>
<p>这是每一行带有数字的完整代码:</p>
<pre><code>1 all_words = nltk.FreqDist(w.lower() for w in movie_reviews.words())
2 word_features = all_words.keys()[:2000]
3 def document_features(document):
4 document_words = set(document)
5 features = {}
6 for word in word_features:
7 features['contains(%s)' % word] = (word in document_words)
8 return features
</code></pre>
<p>在第1行,它创建了一个包含所有单词的列表。</p>
<p>在第二行中,最常用的是2000个单词。</p>
<p>3功能的定义</p>
<p>4转换文档列表(我认为它必须是列表)并将列表转换为集合。</p>
<p>5声明字典</p>
<p>在所有最频繁的2000个单词中重复6次</p>
<p>7创建一个字典,其中键为“contains(theword)”,值为true或false。如果文档中有单词,则为True;否则为false</p>
<p>8返回显示文档是否包含最常用的2000个单词的字典。</p>
<p>这能回答你的问题吗?</p>