コード例 #1
0
def import_parameter_has_parameter_relation(cur, session):
    parameter_data_from_knowledgegraph = read_parameter_data_from_knowledgegraph(
        cur)
    for each in parameter_data_from_knowledgegraph:
        method_id = each[0]
        full_declaration = each[2]
        simple_parameter_list = get_simple_parameter_list(full_declaration)
        if simple_parameter_list is not None:
            for i in range(0, len(simple_parameter_list)):
                simple_parameter_list[i] = simple_parameter_list[i].replace(
                    "[]", "").replace("...", "").strip()
                parameter_entity = APIEntity.find_by_full_declaration_and_description(
                    session, simple_parameter_list[i], None)
                api_knowledge_table = KnowledgeTableFactory.get_api_entity_table(
                    session)
                android_method_table = KnowledgeTableFactory.get_android_method_table(
                    session)
                method_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(
                    session, android_method_table, api_knowledge_table,
                    method_id)
                if parameter_entity is not None and method_entity_id is not None:
                    api_relation_has_parameter = APIRelation(
                        method_entity_id, parameter_entity.id,
                        APIRelation.RELATION_TYPE_HAS_PARAMETER)
                    api_relation_has_parameter.find_or_create(session,
                                                              autocommit=False)
    session.commit()
コード例 #2
0
def import_jdk_parameter_relation(cur, session):
    parameter_data = read_parameter_data(cur)
    for each in parameter_data:
        if each is not None:
            name = each[0]
            method_id = each[1]
            type_string = each[2]
            description = each[3]
            type_class = each[4]
            full_declaration = type_string + " " + name
            description = clean_html_text(description)
            parameter_entity = APIEntity.find_by_full_declaration_and_description(session, full_declaration, description)
            jdk_method_knowledge_table = KnowledgeTableFactory.get_jdk_method_table(session)
            api_knowledge_table = KnowledgeTableFactory.get_api_entity_table(session)
            method_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(session, jdk_method_knowledge_table, api_knowledge_table, method_id)

            if parameter_entity is not None and method_entity_id is not None:
                end_api_id = parameter_entity.id
                api_relation_has_parameter = APIRelation(method_entity_id, end_api_id, APIRelation.RELATION_TYPE_HAS_PARAMETER)
                print("------------------------")
                print(api_relation_has_parameter)
                api_relation_has_parameter.find_or_create(session, autocommit=False)
            if type_class == 0:
                qualified_class_name = type_string
            else:
                qualified_class_name = get_qualified_class_name(type_class, cur)
            if qualified_class_name is not None and parameter_entity is not None:
                class_entity = APIEntity.find_by_qualifier(session, qualified_class_name)
                if class_entity is not None:
                    api_relation_has_type = APIRelation(parameter_entity.id, class_entity.id, APIRelation.RELATION_TYPE_PARAMETER_HAS_TYPE)
                    print("=============================")
                    print(api_relation_has_type)
                    api_relation_has_type.find_or_create(session, autocommit=False)
    session.commit()
コード例 #3
0
def import_android_exception_relation(cur, session):
    total = 0
    type1 = 0
    type2 = 0
    exception_data = read_exception_data(cur)
    for each in exception_data:
        total += 1
        exception_name = each[0]
        exception_text = each[1].replace("\n", '').replace(
            "           ",
            '').replace("     ", '').replace("  ", '').replace("   ", '')
        exception_entity = APIEntity.find_by_full_declaration_and_description(
            session, exception_name, exception_text)
        method_id = each[2]
        api_knowledge_table = KnowledgeTableFactory.get_api_entity_table(
            session)
        android_method_table = KnowledgeTableFactory.get_android_method_table(
            session)
        method_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(
            session, android_method_table, api_knowledge_table, method_id)
        exception_url = each[3]
        qualified_name_list = exception_url.replace(
            "https://developer.android.google.cn/reference/",
            '').replace(".html", "").split("/")
        qualified_name = ""
        for i in range(0, len(qualified_name_list)):
            if i == 0:
                qualified_name += qualified_name_list[i]
            else:
                qualified_name += ("." + qualified_name_list[i])
        print(qualified_name)
        exception_class = session.query(APIEntity).filter_by(
            qualified_name=qualified_name).first()

        if exception_entity is not None and method_entity_id is not None:
            api_relation_has_exception = APIRelation(
                method_entity_id, exception_entity.id,
                APIRelation.RELATION_TYPE_HAS_EXCEPTION)
            api_relation_has_exception.find_or_create(session,
                                                      autocommit=False)
            type1 += 1
        if exception_entity is not None and exception_class is not None:
            api_relation_has_type = APIRelation(
                exception_entity.id, exception_class.id,
                APIRelation.RELATION_TYPE_EXCEPTION_HAS_TYPE)
            api_relation_has_type.find_or_create(session, autocommit=False)
            type2 += 1
    session.commit()
    print(total)
    print(type1)
    print(type2)
