Ejemplo n.º 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] 

    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)
      print "matched ", p," to ", 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)))
      print "subq: " , pobj.query_one(p_uri)
      print "subgraph: ", serialize_rdf(p_subgraph)
      
      # Append to search result graph
      return_graph += p_subgraph
    print "got", serialize_rdf(return_graph)
    return serialize_rdf(return_graph)
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
def rdf_post(record_connector, new_g):
    for s in new_g:
        record_connector.pending_adds.append(s)

    record_connector.execute_transaction()
    return rdf_response(serialize_rdf(new_g))