Beispiel #1
0
 def __getitem__(cls, key):
     try:
         return cls.known_types_dict[key]
     except:
         try:
             return cls.known_types_dict[key.uri]
         except:
             return cls.known_types_dict[URIRef(key.encode())]
Beispiel #2
0
class ContextTripleStore(TripleStore):
    queryparam = "$context"

    def __init__(self, endpoint, context):
        super(ContextTripleStore, self).__init__(endpoint)
        self.context = URIRef( context )

    def sparql(self, q):
        q = q.replace(self.queryparam, self.context.n3())
        return super(ContextTripleStore, self).sparql(q)
Beispiel #3
0
def container_capabilities(request, **kwargs):
    m = bound_graph()
    site = URIRef(settings.SITE_URL_PREFIX)
    print "avail", dir(m)
    m.add((site, rdf['type'], sp['Container']))

    m.add((site, sp['capability'], sporg['capability/SNOMED/lookup']))

    m.add((site, sp['capability'], sporg['capability/SPL/lookup']))

    m.add((site, sp['capability'], sporg['capability/Pillbox/lookup']))

    return utils.x_domain(
        HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
Beispiel #4
0
    def determine_full_path(self, var_bindings=None):
        ret = settings.SITE_URL_PREFIX + self.path
        for vname, vval in var_bindings.iteritems():
            if vval == "": vval = "{new_id}"
            ret = ret.replace("{" + vname + "}", vval)

        still_unbound = re.findall("{(.*?)}", ret)
        assert len(
            still_unbound
        ) <= 1, "Can't match path closely enough: %s given %s -- got to %s" % (
            self.path, var_bindings, ret)
        if len(still_unbound) == 1:
            ret = ret.replace("{" + still_unbound[0] + "}", str(uuid.uuid4()))

        return URIRef(ret)
Beispiel #5
0
    def attach_statements_to_record(self, g, new_uris, var_bindings):
        # Attach each data element (med, problem, lab, etc), to the
        # base record URI with the sp:Statement predicate.
        recordURI = URIRef(
            smart_path("/records/%s" % var_bindings['record_id']))
        for n in new_uris:
            node_type = get_property(g, n, rdf.type)

            # Filter for top-level medical record "Statement" types
            t = ontology[node_type]
            if (not t.is_statement): continue
            if (not t.base_path.startswith("/records")): continue
            if (n == recordURI):
                continue  # don't assert that the record has itself as an element

            g.add((recordURI, sp.hasStatement, n))
            g.add((recordURI, rdf.type, sp.MedicalRecord))
Beispiel #6
0
    def to_rdf(self, model=None):
        from smart.client.common.util import sp, foaf, rdf

        if model == None: m = util.bound_graph()
        else: m = model

        n = URIRef("%s/users/%s" %
                   (settings.SITE_URL_PREFIX, self.email.encode()))
        m.add((n, rdf['type'], sp['user']))

        try:
            gn = self.given_name or "?"
            fn = self.family_name or "?"

            m.add((n, foaf['givenName'], Literal(gn.encode())))
            m.add((n, foaf['familyName'], Literal(fn.encode())))
            m.add((n, sp['department'], Literal(self.department.encode())))
            m.add((n, sp['role'], Literal(self.role.encode())))
            m.add(
                (n, foaf['mbox'], Literal("mailto:%s" % self.email.encode())))
        except:
            pass

        return m
Beispiel #7
0
 def destroy_triples(self):
     self.pending_clears.append(URIRef(self.context.encode()))
     self.execute_transaction()
Beispiel #8
0
 def serialize_statement(self, st):
     return "%s %s %s %s" % (self.serialize_node(
         st[0]), self.serialize_node(st[1]), self.serialize_node(
             st[2]), self.serialize_node(URIRef(self.context.encode())))
Beispiel #9
0
 def __init__(self, endpoint, context):
     super(ContextTripleStore, self).__init__(endpoint)
     self.context = URIRef( context )