def create_item(self, login): statements = [ PBB_Core.WDExternalID(value=self.id, prop_nr=INTERPRO, references=[self.reference]), PBB_Core.WDItemID(value=self.type_wdid, prop_nr="P279", references=[self.reference]) ] wd_item = PBB_Core.WDItemEngine( item_name=self.name, domain='interpro', data=statements, append_value=["P279"], fast_run=True, fast_run_base_filter=IPRTerm.fast_run_base_filter) wd_item.set_label(self.name, lang='en') for lang, description in self.lang_descr.items(): wd_item.set_description(description, lang=lang) wd_item.set_aliases([self.short_name, self.id]) PBB_Helpers.try_write(wd_item, self.id, INTERPRO, login) return wd_item
def create_relationships(self, ipr_wd): # ipr_wd is a dict ipr ID to wikidata ID mapping statements = [ PBB_Core.WDExternalID(value=self.id, prop_nr=INTERPRO, references=[self.reference]) ] if self.parent: statements.append( PBB_Core.WDItemID(value=ipr_wd[self.parent], prop_nr='P279', references=[self.reference])) # subclass of if self.contains: for c in self.contains: statements.append( PBB_Core.WDItemID(value=ipr_wd[c], prop_nr='P527', references=[self.reference])) # has part if self.found_in: for f in self.found_in: statements.append( PBB_Core.WDItemID(value=ipr_wd[f], prop_nr='P361', references=[self.reference])) # part of if len(statements) == 1: return # write data item = PBB_Core.WDItemEngine(item_name=self.name, domain='interpro', data=statements, server=SERVER, append_value=["P279", "P527", "P361"]) try: item.write(self.login) except WDApiError as e: print(e) PBB_Core.WDItemEngine.log( 'ERROR', '{main_data_id}, "{exception_type}", "{message}", {wd_id}, {duration}' .format(main_data_id=self.id, exception_type=type(e), message=e.__str__(), wd_id=self.wd_item_id, duration=datetime.now())) return PBB_Core.WDItemEngine.log( 'INFO', '{main_data_id}, "{exception_type}", "{message}", {wd_id}, {duration}' .format(main_data_id=self.id, exception_type='', message='created interpro relationships: {}'.format([ (x.prop_nr, x.value) for x in statements ]), wd_id=item.wd_item_id, duration=datetime.now()))
def create_relationships(self, login): try: # endpoint may not get updated in time? self.do_wdid_lookup() except KeyError as e: PBB_Core.WDItemEngine.log( "ERROR", format_msg(self.id, INTERPRO, None, str(e), type(e))) return statements = [ PBB_Core.WDExternalID(value=self.id, prop_nr=INTERPRO, references=[self.reference]) ] if self.parent: # subclass of statements.append( PBB_Core.WDItemID(value=self.parent_wdid, prop_nr='P279', references=[self.reference])) if self.contains: for c in self.contains_wdid: statements.append( PBB_Core.WDItemID(value=c, prop_nr='P527', references=[self.reference])) # has part if self.found_in: for f in self.found_in_wdid: statements.append( PBB_Core.WDItemID(value=f, prop_nr='P361', references=[self.reference])) # part of if len(statements) == 1: return wd_item = PBB_Core.WDItemEngine( wd_item_id=self.wdid, domain='interpro', data=statements, append_value=['P279', 'P527', 'P361'], fast_run=True, fast_run_base_filter=IPRTerm.fast_run_base_filter) PBB_Helpers.try_write( wd_item, self.id, INTERPRO, login, edit_summary="create/update subclass/has part/part of")
def do_umls_statement(self, doid, umls_list, dry_run=False): statements = [] for umls in umls_list: statements.append(PBB_Core.WDExternalID(value=umls, prop_nr=self.UMLS_PROP, references=[self.reference])) wd_item = PBB_Core.WDItemEngine(wd_item_id=self.DOID2WD[doid], domain='disease', data=statements, append_value=[self.UMLS_PROP], fast_run=True, fast_run_base_filter=self.fast_run_base_filter) # no item creation should be done if wd_item.create_new_item: raise ValueError("something bad happpened") if dry_run: if wd_item.require_write: info_logger.info(" ".join(["item_updated", doid, wd_item.wd_item_id])) if wd_item.require_write and not dry_run: self.try_write(wd_item, doid)
def create_item(self): statements = [ PBB_Core.WDExternalID(value=self.id, prop_nr=INTERPRO, references=[self.reference]), PBB_Core.WDItemID(value=IPRItem.type2subclass[self.type], prop_nr="P279", references=[self.reference]) ] item = PBB_Core.WDItemEngine(item_name=self.name, domain='interpro', data=statements, server=SERVER) item.set_label(self.name) for lang, description in self.description.items(): item.set_description(description, lang=lang) item.set_aliases([self.short_name, self.id]) try: item.write(login=self.login) except WDApiError as e: print(e) PBB_Core.WDItemEngine.log( 'ERROR', '{main_data_id}, "{exception_type}", "{message}", {wd_id}, {duration}' .format(main_data_id=self.id, exception_type=type(e), message=e.__str__(), wd_id=self.wd_item_id, duration=datetime.now())) return self.wd_item_id = item.wd_item_id PBB_Core.WDItemEngine.log( 'INFO', '{main_data_id}, "{exception_type}", "{message}", {wd_id}, {duration}' .format(main_data_id=self.id, exception_type='', message='created/updated interpro item', wd_id=item.wd_item_id, duration=datetime.now()))