中英文分句

版权声明:本文为博主原创文章,未经博主允许不得转载。如需转载,加上原文链接即可~~ https://blog.csdn.net/hpulfc/article/details/82387373

中英文分句

这里主要是使用了两个包:pyltp 和 nltk

安装过程省略,使用方式如下:

import nltk  # 英文分句
from pyltp import SentenceSplitter  # 中文分句

s = "Since I was very small, I was very shy in the public place, so I always avoided giving performance in front of so many people. Though I tried hard to get over it in school, I still felt uneasy in the public place. When I came to the job market, I realized that I must get over my fear, or I would lose my stage.

print "\n".join(nltk.sent_tokenize(s))

# Since I was very small, I was very shy in the public place, so I always avoided giving performance in front of so many people.
# Though I tried hard to get over it in school, I still felt uneasy in the public place.
# When I came to the job market, I realized that I must get over my fear, or I would lose my stage. 

x = "在我很小的时候,在公共场合我会感到非常的害羞,所以我总是避免在人多的情况下表演。虽然我在学校努力想要克服这个问题,但在公共场合我还是感到不自在。当我来到就业市场时,我意识到我必须克服我的恐惧了,否则我将失去自己的舞台。"

sents = SentenceSplitter.split(x)
print "\n".join(sents)

# 在我很小的时候,在公共场合我会感到非常的害羞,所以我总是避免在人多的情况下表演。
# 虽然我在学校努力想要克服这个问题,但在公共场合我还是感到不自在。
# 当我来到就业市场时,我意识到我必须克服我的恐惧了,否则我将失去自己的舞台。

http://www.pythontip.com/blog/post/10012/

猜你喜欢

转载自blog.csdn.net/hpulfc/article/details/82387373