コード例 #4
0
def import_parameter_has_type_relation(session):
    parameter_data_from_codehub = read_parameter_data_from_codehub(session)
    for each in parameter_data_from_codehub:
        # print(each.qualified_name)
        qualified_type = each.qualified_name.split(" ")[0]
        print(qualified_type)
        type_entity = APIEntity.find_by_qualifier(session, qualified_type)
        if type_entity is not None:
            # print(type_entity.id)
            api_relation_has_type = APIRelation(
                each.id, type_entity.id,
                APIRelation.RELATION_TYPE_PARAMETER_HAS_TYPE)
            api_relation_has_type.find_or_create(session, autocommit=False)
    session.commit()
コード例 #5
0
def import_jdk_return_value_relation(cur, session):
    return_value_data = read_return_value_data(cur)
    total = 0
    type1 = 0
    type2 = 0
    for each in return_value_data:
        total += 1
        method_id = each[0]
        full_declaration = each[1]
        return_type = each[2]
        return_string = each[3]
        return_type = process_return_type_string(return_type)
        qualified_name = construct_qualified_name_by_full_declaration(full_declaration, return_type)
        print("****************")
        print(method_id)
        print(return_type)
        print(full_declaration)
        print(qualified_name)
        if qualified_name is None:
            qualified_name = return_type
        return_string = clean_html_text(return_string)
        parameter_entity = APIEntity.find_by_full_declaration_and_description(session, return_type, return_string)

        jdk_method_knowledge_table = KnowledgeTableFactory.get_jdk_method_table(session)
        api_knowledge_table = KnowledgeTableFactory.get_api_entity_table(session)
        method_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(session, jdk_method_knowledge_table,
                                                                     api_knowledge_table, method_id)
        if parameter_entity is not None and method_entity_id is not None:
            end_api_id = parameter_entity.id
            api_relation_has_return_value = APIRelation(method_entity_id, end_api_id,
                                                        APIRelation.RELATION_TYPE_HAS_RETURN_VALUE)
            api_relation_has_return_value.find_or_create(session, autocommit=False)
            print("------------------------")
            print(api_relation_has_return_value)
            type1 += 1

        if qualified_name is not None and parameter_entity is not None:
            print("+++++++++++++++++++++")
            print(qualified_name)
            class_entity = APIEntity.find_by_qualifier(session, qualified_name)
            if class_entity is not None:
                api_relation_has_type = APIRelation(parameter_entity.id, class_entity.id,
                                                    APIRelation.RELATION_TYPE_RETURN_VALUE_HAS_TYPE)
                api_relation_has_type.find_or_create(session, autocommit=False)
                print("=============================")
                print(api_relation_has_type)
                type2 += 1
    session.commit()
    print("total: " + str(total) + ", type1: " + str(type1) + ", type2: " + str(type2))
def import_jdk_see_also_relation_for_method():
    see_also_data = get_see_also_data()
    # print see_also_data
    for each in see_also_data:
        see_also_website = each[0]
        original_method_id = each[1]
        end_api_id = APIDocumentWebsite.get_api_id_by_website(session, see_also_website)
        # print see_also_website, " ", end_api_id
        start_api_id = KnowledgeTableRowMapRecord.get_end_row_id(session, jdk_method_knowledge_table, api_knowledge_table, original_method_id)
        # print start_api_id
        if end_api_id is not None and start_api_id is not None:
            api_relation = APIRelation(start_api_id, end_api_id, APIRelation.RELATION_TYPE_SEE_ALSO)
            api_relation.find_or_create(session, autocommit=False)
            print original_method_id, "-------------------------------", api_relation
    session.commit()
def import_jdk_throw_exception_relation_for_method():
    jdk_exception_data = get_jdk_exception_data()
    for each in jdk_exception_data:
        exception_name = each[0]
        original_method_id = each[1]
        print exception_name, " ", original_method_id
        start_api_id = KnowledgeTableRowMapRecord.get_end_row_id(session, jdk_method_knowledge_table, api_knowledge_table, original_method_id)
        print "start_api_id: ", start_api_id
        original_exception_id = get_class_id_by_exception_name(exception_name)
        if original_exception_id is not None:
            end_api_id = KnowledgeTableRowMapRecord.get_end_row_id(session, jdk_class_knowledge_table, api_knowledge_table, original_exception_id)
            if end_api_id is not None and start_api_id is not None:
                api_relation = APIRelation(start_api_id, end_api_id, APIRelation.RELATION_TYPE_THROW_EXCEPTION)
                print original_method_id, "------------------------------", api_relation
                api_relation.find_or_create(session, autocommit=False)
    session.commit()
