Beispiel #1
0
 def db_save_reconcile_entity_predicates_types(self, act_dir):
     """ saves predicates and type items to the
         Open Context database, and / or reconciles these
         items with previously saved items from the same project
     """
     key = self.oc_config_entity_types
     json_obj = self.fm.get_dict_from_file(key, act_dir)
     if json_obj is None:
         print('Need to 1st generate an attributes file from the ArchEnts!')
         ok = False
     else:
         # we have JSON with dictionary for the entity_types
         self.entity_types = json_obj
         make_entity_types_assertions = False
         for faims_ent_type_id, ent_dict in json_obj.items():
             if isinstance(ent_dict['item_type'], str) \
                and ent_dict['add_type_as_attribute']:
                 # OK we have some items that need entity types made as
                 # a descriptive attribute
                 make_entity_types_assertions = True
                 break
         if make_entity_types_assertions:
             # we have entity_types that need to have a descriptive
             # predicate, so create a new predicate in Open Context
             # to describe entity_types for this project
             sup_dict = LastUpdatedOrderedDict()
             sup_dict[self.reconcile_key] = self.ent_type_pred_sup_id
             pm = PredicateManagement()
             pm.project_uuid = self.project_uuid
             pm.source_id = self.source_id
             pm.sup_dict = sup_dict
             pm.sup_reconcile_key = self.reconcile_key
             pm.sup_reconcile_value = self.ent_type_pred_sup_id
             pred_obj = pm.get_make_predicate(
                 self.FAIMS_ENTITY_TYPE_PREDICATE_LABEL, 'variable', 'id')
             if pred_obj is not False:
                 # we reconciled or created the predicate!
                 # now we mint oc_types for all the entity_types
                 predicate_uuid = str(pred_obj.uuid)
                 for faims_ent_type_id, ent_dict in json_obj.items():
                     if isinstance(ent_dict['item_type'], str) \
                        and ent_dict['add_type_as_attribute']:
                         # OK, we have an item entity type to be used as a description
                         sup_dict = LastUpdatedOrderedDict()
                         sup_dict[self.reconcile_key] = faims_ent_type_id
                         tm = TypeManagement()
                         tm.project_uuid = self.project_uuid
                         tm.source_id = self.source_id
                         tm.sup_dict = sup_dict
                         tm.sup_reconcile_key = self.reconcile_key
                         tm.sup_reconcile_value = faims_ent_type_id
                         type_obj = tm.get_make_type_within_pred_uuid(
                             predicate_uuid, ent_dict['label'])
                         if type_obj is not False:
                             # we have reconciled the type!
                             ent_dict['type_uuid'] = str(type_obj.uuid)
                             ent_dict['predicate_uuid'] = predicate_uuid
                             self.entity_types[faims_ent_type_id] = ent_dict
             # now save the results
             self.fm.save_serialized_json(key, act_dir, self.entity_types)
Beispiel #2
0
 def db_save_reconcile_predicates_types(self, act_dir):
     """ saves predicates and type items to the
         Open Context database, and / or reconciles these
         items with previously saved items from the same project
     """
     key = self.oc_config_attributes
     json_obj = self.fm.get_dict_from_file(key, act_dir)
     if json_obj is None:
         print('Need to 1st generate an attributes file from the ArchEnts!')
         ok = False
     else:
         # we have JSON with dictionary for the attributes
         ok = True
         self.attributes = json_obj
         for faims_id_pred, attrib_dict in json_obj.items():
             # default to always making a predicate and a type for attributes
             sup_dict = LastUpdatedOrderedDict()
             sup_dict[self.reconcile_key] = faims_id_pred
             pm = PredicateManagement()
             pm.project_uuid = self.project_uuid
             pm.source_id = self.source_id
             pm.sup_dict = sup_dict
             pm.sup_reconcile_key = self.reconcile_key
             pm.sup_reconcile_value = faims_id_pred
             pred_obj = pm.get_make_predicate(attrib_dict['label'],
                                              attrib_dict['predicate_type'],
                                              attrib_dict['data_type'])
             if pred_obj is not False:
                 # we reconciled the predicate!
                 self.attributes[faims_id_pred]['predicate_uuid'] = str(
                     pred_obj.uuid)
                 if 'objects' in attrib_dict:
                     for faims_id_type, type_dict in attrib_dict[
                             'objects'].items():
                         sup_dict = LastUpdatedOrderedDict()
                         sup_dict[self.reconcile_key] = faims_id_type
                         tm = TypeManagement()
                         tm.project_uuid = self.project_uuid
                         tm.source_id = self.source_id
                         tm.sup_dict = sup_dict
                         tm.sup_reconcile_key = self.reconcile_key
                         tm.sup_reconcile_value = faims_id_type
                         type_obj = tm.get_make_type_within_pred_uuid(
                             pred_obj.uuid, type_dict['label'])
                         if type_obj is not False:
                             # we have reconciled the type!
                             type_dict['type_uuid'] = str(type_obj.uuid)
                             type_dict['predicate_uuid'] = str(
                                 pred_obj.uuid)
                             self.attributes[faims_id_pred]['objects'][
                                 faims_id_type] = type_dict
         # now save the results
         self.fm.save_serialized_json(key, act_dir, self.attributes)
