Skip to content
Snippets Groups Projects

SPARQL data fusion

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Steve Battle
    Edited
    fusion.sparql 874 B
    from rdflib import Graph
    g = Graph()
    g.parse("data.ttl", format="turtle")
    
    sparql = """
    prefix sosa: <http://www.w3.org/ns/sosa/>
    prefix dc: <http://purl.org/dc/elements/1.1/>
    
    select ?secs1 ?secs2 ?label1 ?label2 ?diff where {
      [] a sosa:Observation;
        sosa:hasSimpleResult ?r1;
        sosa:madeBySensor ?s1 ;
        sosa:resultTime ?t1.
      ?s1 rdfs:label ?label1 .
    
      [] a sosa:Observation;
        sosa:hasSimpleResult ?r2;
        sosa:madeBySensor ?s2 ;
        sosa:resultTime ?t2.
      ?s2 rdfs:label ?label2 .
    
      FILTER(YEAR(?t1)=YEAR(?t2)) 
      FILTER(MONTH(?t1)=MONTH(?t2)) 
      FILTER(DAY(?t1)=DAY(?t2))
    
      BIND((HOURS(?t1)*60 + MINUTES(?t1))*60 + SECONDS(?t1) AS ?secs1)
      BIND((HOURS(?t2)*60 + MINUTES(?t2))*60 + SECONDS(?t2) AS ?secs2)
      BIND(?secs2 - ?secs1 AS ?diff)
    
      FILTER(0<?diff && ?diff<60)
    }
    """
    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