Ejemplo n.º 1
0
def query_name_times(path):
    txt = of.read_file_txt(path)
    items = txt_cut(txt)
    while 1:
        num = eval(input("输入需要获得多少个出场次数最多的人物(3—8):"))
        if 3 <= num <= 8:
            for i in range(num):
                word, count = items[i]
                print("{0:<10}{1:>5}".format(word, count))
            break
        else:
            continue
Ejemplo n.º 2
0
def query_name(path):
    txt = of.read_file_txt(path)
    excludes = {"来到", "一个", "国王", "我们", "变成", "你们", "什么"}
    for ch in '!@#$%^&*()_+-=[]\{}|;:,./;:;:",。<>?':
        txt = txt.replace(ch, "")
    words = pseg.cut(txt)
    counts = {}
    for w in words:
        if len(w.word) == 1:
            continue
        if w.flag == 'nr':
            counts[w.word] = counts.get(w.word, 0) + 1
    keys_list = list(counts.keys())
    for word in excludes:
        if word in keys_list:
            del counts[word]
    items = list(counts.items())
    items.sort(key=lambda x: x[1], reverse=True)
    return items
Ejemplo n.º 3
0
def test_cut_sentence():
    txt = of.read_file_txt(path_xyj)
    sentence = standard.cut_sentence(txt)
    of.write_list(sentence, path_sentences)
Ejemplo n.º 4
0
def test_query_name_times_udf():
    txt = of.read_file_txt(path_xyj)
    items = pre.query_name_times_udf(path_rw, txt)
    for i in range(len(items)):
        word, count = items[i]
        print("{0:<10}{1:>5}".format(word, count))
Ejemplo n.º 5
0
def test_read_file_txt():
    print(of.read_file_txt(path_sent))