Пример #1
0
def comp(ins: dict, stu: dict) -> tuple and tuple:
    """
    Compare two concept_dict list of matched matched values of the dictionaries
    """
    ins_concept, extra_ins = concept(ins)
    stu_concept, extra_stu = concept(stu)
    res = []
    res_no_duplicates = []

    pes = []
    pes_no_duplicates = []
    for i in ins_concept:
        for j in stu_concept:
            if root.justify(str(i[0]), str(j[0])) and root.justify(
                    str(i[1]), str(j[1])):
                res.append(i)
    for i in ins_concept:
        for j in extra_stu:
            if root.justify(str(i[0]), str(j[0])) and root.justify(
                    str(i[1]), str(j[1])):
                pes.append(i)
    for i in res:
        if i not in res_no_duplicates:
            res_no_duplicates.append(i)
    for i in pes:
        if i not in pes_no_duplicates:
            pes_no_duplicates.append(i)

    return res_no_duplicates, pes_no_duplicates
Пример #2
0
def unmatched_value_advanced(instructor: list, student: list) -> list:
    """
    find the unmatched values from student and teacher list and append it to a list which is returned
    Natural Language Processing is Applied
    remove the block word from each element of the list and run all the synonyms to justify the match
    more leaner/stricter matching can be implemented by changing interaction between n, teacher, and student on root.isSame()
    """
    matched = []
    for i in set(student):
        for j in set(instructor):
            if root.justify(j, i):
                matched.append(j)
    unmatched_ins = set(instructor) - set(matched)
    unmatched_stu = set(student) - set(matched)

    u_m_i_c = unmatched_ins.copy()
    u_m_i_c.update(unmatched_stu)
    unmatched = list(u_m_i_c)
    unmatched_index = []
    ind = None
    for i in instructor:
        for j in unmatched:
            if i == j:
                ind = instructor.index(i)
                unmatched_index.append(ind)
    return unmatched_index
Пример #3
0
def get_index(lis: list, val: str) -> int:
    """
    return the index of value on a list
    """
    index = None
    for i, e in enumerate(lis):
        if root.justify(e, val):
            index = i
    return index
Пример #4
0
def get_list_from_key(dictionary: dict, k: str) -> list:
    """
    return the list of a list if the key if the key matched with any key of the dictionary
    """
    v = []
    for key, value in dictionary.items():
        if root.justify(key, k):
            v = value
    return v
Пример #5
0
def unmatched_key(instructor: list, student: list) -> list:
    """
    return the index+1 of a instructor list for any unmatched value and append it to a list
    """
    matched = []
    ind = []
    c = (set(student) - set(instructor))
    d = (set(instructor) - set(student))
    c.update(d)

    for i in set(student):
        for j in set(instructor):
            if root.justify(j, i):
                matched.append(j)
    unmatched_ins = set(instructor) - set(matched)
    unmatched_stu = set(student) - set(matched)
    for i in set(unmatched_ins):
        for index, s in enumerate(instructor):
            if root.justify(i, s):
                ind.append(index + 1)
    return ind
Пример #6
0
def matched_value_advanced(instructor: list, student: list) -> list:
    """
    find the matched values from student and teacher list and append it to a list which is returned
    Natural Language Processing is Applied
    remove the block word from each element of the list and run all the synonyms to justify the match
    more leaner matching can be implemented by changing interaction between n, teacher, and student on root.isSame()
    """
    matched = []
    for i in set(student):
        for j in set(instructor):
            if root.justify(i, j):
                matched.append(j)
    return matched
Пример #7
0
def find_match(dictionary_i: dict, lis: list) -> int:
    """
    Most important function of the module
    It compares the branches of dictionaries (branch of a instructor dictionary to the student dictionary)
    and return the matching key of the student dictionary
    """

    high = 0
    h_key = 0
    h_point = 0
    m_l = []
    i_l_l = []
    for key, value in dictionary_i.items():
        point = 0
        val = 0
        i_l_l = value
        s_l_l = lis
        m_l = matched_value_advanced(i_l_l, s_l_l)
        for i, e in enumerate(m_l):
            point += (len(i_l_l) - i_l_l.index(e))
            if point > h_point:
                h_point = point
        q = 0
        for i in range(len(i_l_l) - 1, -1, -1):
            if len(i_l_l) == len(lis):
                if root.justify(i_l_l[i], lis[i]):
                    q += 1
                    if q == len(i_l_l):
                        h_key = key
                    else:
                        val = len(m_l)
                        if val > high and h_point > point:
                            high = val
                            h_key = key
        val = len(m_l)
        if val > high and h_point > point:
            high = val
            h_key = key
        elif val > high:
            high = val
            h_key = key
    return h_key
