python 英语精细分句
时间: 2023-11-20 08:56:33 浏览: 144
Python 分词
为了实现英语精细分句,我们需要使用nltk库中的sent_tokenize()函数。该函数可以将文本分成句子列表,其中句子的边界由标点符号和其他特殊字符确定。以下是一个例子:
```python
import nltk
nltk.download('punkt') # 下载punkt数据包
text = "Hello Mr. Smith, how are you doing today? The weather is great, and Python is awesome. The sky is pinkish-blue. You shouldn't eat cardboard."
sentences = nltk.sent_tokenize(text)
for sentence in sentences:
print(sentence)
```
输出结果为:
```
Hello Mr. Smith, how are you doing today?
The weather is great, and Python is awesome.
The sky is pinkish-blue.
You shouldn't eat cardboard.
```
阅读全文