python - python 中的 Nltk 法语分词器无法正常工作

标签 python nltk tokenize

为什么 python 自带的 french tokenizer 对我不起作用? 我做错了什么吗?

我在做

import nltk
content_french = ["Les astronomes amateurs jouent également un rôle important en recherche; les plus sérieux participant couramment au suivi d'étoiles variables, à la découverte de nouveaux astéroïdes et de nouvelles comètes, etc.", 'Séquence vidéo.', "John Richard Bond explique le rôle de l'astronomie."]
tokenizer = nltk.data.load('tokenizers/punkt/PY3/french.pickle')
for i in content_french:
        print(i)
        print(tokenizer.tokenize(i))

但我得到的是非标记化的输出

John Richard Bond explique le rôle de l'astronomie.
["John Richard Bond explique le rôle de l'astronomie."]

最佳答案

tokenizer.tokenize() 是句子分词器(分割器)。如果你想标记单词然后使用 word_tokenize():

import nltk
from nltk.tokenize import word_tokenize

content_french = ["Les astronomes amateurs jouent également un rôle important en recherche; les plus sérieux participant couramment au suivi d'étoiles variables, à la découverte de nouveaux astéroïdes et de nouvelles comètes, etc.", 'Séquence vidéo.', "John Richard Bond explique le rôle de l'astronomie."]
for i in content_french:
        print(i)
        print(word_tokenize(i, language='french'))

Reference

关于python - python 中的 Nltk 法语分词器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42428390/

相关文章:

R 向量化函数的 Pythonic 替代品

python - 使用 NLTK 3 将法语翻译成英语

Python 3 不适用于 NLTK 3

java - 读取文件时数组索引越界

python - 如何使用 Python nltk.tokenize 将包含停用词的短语视为单个标记

python - 如何在 Python 中导入 lib.sort

Python排序txt文件的内容

python - 在 openCV 中显示的图像之间暂停

python - 将未标记语料库转换为标记语料库 (NLTK)

python - NLTK的一些问题