Пример #8
0
def mismatched_key_list(instructor_directory: str or list, student_directory: str or list) -> list and float and float and float and int:
    """
    finds the unmatched key list from the instructor dictionary that were absent in student dictionary
    """
    list_i = []
    list_s = []
    rt = []

    dict_key_i = {}
    dict_lf_i = {}
    dict_concept_i = {}
    dict_node_linking_i = {}

    dict_key_s = {}
    dict_lf_s = {}
    dict_concept_s = {}
    dict_node_linking_s = {}


    if isinstance(instructor_directory, str):
        dict_key_i = xmlParsing.process_key(instructor_directory)
        dict_concept_i = xmlParsing.node(instructor_directory)
        dict_lf_i = xmlParsing.lf(instructor_directory)
        dict_node_linking_i.update(dict_concept_i)
        dict_node_linking_i.update(dict_lf_i)
    elif isinstance(instructor_directory, list):
        dict_key_i = xmlParsing.process_key_many(instructor_directory)
        dict_concept_i = xmlParsing.node_multiple(instructor_directory)
        dict_lf_i = xmlParsing.lf_multiple(instructor_directory)
        dict_node_linking_i.update(dict_concept_i)
        dict_node_linking_i.update(dict_lf_i)
    if isinstance(student_directory, str):
        dict_key_s = xmlParsing.process_key(student_directory)
        dict_concept_s = xmlParsing.node(student_directory)
        dict_lf_s = xmlParsing.lf(student_directory)
        dict_node_linking_s.update(dict_concept_s)
        dict_node_linking_s.update(dict_lf_s)
    elif isinstance(student_directory, list):
        dict_key_s = xmlParsing.process_key_many(student_directory)
        dict_concept_s = xmlParsing.node_multiple(student_directory)
        dict_lf_s = xmlParsing.lf_multiple(student_directory)
        dict_node_linking_s.update(dict_concept_s)
        dict_node_linking_s.update(dict_lf_s)
    num_i_node = len(dict_concept_i) + len(dict_concept_s) + len(dict_lf_i) + len(dict_lf_s)

    for key, value in dict_node_linking_i.items():
        if value not in list_i:
            list_i.append(value)
    for key, value in dict_node_linking_s.items():
        if value not in list_s:
            list_s.append(value)
    for value_i in list_i:
        for value_s in list_s:
            if (root.justify(value_i, value_s)):
                rt.append(value_i)
    num_node = 0
    num_lf = 0
    num_node_list = []
    num_lf_list = []

    for i in rt:
        if get_key_any(instructor_directory,i) in dict_concept_i:
            if get_key_any(instructor_directory,i) not in num_node_list:
                num_node_list.append(get_key_any(instructor_directory,i))
                num_node+=1
        if get_key_any(instructor_directory,i) in dict_lf_i:
            if get_key_any(instructor_directory, i) not in num_lf_list:
                num_lf_list.append(get_key_any(instructor_directory, i))
                num_lf+=1
    per_node = round((num_node/len(delete_duplicate(dict_concept_i)))*100,2)
    per_lf = round((num_lf / len(delete_duplicate(dict_lf_i)))*100,2)

    ###
    per_avg = round(((num_node+num_lf)/(len(delete_duplicate(dict_concept_i))+len(delete_duplicate(dict_lf_i))))*100,2)

    result = []
    for i in list_i:
        if i not in rt:
                if i not in result:
                    result.append(i)
    result_final = []
    for i in result:
        result_final.append(get_key_any(instructor_directory,i))
    return result_final, per_node, per_lf, per_avg, num_i_node