擅长:python、mysql、java
<p>还有一种方法(利用元组的优势):</p>
<pre><code>from nltk.corpus import wordnet as wn
from nltk import pos_tag
import nltk
sentence = "Hello my name is Abhishek Mitra"
sentence = nltk.word_tokenize(sentence)
sent = pos_tag(sentence)
sent_clean = [x for (x,y) in sent if y not in ('NN')]
print(sent_clean)
</code></pre>
<p><strong>输出:</strong></p>
^{pr2}$
<p><strong>说明:</strong>
在准则中:</p>
<pre><code>sent_clean = [x for (x,y) in sent if y not in ('NN')]
</code></pre>
<p>在对句子中的每个单词进行POS标记后,您将尝试提取由POS标记创建的元组的单词。指定要提取的条件是第二部分</p>
<p>同样,如果要消除多个POS:</p>
<pre><code>sent_clean2 = [x for (x,y) in sent if y not in ('PRP$', 'VBZ', 'NN')]
print(sent_clean2)
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>['Hello', 'Abhishek', 'Mitra']
</code></pre>