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

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

问题描述

我正在使用 nltk,所以我想创建我自己的自定义文本,就像 nltk.books 上的默认文本一样.但是,我刚刚开始使用

之类的方法

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

我想找到任何方式来输入我的文本":

"

my_text = "这是我的文字,这是输入文字的好方法."

python 或 nltk 的哪种方法允许我这样做.更重要的是,我怎样才能忽略标点符号?

解决方案

这实际上在 nltk.org 的主页:><预><代码>>>>导入 nltk>>>句子="""星期四早上八点……亚瑟感觉不太好."">>>令牌 = nltk.word_tokenize(句子)>>>令牌['At', '8', "o'clock", 'on', 'Thursday', '早上','亚瑟'、'做过'、'不'、'感觉'、'非常'、'好'、'.']

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."

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

解决方案

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天全站免登陆