def import_android_doc_website_for_method(): method_id_list = get_android_method_data() if method_id_list is not None and len(method_id_list) > 0: for method_id in method_id_list: api_entity = APIEntity.find_by_id(session, method_id) if api_entity is not None: url = construct_android_method_url(api_entity) if url is not None and url is not "": api_document_website = APIDocumentWebsite(api_entity.id, url) api_document_website.find_or_create(session, autocommit=False) session.commit()
def import_android_doc_website_for_package(): package_id_list = get_android_package_data() if package_id_list is not None and len(package_id_list) > 0: for package_id in package_id_list: api_entity = APIEntity.find_by_id(session, package_id) url = construct_android_package_url(api_entity) print url if api_entity is not None and url is not "": api_document_website = APIDocumentWebsite(api_entity.id, url) print api_document_website api_document_website.find_or_create(session=session, autocommit=False) session.commit()
def import_android_doc_website_for_class(): class_id_list = get_android_class_data() if class_id_list is not None and len(class_id_list) > 0: for class_id in class_id_list: api_entity = APIEntity.find_by_id(session, class_id) if api_entity is not None: url = construct_android_class_ur(api_entity) if url is not None and url != "": api_document_website = APIDocumentWebsite( api_entity.id, url) api_document_website.find_or_create(session, autocommit=False) session.commit()
def construct_android_method_url(api_entity): url = "" if api_entity is not None: class_id = APIRelation.get_end_id_by_start_id_and_relation_type(session, api_entity.id, APIRelation.RELATION_TYPE_BELONG_TO)[0] qualified_method_name = api_entity.qualified_name if class_id is not None and qualified_method_name is not None: class_document_website_list = APIDocumentWebsite.get_document_website_list_by_api_id(session, class_id) class_document_website = "" if class_document_website_list is not None: for each in class_document_website_list: print "-----------------------------" print each[0] website = each[0] if "https://developer.android.com/reference/" in website: class_document_website = website break parent = APIEntity.find_by_id(session, class_id) qualified_class_name = parent.qualified_name method_name = qualified_method_name.replace(qualified_class_name, "", 1) method_name = method_name[1:] if "," in method_name: method_name = method_name.replace(",", ",%20") url = class_document_website + "#" + method_name print url return url
def import_all_jdk_method_doc_website_relation(): # with open("url.txt", 'w') as f: id_list = get_data_id_list() for each in id_list: print "start_row_id: ", each[0], ", end_row_id: ", each[1] sql = "select * from api_doc.jdk_method where method_id = " + str( each[0]) cur.execute(sql) method_data = cur.fetchone() method_name, class_website = get_properties_from_jdk_method( method_data) qualified_name, full_declaration = get_property_from_api_entity( each[1]) url = create_doc_website_relation(method_name, full_declaration, qualified_name, class_website) if url is not None: api_document_website = APIDocumentWebsite(each[1], url) api_document_website.find_or_create(session, autocommit=False) # f.write(url) # f.write("\n") session.commit()
def start_import(self, graphClient): self.logger = Logger(self.logger_file_name).get_log() if not self.session: self.session = EngineFactory.create_session() self.graphClient = graphClient all_apis = self.session.query(APIEntity).all() for api_entity in all_apis: api_id = api_entity.id api_document_website_list = APIDocumentWebsite.get_document_website_list_by_api_id( self.session, api_id) self.import_document_website_to_one_entity( api_id, api_document_website_list) print("import api doc url complete")
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 create_doc_website_relation(old_class_id, doc_website): if doc_website is None: logger.error("no doc_website for %d", old_class_id) return None new_class_api_entity_id = KnowledgeTableRowMapRecord.get_end_row_id(session=session, start_knowledge_table=jdk_class_knowledge_table, end_knowledge_table=api_knowledge_table, start_row_id=old_class_id) if new_class_api_entity_id is None: logger.error("no new_class_api_entity_id for %d", old_class_id) return None relation = APIDocumentWebsite(new_class_api_entity_id, doc_website) logger.info("API %d : %s", new_class_api_entity_id, doc_website) return relation