Beispiel #1
0
 def _rdf_resource(self, e):
     TNS, tn = _split_URI(e.tag)
     concept = None
     try:
         concept = TNS[tn]
     except ObjectDoesNotExist, x:
         self._except(ObjectDoesNotExist, x, 'unable to resolve tag `%s`' % e.tag) # IGNORE:E1101
Beispiel #2
0
 def _rdf_property_subpropertyof(self, e, predicate):
     b = e.find(RDFS_SUBPROPERTYOF)
     if b is None: return
     b = b.get(RDF_RESOURCE)
     if b is None: return
     bns, bname = _split_URI(b)
     self._superpredicates.append((predicate, bns, bname))    
Beispiel #3
0
 def _rdfs_class_subclassof(self, e, concept):
     b = e.find(RDFS_SUBCLASSOF)
     if b is None: return
     b = b.get(RDF_RESOURCE)
     if b is None: return
     bns, bname = _split_URI(b)
     self._superconcepts.append((concept, bns, bname))                
Beispiel #4
0
def _rdf_property_domain(e):
    create = False
    de = e.find(RDFS_DOMAIN)
    if de is None:
        domain = RESOURCE
    else:
        dns, dn = _split_URI(de.get(RDF_RESOURCE))
        try: 
            domain = Concept.objects.get(resource__namespace=dns, resource__name=dn)
        except Concept.DoesNotExist: # IGNORE:E1101
            r, _ = Resource.objects.get_or_create(
                namespace=dns, name=dn, defaults=dict(type=CONCEPT))
            domain = Concept(resource=r, title=dn.title())
            create = True
    return domain, create
Beispiel #5
0
def _rdf_property_range(e):
    create = False
    re = e.find(RDFS_RANGE)
    if re is None:
        range = RESOURCE
    else:
        rns, rn = _split_URI(re.get(RDF_RESOURCE))
        assert not rns is None
        assert '' != rn
        try:
            r, _ = Resource.objects.get_or_create(
                namespace=rns, name=rn, defaults=dict(type=CONCEPT))
            range = Concept.objects.get(resource=r)
        except Concept.DoesNotExist: # IGNORE:E1101
            range = Concept(resource=r, title=rn.title())
            create = True
    return range, create
Beispiel #6
0
     self._superpredicates.append((predicate, bns, bname))    
 
 def _rdf_resource(self, e):
     TNS, tn = _split_URI(e.tag)
     concept = None
     try:
         concept = TNS[tn]
     except ObjectDoesNotExist, x:
         self._except(ObjectDoesNotExist, x, 'unable to resolve tag `%s`' % e.tag) # IGNORE:E1101
     if concept is None or not isinstance(concept, Concept):
         return
     
     uri = e.get(RDF_ABOUT)
     if uri is None:
         uri = e.get(RDF_ID) # Either about or ID are required
     RNS, rn = _split_URI(uri)
     if RNS is None:
         RNS = self._ontology.namespace # Best guess
     match = Resource.objects.filter(namespace=RNS, name=rn)
     resource = None
     if 1 > match.count(): 
         resource = Resource(namespace=RNS, name=rn, type=concept)
         yield resource
     else:
         resource = match[0]
         
     custom_model = _rdf_resource_map_custom_model(e, resource, concept)
     if not custom_model is None: yield custom_model
     dc_title = _rdf_resource_dc_title(e, resource)
     if not dc_title is None: yield dc_title
     dc_description = _rdf_resource_dc_description(e, resource)