Skip to content
Snippets Groups Projects

SPARQL group by

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Steve Battle
    group.sparql 399 B
    from rdflib import Graph
    
    g = Graph()
    g.parse("data.ttl", format="turtle")
    
    sparql = """
    prefix sosa: <http://www.w3.org/ns/sosa/>
    prefix iot: <http://www.example.com/iot#>
    select (COUNT(*) AS ?count) ?label where {
        [] a sosa:Observation;
            sosa:madeBySensor ?s .
        ?s rdfs:label ?label
    } GROUP BY ?label
    """
    
    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