# coding=gbk
from Dict import TrAngle as dict1  # ֵ
import Character  # кֵб
from tqdm import tqdm  # 
from writenumDict import write_num_dict as dict2  # ʻֵ
from Dict import structure_dict as dict3  # ṹֵ
from Pronunciation import pronunciation_index

lst = Character.Symbol_lst()

file1 = open('D:/py/Shape.txt', 'w')


def get_similar(char1,char2):  # char1,char2Ϊ
    # ȡͺֱʻ
    code1 = dict1[char1]
    code2 = dict1[char2]
    write_num1 = int(dict2[char1])
    write_num2 = int(dict2[char2])
    structure1 = dict3.setdefault(char1, None)
    structure2 = dict3.setdefault(char2, None)

    # ṹƶ
    if structure1 and structure2 and structure1 == structure2:
        structure_index = 1
    else:
        structure_index = 0

    # ƶ
    code_index = 0
    # Ϊλ㣬ָͬ+1ͬΪ0,Ȩ4ټȨ
    for _i in range(4):
        if code1[_i] == code2[_i]:
            code_index += 1
    code_index /= 4

    # ӷƶ
    voice_index = pronunciation_index(char1,char2)

    # ʻƫķʽм
    write_num_index = 1- abs((write_num1 - write_num2)/max(write_num1,write_num2))
    # ȨءʻȨغͽṹȨطֱΪΪ 0.4 0.3 0.3
    write_index = code_index * 0.4 + write_num_index * 0.3 + structure_index * 0.3
    similarity_index_ = write_index * 0.5 + voice_index * 0.5

    return write_index,voice_index,similarity_index_


def main():
    print('νжд...')
    for i in tqdm(lst):
        file1.write(i+' ')
        for j in lst:
            if i == j:
                pass
            else:
                # һȨƶ㷨ݱʻ̶жϣĳһֵдļ
                write_index, voice_index, similarity_index = get_similar(i,j)
                if (voice_index == 1 and write_index >= 0.6) or write_index >= 0.9:
                    file1.write(j)
                elif similarity_index >= 0.85:
                    file1.write(j)
                else:
                    pass
        file1.write('\n')
    file1.close()

if __name__ == '__main__':
    main()

