擅长:python、mysql、java
<p>前面的答案是复杂的,无法编辑,所以这里有一个更传统的答案。</p>
<pre><code># make sure your downloaded the english model with "python -m spacy download en"
import spacy
nlp = spacy.load('en')
doc = nlp(u"Apples and oranges are similar. Boots and hippos aren't.")
for token in doc:
print(token, token.lemma, token.lemma_)
</code></pre>
<p>输出:</p>
<pre><code>Apples 6617 apples
and 512 and
oranges 7024 orange
are 536 be
similar 1447 similar
. 453 .
Boots 4622 boot
and 512 and
hippos 98365 hippo
are 536 be
n't 538 not
. 453 .
</code></pre>
<p>从<a href="https://spacy.io/docs/usage/lightning-tour" rel="noreferrer">official Lighting tour</a></p>