为了在python中拆分单词,我使用了wordsegment库,它有内置的字典,根据字典进行单词的拆分。有没有人能告诉我怎么把更多的单词加到字典里?代码如下:
import wordsegment as ws
from wordsegment import load, segment
from wordsegment import segment
help(wordsegment)
load()
segment("rollersharp")
['roller', 'sharp']该词典来自以下链接:https://github.com/grantjenks/python-wordsegment/tree/master/wordsegment
发布于 2018-02-20 19:45:05
自定义字典的用法在official docs中有很好的介绍。
要扩展现有语料库,需要更新wordsegment.UNIGRAMS和wordsegment.BIGRAMS
发布于 2018-02-20 19:59:01
如果你想创建一个新的字典,请点击这个链接http://www.grantjenks.com/docs/wordsegment/using-a-different-corpus.html。如果要将单词添加到现有词典中,请使用
import wordsegment as ws
ws.bigram_counts['my text'] = 10.2e6 #basing on number of google search results returned
ws.segment('my text')希望这能有所帮助。
https://stackoverflow.com/questions/48884497
复制相似问题