Пример #1
0
def graph_sim_cal(src_graph_idx, current_tgt_graph_id, current_tgt_elem_info):
    src_graph = test_array[src_graph_idx]
    if 'activity' not in src_graph:
        src_graph = test_array[src_graph_idx - 1]
    src_activity = src_graph['activity']
    src_graph_elems = src_dict[src_activity].elements
    tar_graph_elems_candidate = tar_dict[current_tgt_graph_id].elements
    tar_graph_elems = []
    suffix = ''
    for i in range(len(tar_graph_elems_candidate)):
        this_elem_info = current_tgt_elem_info[current_tgt_graph_id][
            tar_graph_elems_candidate[i].id + '_' +
            tar_graph_elems_candidate[i].bounds]
        suffix += str(this_elem_info)
        if this_elem_info == 0:  # 0 means the element has not been matched
            tar_graph_elems.append(tar_graph_elems_candidate[i])
    if (src_graph_idx == 1 and current_tgt_graph_id
            == "com.yelp.android.ui.activities.ActivityCreateAccount2"):
        a = 1
    key = str(src_graph_idx) + "_" + str(current_tgt_graph_id) + '_' + suffix
    if key in cache:
        return cache[key]
    toDeleteElem = {
        "id": src_graph["resource-id"],
        "class": src_graph["class"]
    }
    src_graph_elems = deleteElem(src_graph_elems, toDeleteElem)
    v = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
    # o_sim, o_match = oracle_sim(src_graph_idx, current_tgt_graph_id)
    # v += o_sim
    cache[key] = v
    return v
Пример #2
0
def calculateGraphSim(test_idx, tar_id):
    test_node = test_array[test_idx]
    if 'activity' not in test_node:
        test_node = test_array[test_idx - 1]
    src_activity = test_node['activity']
    src_graph_elems = src_dict[src_activity].elements
    tar_graph_elems = tar_dict[tar_id].elements
    # key = src_activity + "_" + test_node["resource-id"] + "_" + tar_id
    key = src_activity + "_" + test_node["resource-id"] + "_" + tar_id
    # act = 0
    # edge = [1, 2, 3, 4, 5]
    # 0_1_0
    # 0_2_0
    # 0_3_0
    # 0_1_0

    #  key = str(test_idx)+' '+str(tar_id)
    if key in cache:
        return cache[key]
    toDeleteElem = {
        "id": test_node["resource-id"],
        "class": test_node["class"]
    }
    src_graph_elems = deleteElem(src_graph_elems, toDeleteElem)
    v = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
    cache[key] = v
    return v
Пример #3
0
def graph_sim_cal(src_graph_idx, current_tgt_graph_id, current_tgt_elem_info):
    # src_graph_idx -= 1
    src_graph_elems = src_elem_dicts_minus[src_graph_idx]
    tar_graph_elems_candidate = tar_dict[current_tgt_graph_id].elements
    tar_graph_elems = []
    suffix = ''
    for i in range(len(tar_graph_elems_candidate)):
        this_elem_info = current_tgt_elem_info[current_tgt_graph_id][
            tar_graph_elems_candidate[i].id + '_' +
            tar_graph_elems_candidate[i].bounds]
        suffix += str(this_elem_info)
        if this_elem_info == 0:  # 0 means the element has not been matched
            tar_graph_elems.append(tar_graph_elems_candidate[i])
    key = str(src_graph_idx) + "_" + str(current_tgt_graph_id) + '_' + suffix
    if key in cache:
        return cache[key]
    v = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
    o_sim = 0
    o_match = -1
    if src_graph_idx == len(test_array) - 1:
        o_sim, o_match = oracle_sim(src_graph_idx + 1, current_tgt_graph_id)
    else:
        o_sim, o_match = oracle_sim(src_graph_idx, current_tgt_graph_id)
    v += o_sim
    cache[key] = v
    return v
Пример #4
0
def calculateGraphSim(test_idx, tar_id):
    src_graph_elems = src_elem_dicts_minus[test_idx]
    tar_graph_elems = tar_dict[tar_id].elements
    key = str(test_idx) + "_" + str(tar_id)
    if key in cache:
        return cache[key]

    v = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
    cache[key] = v
    return v
