def add_skos_hierarachy(self, parent_uri, child_uri): """ Add a hiearchy assertion for linked entities """ try: parent = LinkEntity.objects.get(uri=parent_uri) except LinkEntity.DoesNotExist: parent = False try: child = LinkEntity.objects.get(uri=child_uri) except LinkEntity.DoesNotExist: child = False if parent is not False and child is not False: lr = LinkRecursion() exiting_parents = lr.get_entity_parents(child_uri) if len(exiting_parents) >= 1: print('Child has parents: ' + str(exiting_parents)) else: # child is not already in a hieararchy, ok to put it in one la = LinkAnnotation() la.subject = child.uri # the subordinate is the subject la.subject_type = 'uri' la.project_uuid = self.project_uuid la.source_id = self.source_id + '-hierarchy' la.predicate_uri = self.PRED_SBJ_IS_SUB_OF_OBJ la.object_uri = parent.uri # the parent is the object la.save() print('Made: ' + child.uri + ' child of: ' + parent.uri) else: print('Cannot find parent or child')
def get_new_hierarchic_types(self, revision_date): """ Gets a list of types items revised after a date with the default delimiter for hierachy, but no superior concept """ rdate = datetime.strptime(revision_date, '%Y-%m-%d') new_hierarchic_list = [] hi_types = Manifest.objects.filter(item_type='types', label__contains=self.HIERARCHY_DELIM, revised__gte=rdate) if(len(hi_types) > 0): for hi_type in hi_types: lr = LinkRecursion() lr.get_entity_parents(hi_type.uuid) if(len(lr.parent_entities) < 1): # no superior parents found new_hierarchic_list.append(hi_type) return new_hierarchic_list
def get_new_hierarchic_types(self, revision_date): """ Gets a list of types items revised after a date with the default delimiter for hierachy, but no superior concept """ rdate = datetime.strptime(revision_date, '%Y-%m-%d') new_hierarchic_list = [] hi_types = Manifest.objects.filter( item_type='types', label__contains=self.HIERARCHY_DELIM, revised__gte=rdate) if (len(hi_types) > 0): for hi_type in hi_types: lr = LinkRecursion() lr.get_entity_parents(hi_type.uuid) if (len(lr.parent_entities) < 1): # no superior parents found new_hierarchic_list.append(hi_type) return new_hierarchic_list