Exemplo n.º 1
0
 def reconcile_predicate_var(self, des_field_obj):
     """ reconciles a predicate variable from the Import Field
     """
     output = False
     self.setup_field(des_field_obj)
     if len(self.label) > 0:
         output = True
         pm = PredicateManagement()
         pm.project_uuid = self.project_uuid
         pm.source_id = self.source_id
         pm.sort = self.sort
         predicate = pm.get_make_predicate(self.label,
                                           'variable',
                                           self.data_type)
         self.uuid = predicate.uuid
         self.predicate = predicate
         if predicate.uuid != self.candidate_uuid:
             if self.des_import_cell is False:
                 # update the reconcilted UUID with for the import field object
                 des_field_obj.f_uuid = self.uuid
                 des_field_obj.save()
             else:
                 # update the reconcilted UUID for import cells with same rec_hash
                 up_cells = ImportCell.objects\
                                      .filter(source_id=self.source_id,
                                              field_num=self.des_import_cell.field_num,
                                              rec_hash=self.des_import_cell.rec_hash)
                 for up_cell in up_cells:
                     # save each cell with the correct UUID
                     up_cell.fl_uuid = self.uuid
                     up_cell.uuids_save()
     return output
Exemplo n.º 2
0
 def make_reconcile_link_pred(self, label):
     """ Makes a linking predicate from a given predicate label """
     self.label = label
     pm = PredicateManagement()
     pm.project_uuid = self.project_uuid
     pm.source_id = self.source_id
     pm.data_type = self.data_type
     pm.sort = self.sort
     pm.get_make_predicate(label, self.class_uri, self.data_type)
     self.uuid = pm.predicate.uuid
Exemplo n.º 3
0
 def make_reconcile_link_pred(self, label):
     """ Makes a linking predicate from a given predicate label """
     self.label = label
     pm = PredicateManagement()
     pm.project_uuid = self.project_uuid
     pm.source_id = self.source_id
     pm.data_type = self.data_type
     pm.sort = self.sort
     pm.get_make_predicate(label,
                           self.class_uri,
                           self.data_type)
     self.uuid = pm.predicate.uuid
Exemplo n.º 4
0
 def create_pred_parents(self, new_hierachic_list):
     """ Creates new types for
     superior (more general) types from a list
     of types that have hiearchies implicit in their labels
     once the superior types are created,
     linked data annotations noting hierarchy are stored
     """
     parent_children_pairs = []
     for manifest in new_hierachic_list:
         try:
             oc_pred = Predicate.objects.get(uuid=manifest.uuid)
         except Predicate.DoesNotExist:
             oc_pred = False
         if (oc_pred is not False):
             child_parts = manifest.label.split(self.HIERARCHY_DELIM)
             act_delim = ''
             act_new_label = ''
             current_parent = False
             for label_part in child_parts:
                 act_new_label = act_new_label + act_delim + label_part
                 act_delim = self.HIERARCHY_DELIM
                 pred_manage = PredicateManagement()
                 pred_manage.project_uuid = manifest.project_uuid
                 pred_manage.source_id = self.source_id
                 pred_manage.sort = oc_pred.sort
                 pred_manage.data_type = oc_pred.data_type
                 ppred = pred_manage.get_make_predicate(
                     act_new_label, manifest.class_uri)
                 if (ppred is not False and current_parent is not False):
                     parent_child = {
                         'parent': current_parent,
                         'child': ppred.uuid
                     }
                     parent_children_pairs.append(parent_child)
                 current_parent = ppred.uuid
             if (len(parent_children_pairs) > 0):
                 # now make some linked data annotations
                 for parent_child in parent_children_pairs:
                     if (parent_child['parent'] is not False):
                         new_la = LinkAnnotation()
                         new_la.subject = parent_child['child']
                         new_la.subject_type = 'predicates'
                         new_la.project_uuid = manifest.project_uuid
                         new_la.source_id = self.source_id
                         new_la.predicate_uri = self.p_for_superobjs
                         new_la.object_uri = URImanagement.make_oc_uri(
                             parent_child['parent'], 'predicates')
                         new_la.creator_uuid = ''
                         new_la.save()
     return parent_children_pairs
