Exemple #1
0
def Search(input):
    ResNodes = {x: 100 for x in range(1, 21)}
    SearchRes = []
    nodes = load2prog("./data.dat")

    for node in nodes:
        # 完全匹配搜索
        MatchTarget = [node.name, node.desc]
        for i in range(len(MatchTarget)):
            SelectRes = SelectAlogrithm(str(input), str(MatchTarget[i]))
            if SelectRes == 100:
                SelectRes = SelectAlogrithm(GetPinYin(input), GetPinYin(MatchTarget[i]))
                SelectRes += 1
            if i == 1 and SelectRes != 100:
                SelectRes += 2
            ResNodes[node.id] = min(ResNodes[node.id], SelectRes)

        input_word, input_pinyin = CutWord(input)
        desc_word, desc_pinyin = CutWord(node.desc)

        if (ResNodes[node.id] == 100):
            #  部分匹配搜索
            for word in input_word:
                for i in range(len(MatchTarget)):
                    ResNodes[node.id] = min(ResNodes[node.id], SelectAlogrithm(word, str(MatchTarget[i])))

        if (ResNodes[node.id] == 100):
            # 编辑距离搜索
            ResNodes[node.id] = max(ResNodes[node.id], Levenshtein(GetPinYin(input), GetPinYin(desc_word[0])) + 5)
            for word in desc_word:
                ResNodes[node.id] = min(ResNodes[node.id], Levenshtein(GetPinYin(input), GetPinYin(word)) + 5)

    ResNodesAftSort = sorted(ResNodes.items(), key=lambda item: item[1], reverse=False)
    for i in range(len(ResNodesAftSort)):
        SearchRes.append(GetNode(ResNodesAftSort[i][0]))
    return SearchRes
Exemple #2
0
from models import load2prog
nodes=load2prog("data.dat")
def DFS(node, AftNodeList):
    for Aft_node in node.aft_list:
        if(Aft_node not in AftNodeList):
            AftNodeList.append(Aft_node)
            DFS(Aft_node, AftNodeList)
def FindAft(node):
    AftNodeList = []
    DFS(node,AftNodeList)
    return AftNodeList
Exemple #3
0
from Search.search import Search
from models import load2prog

data = load2prog("./data.dat")
TestInput = ["数组", "书组", "素组", "线信表", "数"]
for input in TestInput:
    SearchRes = Search(input)
    print("输入内容为:" + input)
    print("结果为")
    for node in SearchRes:
        MatchTarget = [node.name, node.desc]
        for line in MatchTarget:
            print(line)
Exemple #4
0
from models import load2prog
from FindPreAft.FindPre import FindPre
from FindPreAft.FindAft import FindAft
nodes = load2prog("../data.dat")
AftNodes = FindAft(nodes[0])
PreNodes = FindPre(nodes[-1])
for Nodes in [AftNodes, PreNodes]:
    print("-----------------")
    for node in Nodes:
        print(node.name)
Exemple #5
0
def GetNode(id):
    nodes = load2prog("./data.dat")
    for node in nodes:
        if id == node.id:
            return node
Exemple #6
0
def Sort_by_level():
    nodes = models.load2prog('data.dat')
    sorted_nodes = QuickSort(nodes, cmp1)
    return sorted_nodes
Exemple #7
0
def Sort_by_time():
    nodes = models.load2prog('data.dat')
    sorted_nodes = QuickSort(nodes, cmp2)
    return sorted_nodes
Exemple #8
0
def Sort_by_similarity(node):
    nodes = models.load2prog('data.dat')
    edgs = models.To_Graph()
    dis = heap_Dijsktra(edgs, node.id - 1)
    sorted_nodes = QuickSort(nodes, cmp3, dis=dis)
    return sorted_nodes