当前位置: 首页>>代码示例>>Python>>正文


Python jieba.set_dictionary方法代码示例

本文整理汇总了Python中jieba.set_dictionary方法的典型用法代码示例。如果您正苦于以下问题:Python jieba.set_dictionary方法的具体用法?Python jieba.set_dictionary怎么用?Python jieba.set_dictionary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jieba的用法示例。


在下文中一共展示了jieba.set_dictionary方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: segment_trans

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def segment_trans(vocab_file, text_file):
    ''' segment transcripts according to vocab
        using Maximum Matching Algorithm
    Args:
      vocab_file: vocab file
      text_file: transcripts file
    Returns:
      seg_trans: segment words
    '''
    jieba.set_dictionary(vocab_file)
    with open(text_file, "r", encoding="utf-8") as text:
        lines = text.readlines()
        sents = ''
        for line in lines:
            seg_line = jieba.cut(line.strip(), HMM=False)
            seg_line = ' '.join(seg_line)
            sents += seg_line + '\n'
        return sents 
开发者ID:athena-team,项目名称:athena,代码行数:20,代码来源:segment_word.py

示例2: testSetDictionary

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def testSetDictionary(self):
        jieba.set_dictionary("foobar.txt")
        for content in test_contents:
            result = jieba.cut(content)
            assert isinstance(result, types.GeneratorType), "Test SetDictionary Generator error"
            result = list(result)
            assert isinstance(result, list), "Test SetDictionary error on content: %s" % content
            print(" , ".join(result), file=sys.stderr)
        print("testSetDictionary", file=sys.stderr) 
开发者ID:deepcs233,项目名称:jieba_fast,代码行数:11,代码来源:jieba_test.py

示例3: main

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def main():

    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

    # jieba custom setting.
    jieba.set_dictionary('jieba_dict/dict.txt.big')

    # load stopwords set
    stopword_set = set()
    with io.open('jieba_dict/stopwords.txt', 'r', encoding='utf-8') as stopwords:
        for stopword in stopwords:
            stopword_set.add(stopword.strip('\n'))

    output = io.open('wiki_seg.txt','w', encoding='utf-8')
    with io.open('wiki_zh_tw.txt','r', encoding='utf-8') as content :
        for texts_num, line in enumerate(content):
            line = line.strip('\n')
            words = jieba.cut(line, cut_all=False)
            for word in words:
                if word not in stopword_set:
                    output.write(word +' ')
            output.write('\n')

            if (texts_num + 1) % 10000 == 0:
                logging.info("已完成前 %d 行的斷詞" % (texts_num + 1))
    output.close() 
开发者ID:zake7749,项目名称:word2vec-tutorial,代码行数:28,代码来源:segment.py

示例4: main

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def main():

    logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

    # jieba custom setting.
    jieba.set_dictionary('jieba_dict/dict.txt.big')

    # load stopwords set
    stopword_set = set()
    with open('jieba_dict/stopwords.txt','r', encoding='utf-8') as stopwords:
        for stopword in stopwords:
            stopword_set.add(stopword.strip('\n'))

    output = open('wiki_seg.txt', 'w', encoding='utf-8')
    with open('wiki_zh_tw.txt', 'r', encoding='utf-8') as content :
        for texts_num, line in enumerate(content):
            line = line.strip('\n')
            words = jieba.cut(line, cut_all=False)
            for word in words:
                if word not in stopword_set:
                    output.write(word + ' ')
            output.write('\n')

            if (texts_num + 1) % 10000 == 0:
                logging.info("已完成前 %d 行的斷詞" % (texts_num + 1))
    output.close() 
开发者ID:zake7749,项目名称:word2vec-tutorial,代码行数:28,代码来源:segment.py

示例5: init_jieba

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def init_jieba(self, seg_dic, userdic):

        """
        jieba custom setting.
        """

        jieba.load_userdict(userdic)
        jieba.set_dictionary(seg_dic)
        with open(userdic,'r',encoding='utf-8') as input:
            for word in input:
                word = word.strip('\n')
                jieba.suggest_freq(word, True) 
开发者ID:zake7749,项目名称:Chatbot,代码行数:14,代码来源:console.py

示例6: jiebaCustomSetting

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def jiebaCustomSetting(self, dict_path, usr_dict_path):

        jieba.set_dictionary(dict_path)
        with open(usr_dict_path, 'r', encoding='utf-8') as dic:
            for word in dic:
                jieba.add_word(word.strip('\n')) 
开发者ID:zake7749,项目名称:Chatbot,代码行数:8,代码来源:matcher.py

示例7: setUp

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def setUp(self):
        jieba.set_dictionary(APP_RESOURCES_DATA_PATH + 'jieba.dict')  # 设置中文分词库 
开发者ID:tenstone,项目名称:kim-voice-assistant,代码行数:4,代码来源:plugins_test.py

示例8: set_default_dict

# 需要导入模块: import jieba [as 别名]
# 或者: from jieba import set_dictionary [as 别名]
def set_default_dict(tokenizer, path_default_dict):
        print("Setting Jieba Default Dictionary at " + str(path_default_dict))
        tokenizer.set_dictionary(path_default_dict)
        
        return tokenizer 
开发者ID:crownpku,项目名称:Rasa_NLU_Chi,代码行数:7,代码来源:jieba_tokenizer.py


注:本文中的jieba.set_dictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。