コード例 #8
0
def import_jdk_exception_relation(cur, session):
    jdk_exception_data = read_jdk_exception_data(cur)
    simple_exception_name_list = get_simple_exception_name_list(session)
    total = 0
    type1 = 0
    type2 = 0
    for each in jdk_exception_data:
        total += 1
        name = each[0]
        method_id = each[1]
        description = each[2]
        description = clean_html_text(description)
        exception_entity = APIEntity.find_by_full_declaration_and_description(
            session, name, description)
        jdk_method_knowledge_table = KnowledgeTableFactory.get_jdk_method_table(
            session)
        api_knowledge_table = KnowledgeTableFactory.get_api_entity_table(
            session)
        method_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(
            session, jdk_method_knowledge_table, api_knowledge_table,
            method_id)
        if exception_entity is not None and method_entity_id is not None:
            type1 += 1
            api_relation_has_exception = APIRelation(
                method_entity_id, exception_entity.id,
                APIRelation.RELATION_TYPE_HAS_EXCEPTION)
            api_relation_has_exception.find_or_create(session,
                                                      autocommit=False)
            print("------------------------")
            print(api_relation_has_exception)

        if exception_entity is not None and name is not None:
            type2 += 1
            exception_id = get_exception_id_by_simple_name(
                simple_exception_name_list, name)
            if exception_id is not None:
                api_relation_has_type = APIRelation(
                    exception_entity.id, exception_id,
                    APIRelation.RELATION_TYPE_EXCEPTION_HAS_TYPE)
                api_relation_has_type.find_or_create(session, autocommit=False)
                print("=============================")
                print(api_relation_has_type)
    session.commit()
    print("total: " + str(total) + ", type1: " + str(type1) + ", type2: " +
          str(type2))
def import_jdk_relation_value_relation_for_method():
    return_value_data = get_return_value_data()
    for each in return_value_data:
        original_method_id = each[0]
        full_declaration = each[1]
        return_type = each[2]
        start_api_id = KnowledgeTableRowMapRecord.get_end_row_id(session, jdk_method_knowledge_table, api_knowledge_table, original_method_id)
        qualified_name = construct_qualified_name_by_full_declaration(full_declaration, return_type)
        if start_api_id is not None and qualified_name is not None:
            print "-------------------------------------"
            print "start_api_id: ", start_api_id, ", qualified_name: ", qualified_name
            api_entity = APIEntity.find_by_qualifier(session, qualified_name)
            if api_entity is not None:
                end_api_id = api_entity.id
                print api_entity, " ", end_api_id
                api_relation = APIRelation(start_api_id, end_api_id, APIRelation.RELATION_TYPE_RETURN_VALUE)
                print api_relation
                api_relation.find_or_create(session, autocommit=False)
    session.commit()
def import_android_return_value_relation(cur, session):
    total = 0
    type1 = 0
    type2 = 0
    return_value_data = read_android_return_value_data(cur)
    for each in return_value_data:
        total += 1
        return_value_name = each[0]
        return_value_text = clean_html_text(each[1])
        method_id = each[2]
        return_value_url = each[3]
        return_value_entity = APIEntity.find_by_full_declaration_and_description(session, return_value_name, return_value_text)
        api_knowledge_table = KnowledgeTableFactory.get_api_entity_table(session)
        android_method_table = KnowledgeTableFactory.get_android_method_table(session)
        method_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(session, android_method_table, api_knowledge_table,
                                                                     method_id)
        qualified_name = ""
        if return_value_url != "":
            qualified_name_list = return_value_url.replace("https://developer.android.google.cn/reference/",
                                                           "").replace(".html", "").split("/")
            for i in range(0, len(qualified_name_list)):
                if i == 0:
                    qualified_name += qualified_name_list[i]
                else:
                    qualified_name += ("." + qualified_name_list[i])
        else:
            qualified_name = return_value_name
        return_value_class = session.query(APIEntity).filter_by(qualified_name=qualified_name).first()
        if return_value_entity is not None and method_entity_id is not None:
            type1 += 1
            api_relation_has_return_value = APIRelation(method_entity_id, return_value_entity.id, APIRelation.RELATION_TYPE_HAS_RETURN_VALUE)
            api_relation_has_return_value.find_or_create(session, autocommit=False)
        if return_value_entity is not None and return_value_class is not None:
            type2 += 1
            api_relation_has_type = APIRelation(return_value_entity.id, return_value_class.id, APIRelation.RELATION_TYPE_RETURN_VALUE_HAS_TYPE)
            api_relation_has_type.find_or_create(session, autocommit=False)
    session.commit()
    print(total)
    print(type1)
    print(type2)