Exemplo n.º 5
0
 def create_pred_parents(self, new_hierachic_list):
     """ Creates new types for
     superior (more general) types from a list
     of types that have hiearchies implicit in their labels
     once the superior types are created,
     linked data annotations noting hierarchy are stored
     """
     parent_children_pairs = []
     for manifest in new_hierachic_list:
         try:
             oc_pred = Predicate.objects.get(uuid=manifest.uuid)
         except Predicate.DoesNotExist:
             oc_pred = False
         if oc_pred is not False:
             child_parts = manifest.label.split(self.HIERARCHY_DELIM)
             act_delim = ""
             act_new_label = ""
             current_parent = False
             for label_part in child_parts:
                 act_new_label = act_new_label + act_delim + label_part
                 act_delim = self.HIERARCHY_DELIM
                 pred_manage = PredicateManagement()
                 pred_manage.project_uuid = manifest.project_uuid
                 pred_manage.source_id = self.source_id
                 pred_manage.sort = oc_pred.sort
                 pred_manage.data_type = oc_pred.data_type
                 ppred = pred_manage.get_make_predicate(act_new_label, manifest.class_uri)
                 if ppred is not False and current_parent is not False:
                     parent_child = {"parent": current_parent, "child": ppred.uuid}
                     parent_children_pairs.append(parent_child)
                 current_parent = ppred.uuid
             if len(parent_children_pairs) > 0:
                 # now make some linked data annotations
                 for parent_child in parent_children_pairs:
                     if parent_child["parent"] is not False:
                         new_la = LinkAnnotation()
                         new_la.subject = parent_child["child"]
                         new_la.subject_type = "predicates"
                         new_la.project_uuid = manifest.project_uuid
                         new_la.source_id = self.source_id
                         new_la.predicate_uri = self.p_for_superobjs
                         new_la.object_uri = URImanagement.make_oc_uri(parent_child["parent"], "predicates")
                         new_la.creator_uuid = ""
                         new_la.save()
     return parent_children_pairs
Exemplo n.º 6
0
 def make_datatype_wrong_assertion(self, predicate_uuid, content):
     """ Makes an assertion for records that don't fit the
         expected data_type / object_type
     """
     pm = PredicateManagement()
     pm.project_uuid = self.project_uuid
     pm.source_id = self.source_id
     pm.sort = self.sort
     new_note_predicate = pm.get_make_related_note_predicate(predicate_uuid, ' (Note)')
     if new_note_predicate is not False:
         note_pred_uuid = new_note_predicate.uuid
         # save a skos:related assertion linking the old and new predicates
         ptm = PredicateTypeAssertions()
         ptm.skos_relate_old_new_predicates(self.project_uuid,
                                            self.source_id,
                                            predicate_uuid,
                                            note_pred_uuid)
         sm = StringManagement()
         sm.project_uuid = self.project_uuid
         sm.source_id = self.source_id
         oc_string = sm.get_make_string(content)
         object_uuid = oc_string.uuid
         if self.check_description_new(self.subject_uuid,
                                       self.obs_num,
                                       note_pred_uuid,
                                       object_uuid,
                                       None,
                                       None):
             # this asertion does not exist yet, OK to make it
             new_ass = Assertion()
             new_ass.uuid = self.subject_uuid
             new_ass.subject_type = self.subject_type
             new_ass.project_uuid = self.project_uuid
             new_ass.source_id = self.source_id
             new_ass.obs_node = self.obs_node
             new_ass.obs_num = self.obs_num
             new_ass.sort = self.sort + .1
             new_ass.visibility = 1
             new_ass.predicate_uuid = note_pred_uuid
             new_ass.object_uuid = object_uuid
             new_ass.object_type = 'xsd:string'
             new_ass.save()
