tutorial texto sirve sentimientos que para mineria instalar español ejemplos ejemplo con como analisis python nlp tokenize nltk

python - texto - ¿Cómo puedo tokenizar una oración de cadena en NLTK?



nltk tutorial (2)

Estoy usando nltk, así que quiero crear mis propios textos personalizados al igual que los predeterminados en nltk.books. Sin embargo, acabo de llegar al método como

my_text = [''This'', ''is'', ''my'', ''text'']

Me gustaría descubrir cualquier forma de ingresar mi "texto" como:

my_text = "This is my text, this is a nice way to input text."

¿Qué método, python o de nltk me permite hacer esto? Y más importante, ¿cómo puedo subestimar los símbolos de puntuación?


Como respondió @PavelAnossov, la respuesta canónica, usa la función word_tokenize en nltk:

from nltk import word_tokenize sent = "This is my text, this is a nice way to input text." word_tokenize(sent)

Si tu oración es realmente lo suficientemente simple:

Usando el conjunto string.punctuation , elimine la puntuación y luego divida usando el delimitador de espacios en blanco:

import string x = "This is my text, this is a nice way to input text." y = "".join([i for i in x if not in string.punctuation]).split(" ") print y


Esto es realmente en la página principal de nltk.org :

>>> import nltk >>> sentence = """At eight o''clock on Thursday morning ... Arthur didn''t feel very good.""" >>> tokens = nltk.word_tokenize(sentence) >>> tokens [''At'', ''eight'', "o''clock", ''on'', ''Thursday'', ''morning'', ''Arthur'', ''did'', "n''t", ''feel'', ''very'', ''good'', ''.'']