Beispiel #1
0
def get_name_dat(path, names, stroke_list):
    with open('data/' + path + '.dat', encoding='utf-8') as f:
        line_list = f.readlines()
        size = len(line_list)
        progress = 0
        for i in range(0, size):
            # 生成进度
            if (i + 1) * 100 / size - progress >= 5:
                progress += 5
                print('>>正在生成名字...' + str(progress) + '%')
            data = line_list[i].split(',')
            if len(data[0]) == 2:
                name = data[0]
            else:
                name = data[0][1:]
            # 转繁体
            name = s2tConverter.convert(name)
            gender = data[1].replace('\n', '')
            if len(name) == 2:
                # 转换笔画数
                strokes = list()
                strokes.append(get_stroke_number(name[0]))
                strokes.append(get_stroke_number(name[1]))
                # 判断是否包含指定笔画数
                for stroke in stroke_list:
                    if stroke[0] == strokes[0] and stroke[1] == strokes[1]:
                        names.add(Name(name, '', gender))
Beispiel #2
0
def check_wuge_config(name):
    if len(name) != 3:
        return
    # 姓名转繁体
    converter = opencc.OpenCC('s2t.json')
    complex_name = converter.convert(name)
    xing = get_stroke_number(complex_name[0])
    ming1 = get_stroke_number(complex_name[1])
    ming2 = get_stroke_number(complex_name[2])
    # 天格
    tian = xing + 1
    # 人格
    ren = xing + ming1
    # 地格
    di = ming1 + ming2
    # 总格
    zong = xing + ming1 + ming2
    # 外格
    wai = zong - ren + 1
    # 三才配置
    sancai_config = get_sancai_config([tian, ren, di])
    # 输出结果
    print("\n")
    print(name + "\n")
    print(complex_name + " " + str(xing) + " " + str(ming1) + " " +
          str(ming2) + "\n")
    print("天格\t" + str(tian))
    print("人格\t" + str(ren) + "\t" + get_stroke_type(ren))
    print("地格\t" + str(di) + "\t" + get_stroke_type(di))
    print("总格\t" + str(zong) + "\t" + get_stroke_type(zong))
    print("外格\t" + str(wai) + "\t" + get_stroke_type(wai))
    print("\n三才\t" + sancai_config + "\t" + get_sancai_type(sancai_config) +
          "\n")
Beispiel #3
0
 def __init__(self, first_name, source, gender):
     self.stroke_number1 = get_stroke_number(first_name[0])
     self.stroke_number2 = get_stroke_number(first_name[1])
     self.count = len(first_name)
     self.source = source.replace(first_name[0], "「" + first_name[0] + "」") \
         .replace(first_name[1], "「" + first_name[1] + "」")
     self.gender = gender
     # 转回简体
     cc = OpenCC('t2s')
     self.first_name = cc.convert(first_name)
Beispiel #4
0
def get_stroke_list(last_name, allow_general):
    print(">>计算笔画组合...")
    # 姓氏转繁体
    converter = opencc.OpenCC('s2t.json')
    last_name = converter.convert(last_name)
    n = get_stroke_number(last_name)
    for i in range(1, 81):
        for j in range(1, 81):
            # 天格
            tian = n + 1
            # 人格
            ren = n + i
            # 地格
            di = i + j
            # 总格
            zong = n + i + j
            # 外格
            wai = zong - ren + 1

            if ren in stroke_goods and di in stroke_goods and zong in stroke_goods and wai in stroke_goods:
                if check_sancai_good([tian, ren, di], allow_general):
                    stroke_list.append([i, j])
            elif allow_general and \
                    (ren in stroke_goods or ren in stroke_generals) and \
                    (di in stroke_goods or di in stroke_generals) and \
                    (zong in stroke_goods or zong in stroke_generals) and \
                    (wai in stroke_goods or wai in stroke_generals):
                if check_sancai_good([tian, ren, di], allow_general):
                    stroke_list.append([i, j])
    print(">>" + str(stroke_list))
    return stroke_list
Beispiel #5
0
 def __init__(self, first_name, source, gender):
     self.first_name = first_name
     self.stroke_number = get_stroke_number(first_name)
     self.count = len(first_name)
     self.index = ""
     spell = lazy_pinyin(first_name)
     for word in spell:
         self.index += word
     self.source = source
     self.gender = gender
Beispiel #6
0
def check_and_add_names(names, string_list, stroke_list):
    for sentence in string_list:
        sentence = sentence.strip()
        # 转换笔画数
        strokes = list()
        for ch in sentence:
            if is_chinese(ch):
                strokes.append(get_stroke_number(ch))
            else:
                strokes.append(0)
        # 判断是否包含指定笔画数
        for stroke in stroke_list:
            if stroke[0] in strokes and stroke[1] in strokes:
                index0 = strokes.index(stroke[0])
                index1 = strokes.index(stroke[1])
                if index0 < index1:
                    name0 = sentence[index0]
                    name1 = sentence[index1]
                    names.add(Name(name0 + name1, sentence, ''))