Esempio n. 1
0
 def _retrieve_value(self, val_id):
     """
     returns a dictionary from a val_id
     
     """
     value_dict = {'value':val_id}
     val = queries.retrieve_value(self, val_id)
     for key in val.keys():
         value_dict['mr:{}'.format(key)] = val[key]
     for sc_prop in ['mr:subject', 'mr:object']:
         pid = value_dict.get(sc_prop)
         if pid:
             prop = queries.retrieve_scoped_property(self, pid)
             if prop:
                 value_dict[sc_prop] = {}
                 for pkey in prop:
                     pv = prop[pkey]
                     value_dict[sc_prop]['mr:{}'.format(pkey)] = pv
                     if pkey == 'hasProperty':
                         pr = value_dict[sc_prop]['mr:{}'.format(pkey)]
                         aprop = queries.retrieve_property(self, pr)
                         value_dict[sc_prop]['mr:{}'.format(pkey)] = {'property':pv}
                         for p in aprop:
                             value_dict[sc_prop]['mr:{}'.format(pkey)]['mr:{}'.format(p)] = aprop[p]
             elif pid.startswith('<http://www.metarelate.net/metOcean/value/'):
                 newval = self._retrieve_value(pid)
                 value_dict[sc_prop] = newval
             else:
                 value_dict[sc_prop] = pid
     return value_dict
Esempio n. 2
0
 def _retrieve_component(self, c_id):
     """
     returns a dictionary of component information
     recursive call to get all the nested formatConcept
     information from a formatConcept
     
     """
     # c_dict = {'formatConcept':'', 'mr:format': '', 'skos:member': []},
     top_c = queries.retrieve_component(self, c_id)
     if top_c:
         c_dict = {'component':c_id, 'mr:hasFormat': top_c['format']}
         if isinstance(top_c.get('property'), str):
             top_c['property'] = [top_c['property']]
         if isinstance(top_c.get('subComponent'), str):
             top_c['subComponent'] = [top_c['subComponent']]
         if top_c.get('property'):
             c_dict['mr:hasProperty'] = []
         if top_c.get('subComponent'):
             c_dict['mr:hasComponent'] = []
         for aproperty in top_c.get('property', []):
             prop_dict = queries.retrieve_property(self, aproperty)
             pref_prop_dict = {}
             #pcomp = prop_dict.get('mr:hasComponent')
             pcomp = prop_dict.get('component') 
             if pcomp:
                 comp = self._retrieve_component(pcomp)
                 pref_prop_dict['mr:hasComponent'] = comp
             if prop_dict.get('name'):
                 pref_prop_dict['mr:name'] = prop_dict['name']
             if prop_dict.get('operator'):
                 pref_prop_dict['mr:operator'] = prop_dict['operator']
             if prop_dict.get('value'):
                 pref_prop_dict['rdf:value'] = prop_dict['value']
             c_dict['mr:hasProperty'].append(pref_prop_dict)
         for component in top_c.get('subComponent',[]):
             subc_dict = self._retrieve_component(component)
             c_dict['mr:hasComponent'].append(subc_dict)
         if top_c.get('mediates'):
             c_dict['dc:mediator'] = [top_c['mediates']]
         if top_c.get('requires'):
             c_dict['dc:requires'] = top_c['requires']
     else:
         raise ValueError('{} a malformed formatConcept'.format(fc_id))
     return c_dict