def legacy_load_databases_json(): subject_dict = {} alt_title_dict = {} for row in subjects: subject_dict[row['pk']] = {"name":row['fields']['name']} new_topic = TopicalConcept(redis_datastore=REDIS_DATASTORE, description="Topic Used for Database-by-Subject view in dbfinder", label=row['fields']['name']) new_topic.save() subject_dict[row['pk']]["redis_key"] = new_topic.redis_key REDIS_DATASTORE.sadd("dbfinder:subjects", new_topic.redis_key) for row in alt_titles: db_key = row['fields']['database'] if alt_title_dict.has_key(db_key): alt_title_dict[db_key].append(row['fields']['title']) else: alt_title_dict[db_key] = [row['fields']['title'],] for i,row in enumerate(databases): db_pk = row['pk'] description = row['fields']['description'] title = row['fields']['title'] new_work = Work(redis_datastore=REDIS_DATASTORE, description=description, title={'rda:preferredTitleForTheWork':title}) if alt_title_dict.has_key(db_pk): new_work.varientTitle = [] for alt_title in alt_title_dict[db_pk]: new_work.varientTitle.append(alt_title) new_work.varientTitle = set(new_work.varientTitle) new_work.save() subject_keys = [] for subject_id in row['fields']['subjects']: subject_name = subject_dict[subject_id].get("name",None) if subject_name is not None: subject_keys.append(subject_dict[subject_id].get("redis_key")) REDIS_DATASTORE.sadd("dbfinder:subject:{0}".format(subject_name), new_work.redis_key) if len(subject_keys) > 0: new_work.subject = set(subject_keys) new_work.save() alpha_redis_key = "dbfinder:alpha:{0}".format(title[0].upper()) REDIS_DATASTORE.sadd(alpha_redis_key, new_work.redis_key) REDIS_DATASTORE.sadd("dbfinder:alphas",alpha_redis_key) new_instance = Instance(redis_datastore=REDIS_DATASTORE, instanceOf=new_work.redis_key, uri=row['fields']['url']) new_instance.save() REDIS_DATASTORE.sadd("{0}:bibframe:Instances".format(new_work.redis_key), new_instance.redis_key) print("Added {0}".format(title))
def setUp(self): new_database = Work(primary_redis=test_redis, description="A new database of Art and Artists", title={"rda:preferredTitleOfWork":"Art and Artists", "rda:varientTitle":["Art's Aritists"]}) new_database.save() self.db_redis_key = new_database.redis_key new_db_instance = Instance(primary_redis=test_redis, instanceOf=new_database.redis_key, uri="http://ArtAndArtists.html") new_db_instance.save() setattr(new_database,"bibframe:Instances",new_db_instance.redis_key) new_database.save()
def __create_instances__(self, work_key, rdacarrier): """Helper function creates specific instance(s) from MODS Parameter: work_key -- Work Key to be associated with BIBFRAME Instance(s) """ # Create an instance for each originInfo element in MODS origin_infos = self.mods_xml.findall('{{{0}}}originInfo'.format( MODS_NS)) form = self.mods_xml.find( '{{{0}}}physicalDescription/{{{0}}}form'.format(MODS_NS)) for element in origin_infos: instance_of = {'instanceOf': work_key} if form is not None: if form.attrib.get('type', None) == 'carrier': if form.attrib.get('authority', None) == 'rdacarrier': instance_of['rda:carrierTypeManifestation'] = form.text # Assumes a default of an online resource for # rda:carrierTypeManifestation if not instance_of.has_key('rda:carrierTypeManifestation'): instance_of['rda:carrierTypeManifestation'] = rdacarrier extent = element.find('{{{0}}}extent'.format(MODS_NS)) if extent is not None: if extent.text is not None: instance_of['extent'] = extent.text hdl = self.__extract_hdl__() if hdl is not None: instance_of['hdl'] = hdl language = self.__extract_languages__() if language is not None: instance_of['language'] = language new_instance = Instance(redis_datastore=self.redis_datastore, **instance_of) new_instance.save() self.__create_holding__(new_instance, 'bf:Organization:1:codes:dacc') self.__create_facets__(new_instance, 'Digital Archives of Colorado College') self.instances.append(new_instance.redis_key)
class MARC21toInstance(MARCParser): def __init__(self, **kwargs): kwargs['rules_filename'] = 'bibframe-instance-map.json' super(MARC21toInstance, self).__init__(**kwargs) if kwargs.has_key('instanceOf'): self.entity_info['instanceOf'] = kwargs.get('instanceOf') def add_instance(self): self.instance = Instance(redis_datastore=self.redis_datastore) for key, value in self.entity_info.iteritems(): if key is not None and value is not None: setattr(self.instance, key, value) self.instance.save() def ingest(self): self.parse() #! Should do duplication check before calling add_instance self.add_instance()