Пример #5
0
def oracle_sim(src_graph_idx, tgt_graph_id):
    o_sim = 0
    last = src_graph_idx == len(test_array)
    first = True
    o_match = -1
    g_sim = 0
    if 1 <= src_graph_idx < len(test_array) - 1:
        if test_array[src_graph_idx - 1].__contains__('next'):
            oracle = test_array[src_graph_idx - 1]['next']
            o_gid = oracle['activity']
            if src_dict.__contains__(o_gid):
                src_graph_elems = src_dict[o_gid].elements
                tar_graph_elems = tar_dict[tgt_graph_id].elements
                g_sim = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
            # 1. checking the GUI element; 2. checking the non-GUI; todo: 3. checking the absence of  GUI / non-GUI
            if oracle['is_elem'] == 1:
                t_elems = tar_dict[tgt_graph_id].elements
                src_txt = oracle['text']
                src_cls = oracle['class']
                src_id = oracle['id']
                src_desc = oracle['desc']
                for t_e in t_elems:
                    tgt_txt = t_e.text
                    tgt_id = t_e.id
                    tgt_desc = t_e.desc
                    tgt_cls = t_e.cls
                    clsMatch = False
                    for key in StrUtil.CLASS_CATEGORY:
                        if key in src_cls.lower():
                            for cls in StrUtil.CLASS_CATEGORY[key]:
                                if cls in tgt_cls.lower():
                                    clsMatch = True
                                    break
                            if clsMatch:
                                break
                    contentScore = arraySim(StrUtil.tokenize("text", tgt_txt),
                                            StrUtil.tokenize("text", src_txt))
                    if tgt_txt.isnumeric() and src_txt.isnumeric():
                        contentScore = 1.0
                    idScore = arraySim(StrUtil.tokenize("resource-id", tgt_id),
                                       StrUtil.tokenize("resource-id", src_id))
                    descScore = arraySim(
                        StrUtil.tokenize("content-desc", tgt_desc),
                        StrUtil.tokenize("content-desc", src_desc))
                    v = contentScore + idScore + descScore  # + clsScore
                    v /= 3
                    if v > o_sim or first:
                        o_sim = v
                        o_match = t_e
                        first = False
    o_sim += g_sim
    return o_sim, o_match
Пример #6
0
def graph_sim_cal(src_graph_idx, current_tgt_graph_id, current_tgt_elem_info):
    src_graph_elems = src_elem_dicts_minus[src_graph_idx]
    tar_graph_elems_candidate = tar_dict[current_tgt_graph_id].elements
    tar_graph_elems = []
    suffix = ''
    for i in range(len(tar_graph_elems_candidate)):
        this_elem_info = current_tgt_elem_info[current_tgt_graph_id][
            tar_graph_elems_candidate[i].id + '_' +
            tar_graph_elems_candidate[i].bounds]
        suffix += str(this_elem_info)
        if this_elem_info == 0:  # 0 means the element has not been matched
            tar_graph_elems.append(tar_graph_elems_candidate[i])
    key = str(src_graph_idx) + "_" + str(current_tgt_graph_id) + '_' + suffix
    if key in cache:
        return cache[key]
    v = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
    cache[key] = v
    return v
Пример #7
0
def calculateGraphSim(test_idx, tar_id):
    test_node = test_array[test_idx]
    if 'activity' not in test_node:
        test_node = test_array[test_idx - 1]
    src_activity = test_node['activity']
    src_graph_elems = src_dict[src_activity].elements
    tar_graph_elems = tar_dict[tar_id].elements
    key = str(test_idx) + "_" + str(tar_id)
    if key in cache:
        return cache[key]
    for i in range(test_idx + 1):
        node = test_array[i]
        if 'activity' not in node:
            node = test_array[i - 1]
        toDeleteElem = {"id": node["resource-id"], "class": node["class"]}
        src_graph_elems = deleteElem(src_graph_elems, toDeleteElem)

    v = simCal.graphSim_TFIDF(src_graph_elems, tar_graph_elems)
    cache[key] = v
    return v