Introduction au traitement du langage naturel en Python
Katharine Jarmul
Founder, kjamistan
Texte : « The cat is in the box. The cat likes the box. The box is over the cat. »
Sac de mots (ponctuation retirée) :
from nltk.tokenize import word_tokenizefrom collections import CounterCounter(word_tokenize("""The cat is in the box. The cat likes the box. The box is over the cat."""))
Counter({'.': 3,
'The': 3,
'box': 3,
'cat': 3,
'in': 1,
...
'the': 3})
counter.most_common(2)
[('The', 3), ('box', 3)]
Introduction au traitement du langage naturel en Python