Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong word segmentation in chinese course #125

Open
placebokkk opened this issue Mar 7, 2022 · 1 comment
Open

Wrong word segmentation in chinese course #125

placebokkk opened this issue Mar 7, 2022 · 1 comment

Comments

@placebokkk
Copy link

The sentence is just splited by character.

# 导入spacy并创建中文nlp对象
import spacy

nlp = spacy.blank("zh")

# 处理文本
doc = nlp("我喜欢老虎和狮子。")

# 遍历打印doc中的内容
for i, token in enumerate(doc):
    print(i, token.text)

# 截取Doc中"老虎"的部分
laohu = doc[2:3]
print(laohu.text)

# 截取Doc中"老虎和狮子"的部分(不包括"。")
laohu_he_shizi = doc[2:5]
print(laohu_he_shizi.text)

Output

0 我
1 喜
2 欢
3 老
4 虎
5 和
6 狮
7 子
8 。
欢
欢老虎
@adrianeboyd
Copy link
Collaborator

Thanks for the note, we should update this to use jieba, I suspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants