Pythonのテキスト分析ノート
中国のストップワード処理
次のようにshotwords.txtをダウンロードするには、コードは次のとおりです。
def
stopwordslist(filepath):
stopwords
=
[line.strip()
for
line
in
open
(filepath,
'r'
, encoding
=
'utf-8'
).readlines()]
return
stopwords
# 对句子进行分词
def
seg_sentence(sentence):
sentence_seged
=
jieba.cut(sentence.strip())
stopwords
=
stopwordslist(
'/root/stopwords.txt'
)
# 这里加载停用词的路径
outstr
=
''
for
word
in
sentence_seged:
if
word
not
in
stopwords:
if
word !
=
'\t'
:
outstr
+
=
word
outstr
+
=
" "
return
outstr
|