コード例 #1
0
ファイル: objects.py プロジェクト: azaroth42/pipeline
def add_object_type(data, vocab_type_map):
    '''Add appropriate type information for an object based on its 'object_type' name'''
    typestring = data.get('object_type', '')
    if typestring in vocab_type_map:
        clsname = vocab_type_map.get(typestring, None)
        otype = getattr(vocab, clsname)
        add_crom_data(data=data, what=otype(ident=data['uri']))
    elif ';' in typestring:
        parts = [s.strip() for s in typestring.split(';')]
        if all([s in vocab_type_map for s in parts]):
            types = [getattr(vocab, vocab_type_map[s]) for s in parts]
            obj = vocab.make_multitype_obj(*types, ident=data['uri'])
            add_crom_data(data=data, what=obj)
        else:
            warnings.warn(
                f'*** Not all object types matched for {typestring!r}')
            add_crom_data(data=data,
                          what=model.HumanMadeObject(ident=data['uri']))
    else:
        warnings.warn(f'*** No object type for {typestring!r}')
        add_crom_data(data=data, what=model.HumanMadeObject(ident=data['uri']))

    parent = data['parent_data']
    coll_data = parent.get('_lot_object_set')
    if coll_data:
        coll = get_crom_object(coll_data)
        if coll:
            data['member_of'] = [coll]

    return data
コード例 #2
0
 def attach_source_catalog(self, data, acq, people):
     phys_catalog_notes = {}
     phys_catalogs = {}
     for p in people:
         if '_name_source_catalog_key' in p:
             source_catalog_key = p['_name_source_catalog_key']
             so_cno, so_owner, so_copy = source_catalog_key
             if source_catalog_key in phys_catalog_notes:
                 hand_notes = phys_catalog_notes[source_catalog_key]
                 catalog = phys_catalogs[source_catalog_key]
             else:
                 hand_notes = self.helper.physical_catalog_notes(
                     so_cno, so_owner, so_copy)
                 catalog_uri = self.helper.physical_catalog_uri(
                     so_cno, so_owner, so_copy)
                 catalog = model.HumanMadeObject(ident=catalog_uri)
                 phys_catalog_notes[source_catalog_key] = hand_notes
                 phys_catalogs[source_catalog_key] = catalog
                 catalog.carries = hand_notes
             acq.referred_to_by = hand_notes
     data['_phys_catalog_notes'] = [
         add_crom_data(data={}, what=n)
         for n in phys_catalog_notes.values()
     ]
     data['_phys_catalogs'] = [
         add_crom_data(data={}, what=c) for c in phys_catalogs.values()
     ]
コード例 #3
0
ファイル: test_vocab.py プロジェクト: thegetty/crom
	def test_art_setter(self):
		p = model.HumanMadeObject("a", art=1)
		p._label = "a"
		pj = p._toJSON(done={})
		self.assertFalse(pj.get('classified_as', None))
		vocab.add_art_setter()
		p2 = vocab.Painting("b", art=1)
		p2j = p2._toJSON(done={})
コード例 #4
0
 def test_multiplicity(self):
     model.factory.process_multiplicity = True
     who = model.Actor()
     mmo = model.HumanMadeObject()
     prod = model.Production()
     mmo.produced_by = prod
     who.current_owner_of = mmo
     mmo.current_owner = who
     self.assertEqual(mmo.current_owner, [who])
     self.assertEqual(who.current_owner_of, [mmo])
     self.assertEqual(mmo.produced_by, prod)
コード例 #5
0
    def test_production_mode(self):

        # model.factory.production_mode()
        # Can't unset the cached hierarchy
        # and it causes the test for the hierarchy to fail
        model.factory.validate_profile = False
        model.factory.validate_properties = False
        model.factory.validate_range = False
        model.factory.validate_multiplicity = False

        p = model.Person()
        p.identified_by = model.Name(value="abc")
        p.part = model.HumanMadeObject()
        js = model.factory.toJSON(p)

        model.factory.production_mode(state=False)
コード例 #6
0
 def test_breadth(self):
     x = model.TransferOfCustody()
     e = model.Activity()
     fr = model.Group()
     to = model.Group()
     w = model.HumanMadeObject()
     fr._label = "From"
     to._label = "To"
     x.transferred_custody_of = w
     x.transferred_custody_from = fr
     x.transferred_custody_to = to
     e.used_specific_object = w
     e.carried_out_by = to
     w.current_owner = fr
     x.specific_purpose = e
     js = model.factory.toJSON(x)
     # Okay ... if we're breadth first, then custody_from is a resource
     # And now it's the first in the list
     self.assertTrue(
         isinstance(js['transferred_custody_from'][0], OrderedDict))
コード例 #7
0
 def test_cache_hierarchy(self):
     o = model.HumanMadeObject()
     self.assertEqual(o._all_properties, {})
     model.factory.cache_hierarchy()
     self.assertTrue(len(o._all_properties) > 50)