def make_dinaa_link_assertions(self): """ makes assertions to relate DINAA URIs with federal registry documents """ self.make_fed_reg_vocab_entity() fed_api = FederalRegistryAPI() search_key_list = fed_api.get_list_cached_keyword_searches() dinaa_matches = fed_api.get_dict_from_file(self.dinaa_matches_key) for s_key in search_key_list: s_json = fed_api.get_dict_from_file(s_key) if 'results' in s_json: for match in dinaa_matches: for s_result in s_json['results']: if s_result['document_number'] == match['doc']: print('Found match for ' + match['doc']) man_obj = False try: man_obj = Manifest.objects.get( uuid=match['uuid']) except Manifest.DoesNotExist: man_obj = False if man_obj is not False: fed_uri = s_result['html_url'] le_check = False try: le_check = LinkEntity.objects.get( uri=fed_uri) except LinkEntity.DoesNotExist: le_check = False if le_check is False: print('Saving entity: ' + s_result['title']) title = s_result['title'] if len(title) > 175: title = title[0:175] + '...' le = LinkEntity() le.uri = fed_uri le.label = title le.alt_label = s_result['document_number'] le.vocab_uri = self.FEDERAL_REG_URI le.ent_type = 'instance' le.slug = 'fed-reg-docs-' + s_result[ 'document_number'] le.save() # Now save the link annotation print('Adding ref link to ' + man_obj.label) la = LinkAnnotation() la.subject = man_obj.uuid la.subject_type = man_obj.item_type la.project_uuid = man_obj.project_uuid la.source_id = self.source_id la.predicate_uri = self.DC_TERMS_REF_BY la.object_uri = fed_uri try: la.save() except: pass
def make_dinaa_link_assertions(self): """ makes assertions to relate DINAA URIs with federal registry documents """ self.make_fed_reg_vocab_entity() fed_api = FederalRegistryAPI() search_key_list = fed_api.get_list_cached_keyword_searches() dinaa_matches = fed_api.get_dict_from_file(self.dinaa_matches_key) for s_key in search_key_list: s_json = fed_api.get_dict_from_file(s_key) if 'results' in s_json: for match in dinaa_matches: for s_result in s_json['results']: if s_result['document_number'] == match['doc']: print('Found match for ' + match['doc']) man_obj = False try: man_obj = Manifest.objects.get(uuid=match['uuid']) except Manifest.DoesNotExist: man_obj = False if man_obj is not False: fed_uri = s_result['html_url'] le_check = False try: le_check = LinkEntity.objects.get(uri=fed_uri) except LinkEntity.DoesNotExist: le_check = False if le_check is False: print('Saving entity: ' + s_result['title']) title = s_result['title'] if len(title) > 175: title = title[0:175] + '...' le = LinkEntity() le.uri = fed_uri le.label = title le.alt_label = s_result['document_number'] le.vocab_uri = self.FEDERAL_REG_URI le.ent_type = 'instance' le.slug = 'fed-reg-docs-' + s_result['document_number'] le.save() # Now save the link annotation print('Adding ref link to ' + man_obj.label) la = LinkAnnotation() la.subject = man_obj.uuid la.subject_type = man_obj.item_type la.project_uuid = man_obj.project_uuid la.source_id = self.source_id la.predicate_uri = self.DC_TERMS_REF_BY la.object_uri = fed_uri try: la.save() except: pass
def make_fed_reg_vocab_entity(self): """ makes a vocabulary entity for the federal registry """ try: le_check = LinkEntity.objects.get(uri=self.FEDERAL_REG_URI) except LinkEntity.DoesNotExist: le_check = False if le_check is False: le = LinkEntity() le.uri = self.FEDERAL_REG_URI le.label = self.FEDERAL_REG_LABEL le.alt_label = self.FEDERAL_REG_LABEL le.vocab_uri = self.FEDERAL_REG_URI le.ent_type = 'vocabulary' le.slug = 'fed-reg' le.save()
def make_fed_reg_vocab_entity(self): """ makes a vocabulary entity for the federal registry """ try: le_check = LinkEntity.objects.get(uri=self.FEDERAL_REG_URI) except LinkEntity.DoesNotExist: le_check = False if le_check is False: le = LinkEntity() le.uri = self.FEDERAL_REG_URI le.label = self.FEDERAL_REG_LABEL le.alt_label = self.FEDERAL_REG_LABEL le.vocab_uri = self.FEDERAL_REG_URI le.ent_type = 'vocabulary' le.slug = 'fed-reg' le.save()