Skip to content
Snippets Groups Projects

SPARQL filter

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Steve Battle
    Edited
    filter.sparql 529 B
    from rdflib import Graph
    g = Graph()
    g.parse("data.ttl", format="turtle")
    #ttl = str(g.serialize(format='turtle'),'utf-8')
    # print(ttl)
    
    sparql = """
    prefix sosa: <http://www.w3.org/ns/sosa/>
    prefix dc: <http://purl.org/dc/elements/1.1/>
    
    select ?t ?label ?r where {
      [] a sosa:Observation;
        sosa:hasSimpleResult ?r;
        sosa:madeBySensor ?s ;
        sosa:resultTime ?t.
    
      ?s rdfs:label ?label .
    
      FILTER(?label = "currentKitch1")
    } ORDER BY ?t
    """
    results = g.query(sparql)
    print(str(results.serialize(format='csv'),'utf-8'))
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment