Пример #1
0
def bare_dict():
    negations = set(json.load(open(os.path.join(DATA_DIR, 'negations.json'))))

    with open(os.path.join(DATA_DIR, "degrees.json")) as f:
        degrees = json.load(f)

    with open(os.path.join(DATA_DIR, 'pos.txt')) as f:
        pos_emotion = set([x.strip() for x in f.readlines()])

    with open(os.path.join(DATA_DIR, 'neg.txt')) as f:
        neg_emotion = set([x.strip() for x in f.readlines()])

    # with open(os.path.join(DATA_DIR, 'pos_eva.txt')) as f:
    #     pos_envalute = set([x.strip() for x in f.readlines()])

    # with open(os.path.join(DATA_DIR, 'neg_eva.txt')) as f:
    #     neg_envalute = set([x.strip() for x in f.readlines()])
    # places = os.path.join(os.path.dirname(__file__), "../dictionaries/places.txt")
    # tokenizer.load_userdict(places)

    # with open(os.path.join(DATA_DIR, 'pos_sentence.txt')) as f1,\
    #         open(os.path.join(DATA_DIR, 'neg_sentence.txt')) as f2:
    #     s1 = set([x.strip() for x in f1.readlines()])
    #     s2 = set([x.strip() for x in f2.readlines()])
    #     pos_emotion.union(s1)
    #     neg_emotion.union(s2)
    pos_neg = pos_emotion.union(neg_emotion)
    # pos_neg_eva = pos_envalute.union(neg_envalute)
    tokenizer.load_userdict(pos_neg)
Пример #2
0
def main():

    jieba_instance = Tokenizer()
    seg_list = jieba_instance.cut("我来到北京清华大学", cut_all=True)
    print(type(seg_list))
    print("Full Mode: " + "/ ".join(seg_list))  # 全模式

    seg_list = jieba_instance.cut("他来到了网易杭研大厦")  # 默认是精确模式
    print(", ".join(seg_list))

    seg_list = jieba_instance.cut_for_search(
        "小明硕士毕业于中国科学院计算所,后在日本京都大学深造")  # 搜索引擎模式
    print(", ".join(seg_list))

    t1 = datetime.datetime.now()
    initialize()
    t2 = datetime.datetime.now()
    print("initialize costs:%s" % (t2 - t1))

    print(lcut("我来到北京清华大学"))
    print(list(cut("我来到北京清华大学")))
    print(cut("我来到北京清华大学", cut_all=True))
    print(lcut_for_search("我来到北京清华大学"))
    print(list(cut_for_search("我来到北京清华大学")))

    print(pseg.lcut("我来到北京清华大学"))
    print(list(pseg.cut("我来到北京清华大学")))

    s = "此外,公司拟对全资子公司吉林欧亚置业有限公司增资4.3亿元,增资后,吉林欧亚置业注册资本由7000万元增加到5亿元。吉林欧亚置业主要经营范围为房地产开发及百货零售等业务。目前在建吉林欧亚城市商业综合体项目。2013年,实现营业收入0万元,实现净利润-139.13万元。"
    r = analyse.extract_tags(s)
    print(r)

    r = analyse.textrank(s, withWeight=True)
    print(r)

    tr = TextRank(jieba_instance)
    print(tr.textrank(s, topK=2, withWeight=True))

    tf = TFIDF(jieba_instance)
    print(tf.extract_tags(s, topK=10))

    result = jieba_instance.tokenize('永和服装饰品有限公司')
    for tk in result:
        print("word %s\t\t start: %d \t\t end:%d" % (tk[0], tk[1], tk[2]))

    print(tokenize('永和服装饰品有限公司', mode="search"))

    jieba_instance.load_userdict(["卧槽"])

    load_userdict(set(["卧槽"]))
Пример #3
0
 def accept_set_as_arg(self):
     jieba.load_userdict(set([]))
Пример #4
0
 def accept_list_as_arg(self):
     jieba.load_userdict([])
Пример #5
0
 def accept_string_as_arg(self):
     jieba.load_userdict("")