如何在NLTK中标记字符串语句? [英] How do I tokenize a string sentence in NLTK?

查看:62
本文介绍了如何在NLTK中标记字符串语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nltk,因此我想创建自己的自定义文本,就像nltk.books上的默认文本一样.但是,我刚刚掌握了类似

I am using nltk, so I want to create my own custom texts just like the default ones on nltk.books. However, I've just got up to the method like

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

我想发现将文字"输入为的任何方式:

I'd like to discover any way to input my "text" as:

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

哪个方法(python的或来自nltk的方法)允许我执行此操作.更重要的是,我如何消除标点符号?

Which method, python's or from nltk allows me to do this. And more important, how can I dismiss punctuation symbols?

推荐答案

这实际上是在 nltk.org主页上:

This is actually on the main page of 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', '.']

这篇关于如何在NLTK中标记字符串语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