Beispiel #3
0
 def db_save_reconcile_predicates_types(self, act_dir):
     """ saves predicates and type items to the
         Open Context database, and / or reconciles these
         items with previously saved items from the same project
     """
     key = self.oc_config_attributes
     json_obj = self.fm.get_dict_from_file(key, act_dir)
     if json_obj is None:
         print('Need to 1st generate an attributes file from the ArchEnts!')
         ok = False
     else:
         # we have JSON with dictionary for the attributes
         ok = True
         self.attributes = json_obj
         for faims_id_pred, attrib_dict in json_obj.items():
             # default to always making a predicate and a type for attributes    
             sup_dict = LastUpdatedOrderedDict()
             sup_dict[self.reconcile_key] = faims_id_pred
             pm = PredicateManagement()
             pm.project_uuid = self.project_uuid
             pm.source_id = self.source_id
             pm.sup_dict = sup_dict
             pm.sup_reconcile_key = self.reconcile_key
             pm.sup_reconcile_value = faims_id_pred
             pred_obj = pm.get_make_predicate(attrib_dict['label'],
                                              attrib_dict['predicate_type'],
                                              attrib_dict['data_type'])
             if pred_obj is not False:
                 # we reconciled the predicate!
                 self.attributes[faims_id_pred]['predicate_uuid'] = str(pred_obj.uuid)
                 if 'objects' in attrib_dict:
                     for faims_id_type, type_dict in attrib_dict['objects'].items():
                         sup_dict = LastUpdatedOrderedDict()
                         sup_dict[self.reconcile_key] = faims_id_type
                         tm = TypeManagement()
                         tm.project_uuid = self.project_uuid
                         tm.source_id = self.source_id
                         tm.sup_dict = sup_dict
                         tm.sup_reconcile_key = self.reconcile_key
                         tm.sup_reconcile_value = faims_id_type
                         type_obj = tm.get_make_type_within_pred_uuid(pred_obj.uuid,
                                                                      type_dict['label'])
                         if type_obj is not False:
                             # we have reconciled the type!
                             type_dict['type_uuid'] = str(type_obj.uuid)
                             type_dict['predicate_uuid'] = str(pred_obj.uuid)
                             self.attributes[faims_id_pred]['objects'][faims_id_type] = type_dict
         # now save the results
         self.fm.save_serialized_json(key,
                                      act_dir,
                                      self.attributes)
Beispiel #4
0
 def db_save_reconcile_entity_predicates_types(self, act_dir):
     """ saves predicates and type items to the
         Open Context database, and / or reconciles these
         items with previously saved items from the same project
     """
     key = self.oc_config_entity_types
     json_obj = self.fm.get_dict_from_file(key, act_dir)
     if json_obj is None:
         print('Need to 1st generate an attributes file from the ArchEnts!')
         ok = False
     else:
         # we have JSON with dictionary for the entity_types
         self.entity_types = json_obj
         make_entity_types_assertions = False
         for faims_ent_type_id, ent_dict in json_obj.items():
             if isinstance(ent_dict['item_type'], str) \
                and ent_dict['add_type_as_attribute']:
                 # OK we have some items that need entity types made as
                 # a descriptive attribute
                 make_entity_types_assertions = True
                 break
         if make_entity_types_assertions:
             # we have entity_types that need to have a descriptive
             # predicate, so create a new predicate in Open Context
             # to describe entity_types for this project
             sup_dict = LastUpdatedOrderedDict()
             sup_dict[self.reconcile_key] = self.ent_type_pred_sup_id
             pm = PredicateManagement()
             pm.project_uuid = self.project_uuid
             pm.source_id = self.source_id
             pm.sup_dict = sup_dict
             pm.sup_reconcile_key = self.reconcile_key
             pm.sup_reconcile_value = self.ent_type_pred_sup_id
             pred_obj = pm.get_make_predicate(self.FAIMS_ENTITY_TYPE_PREDICATE_LABEL,
                                              'variable',
                                              'id')
             if pred_obj is not False:
                 # we reconciled or created the predicate!
                 # now we mint oc_types for all the entity_types
                 predicate_uuid = str(pred_obj.uuid)
                 for faims_ent_type_id, ent_dict in json_obj.items():
                     if isinstance(ent_dict['item_type'], str) \
                        and ent_dict['add_type_as_attribute']:
                         # OK, we have an item entity type to be used as a description
                         sup_dict = LastUpdatedOrderedDict()
                         sup_dict[self.reconcile_key] = faims_ent_type_id
                         tm = TypeManagement()
                         tm.project_uuid = self.project_uuid
                         tm.source_id = self.source_id
                         tm.sup_dict = sup_dict
                         tm.sup_reconcile_key = self.reconcile_key
                         tm.sup_reconcile_value = faims_ent_type_id
                         type_obj = tm.get_make_type_within_pred_uuid(predicate_uuid,
                                                                      ent_dict['label'])
                         if type_obj is not False:
                             # we have reconciled the type!
                             ent_dict['type_uuid'] = str(type_obj.uuid)
                             ent_dict['predicate_uuid'] = predicate_uuid
                             self.entity_types[faims_ent_type_id] = ent_dict
             # now save the results
             self.fm.save_serialized_json(key,
                                          act_dir,
                                          self.entity_types)