Exemplo n.º 7
0
 def seperate_inconsistent_data_type(self, predicate_uuid):
     """ This looks for assertions that have different object types than the
         required main data_type of a given predicate. If such different assertions
         are found, the offending assertion is deleted and replaced by a new predicate
         and that new predicate is related back to the old predicate via 'skos:related'
     """
     plabel = False
     ptype = False
     pdata_type = False
     new_rel_predicates = []  # list of new predicates made from old
     try:
         pman = Manifest.objects.get(uuid=predicate_uuid)
         plabel = pman.label
         ptype = pman.class_uri
     except Manifest.DoesNotExist:
         pman = False
     try:  # look for the predicate item
         pred = Predicate.objects.get(uuid=predicate_uuid)
         pdata_type = pred.data_type
     except Predicate.DoesNotExist:
         pred = False
     if (plabel is not False and ptype is not False
             and pdata_type is not False):
         adistinct = Assertion.objects.filter(predicate_uuid=predicate_uuid)\
                              .exclude(object_type=pdata_type)\
                              .order_by('object_type')\
                              .distinct('object_type')  # get distinct list of object_types
         for aitem in adistinct:  # list of assertions that are not using the good data type
             pm = PredicateManagement()
             pm.source_id = pman.source_id
             pm.project_uuid = pman.project_uuid
             pm.sort = pred.sort
             cpred = pm.get_make_predicate(plabel, ptype, aitem.object_type)
             if (cpred is not False):
                 if (cpred.uuid not in new_rel_predicates):
                     new_rel_predicates.append(cpred.uuid)
         if (len(new_rel_predicates) > 0):
             #  add annotations storing the relationship between the new predicates and the old
             print('---- New predicates: ' + str(len(new_rel_predicates)))
             for new_pred_uuid in new_rel_predicates:
                 print('New predicate: ' + str(new_pred_uuid))
                 self.skos_relate_old_new_predicates(
                     pman.project_uuid, pman.source_id, predicate_uuid,
                     new_pred_uuid)
             alist = Assertion.objects.filter(
                 predicate_uuid=predicate_uuid).exclude(
                     object_type=pdata_type)
             for aitem in alist:  # list of assertions that are not using the good data type
                 pm = PredicateManagement()
                 pm.source_id = pman.source_id
                 pm.project_uuid = pman.project_uuid
                 pm.sort = pred.sort
                 cpred = pm.get_make_predicate(plabel, ptype,
                                               aitem.object_type)
                 if (cpred is not False):
                     if (cpred.uuid not in new_rel_predicates):
                         new_rel_predicates.append(cpred.uuid)
                     Assertion.objects.filter(
                         hash_id=aitem.hash_id).delete()
                     # delete the old instance of the assertion
                     aitem.predicate_uuid = cpred.uuid  # change the predicate to the new predicate
                     aitem.save(
                     )  # save the assertion with the new predicate
         else:
             print('--OK Predicate--: ' + str(predicate_uuid))
Exemplo n.º 8
0
 def seperate_inconsistent_data_type(self, predicate_uuid):
     """ This looks for assertions that have different object types than the
         required main data_type of a given predicate. If such different assertions
         are found, the offending assertion is deleted and replaced by a new predicate
         and that new predicate is related back to the old predicate via 'skos:related'
     """
     plabel = False
     ptype = False
     pdata_type = False
     new_rel_predicates = []  # list of new predicates made from old
     try:
         pman = Manifest.objects.get(uuid=predicate_uuid)
         plabel = pman.label
         ptype = pman.class_uri
     except Manifest.DoesNotExist:
         pman = False
     try:  # look for the predicate item
         pred = Predicate.objects.get(uuid=predicate_uuid)
         pdata_type = pred.data_type
     except Predicate.DoesNotExist:
         pred = False
     if(plabel is not False
        and ptype is not False
        and pdata_type is not False):
         adistinct = Assertion.objects.filter(predicate_uuid=predicate_uuid)\
                              .exclude(object_type=pdata_type)\
                              .order_by('object_type')\
                              .distinct('object_type')  # get distinct list of object_types
         for aitem in adistinct:  # list of assertions that are not using the good data type
             pm = PredicateManagement()
             pm.source_id = pman.source_id
             pm.project_uuid = pman.project_uuid
             pm.sort = pred.sort
             cpred = pm.get_make_predicate(plabel, ptype, aitem.object_type)
             if(cpred is not False):
                 if(cpred.uuid not in new_rel_predicates):
                     new_rel_predicates.append(cpred.uuid)
         if(len(new_rel_predicates) > 0):
             #  add annotations storing the relationship between the new predicates and the old
             print('---- New predicates: ' + str(len(new_rel_predicates)))
             for new_pred_uuid in new_rel_predicates:
                 print('New predicate: ' + str(new_pred_uuid))
                 self.skos_relate_old_new_predicates(pman.project_uuid,
                                                     pman.source_id,
                                                     predicate_uuid,
                                                     new_pred_uuid)
             alist = Assertion.objects.filter(predicate_uuid=predicate_uuid).exclude(object_type=pdata_type)
             for aitem in alist:  # list of assertions that are not using the good data type
                 pm = PredicateManagement()
                 pm.source_id = pman.source_id
                 pm.project_uuid = pman.project_uuid
                 pm.sort = pred.sort
                 cpred = pm.get_make_predicate(plabel, ptype, aitem.object_type)
                 if(cpred is not False):
                     if(cpred.uuid not in new_rel_predicates):
                         new_rel_predicates.append(cpred.uuid)
                     Assertion.objects.filter(hash_id=aitem.hash_id).delete()
                     # delete the old instance of the assertion
                     aitem.predicate_uuid = cpred.uuid  # change the predicate to the new predicate
                     aitem.save()  # save the assertion with the new predicate
         else:
             print('--OK Predicate--: ' + str(predicate_uuid))