Beispiel #1
0
  def search_records(cls, query):
    c = DemographicConnector()
    res = c.sparql(query)
    m = parse_rdf(res)

    # for each person, look up their demographics object.
    from smart.models.record_object import RecordObject
    people = m.triples((None, rdf['type'], sp.Demographics))
    pobj = RecordObject[sp.Demographics] 

    obtained = set()
    return_graph = bound_graph()
    for person in people:
      p = person[0] # subject

      # Connect to RDF Store
      pid = re.search("\/records\/(.*?)\/demographics", str(p)).group(1)
      if pid in obtained: continue

      print "matched ", p," to ", pid
      obtained.add(pid)
      c = RecordStoreConnector(Record.objects.get(id=pid))

      # Pull out demographics
      p_uri = p.n3() # subject URI
      p_subgraph = parse_rdf(c.sparql(pobj.query_one(p_uri)))
      
      # Append to search result graph
      return_graph += p_subgraph
    return serialize_rdf(return_graph)
Beispiel #2
0
    def search_records(cls, query):
        c = DemographicConnector()
        res = c.sparql(query)
        m = parse_rdf(res)

        # for each person, look up their demographics object.
        from smart.models.record_object import RecordObject
        people = m.triples((None, rdf['type'], sp.Demographics))
        pobj = RecordObject[sp.Demographics]

        obtained = set()
        return_graph = bound_graph()
        for person in people:
            p = person[0]  # subject

            # Connect to RDF Store
            pid = re.search("\/records\/(.*?)\/demographics", str(p)).group(1)
            if pid in obtained: continue

            print "matched ", p, " to ", pid
            obtained.add(pid)
            c = RecordStoreConnector(Record.objects.get(id=pid))

            # Pull out demographics
            p_uri = p.n3()  # subject URI
            p_subgraph = parse_rdf(c.sparql(pobj.query_one(p_uri)))

            # Append to search result graph
            return_graph += p_subgraph
        return serialize_rdf(return_graph)
Beispiel #3
0
def rdf_delete(record_connector, query, save=True): 
    to_delete = parse_rdf(record_connector.sparql(query))
    deleted = bound_graph()

    for r in to_delete:
       deleted.add(r)
       record_connector.pending_removes.append(r)
       
    if (save): record_connector.execute_transaction()
       
    return rdf_response(serialize_rdf(deleted))
Beispiel #4
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 #5
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 #6
0
def wiki_properties_for_type(t):
    if len(t.object_properties) + len(t.data_properties) == 0:
        return
    properties_start(t.uri)
    for c in sorted(t.object_properties + t.data_properties, key=lambda r: str(r.uri)):
        name = type_name_string(c)
        desc = c.description
        m = bound_graph().namespace_manager
        uri = '['+str(t.uri)+' '+m.normalizeUri(t.uri)+']'

        if type(c) is OWL_ObjectProperty:
            is_code = sp.Code in [p.uri for p in c.to_class.parents] and " code" or ""
            targetname = type_name_string(c.to_class)+ is_code

            desc = "[[#%s RDF | %s]]"%(targetname, targetname)
            further = filter(lambda x: isinstance(x.all_values_from, OWL_Restriction), c.restrictions)
            for f in further:
                p = split_uri(str(f.all_values_from.on_property))
                avf = f.all_values_from
                if avf.has_value:
                    desc += "where "+ p +   " has value: %s"%avf.has_value
                else:
                    pc = avf.all_values_from
                    pc = type_name_string(pc)
                    desc += " where "+ p +   " comes from [[#%s code RDF | %s]]"%(pc,pc)

            if c.description:
                desc += "\n\n" + c.description

        elif type(c) is OWL_DataProperty:
            avf = filter(lambda x: x.all_values_from, c.restrictions)
            if len(avf) >0:
              u = avf[0].all_values_from.uri
              d = '[['+str(u)+' '+m.normalizeUri(u)+']]'
            else: d =  '[['+str(rdfs.Literal)+' '+m.normalizeUri(rdfs.Literal)+']]'
            desc += " "+ d
            
        cardinality = cardinalities[c.cardinality_string]
        required_p = False
        if c.cardinality_string[0] == '1':
          required_p = True
          
        properties_row(name, uri, cardinality, desc, required_p)
    properties_end()
Beispiel #7
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 #8
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