Quick Start

SPARQL is a language for querying so called linked open data stored in a triple store.

Our system consumes data from Czech National Traffic Information Centre in form of DATEX II Situation Publication, converts safety related traffic information content into RDF format and stores it in triple store.

Let’s see how to query the LOD content using publicly available SPARQL query form.

SPARQL queries

SPARQL is language to query RDF data stored in triplestores. It’s syntax is similar to SQL.

Open SPARQL query editor

Visit https://lod.tamtamresearch.com/sparql/ to open SPARQL query editor form.

SPARQL Query Editor is HTML page with a form allowing to enter a SPARQL query and execute it.

SPARQL Query Editor Form

SPARQL Query Editor Form

Leave the “Default Data Set Name (Graph IRI)” (1) empty.

Use the edit field (2) and enter there following SPARQL query:

PREFIX dtx_srti: <http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?type ?sit_rec_ver
WHERE {
  ?sit_rec_ver a ?type .
  ?type rdfs:subClassOf+ dtx_srti:SituationRecord .
}

which shall return a table with situation record versions and their respective type (as the first column “type”).

Keep the “Result Format” selection list (3) as “HTML” and click the “Execute Query” button (4) to run the query.

View results as HTML table

Results of SPARQL Query in HTML table

Results of SPARQL Query in HTML table

The resulting HTML page shall contain HTML table with two columns:

  • type: situation record type IRI

  • sit_rec_ver: situation record version IRI

View results as JSON

If you would select output format “JSON”, the response would be similar to:

{
  "head": {
    "link": [],
    "vars": [
      "type",
      "sit_rec_ver"
    ]
  },
  "results": {
    "distinct": false,
    "ordered": true,
    "bindings": [
      {
        "type": {
          "type": "uri",
          "value": "http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti#AnimalPresenceObstruction"
        },
        "sit_rec_ver": {
          "type": "uri",
          "value": "https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/ff808181-7fd6-d35d-0183-a45277145deb_AnimalPresenceObstruction/2"
        }
      },
      {
        "type": {
          "type": "uri",
          "value": "http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti#AnimalPresenceObstruction"
        },
        "sit_rec_ver": {
          "type": "uri",
          "value": "https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/ff808181-7fd6-d35d-0183-a45277145deb_AnimalPresenceObstruction/2"
        }
      }
    ]
  }
}

Exploring IRIs

Note

IRI stands for Internationalized Resource Identifier which is Uniform Resource Identifier (URI) with greatly expanded set of permitted characters.

The act of retrieving a representation of a resource identified by a URI is known as dereferencing that URI. Typically this is done by HTTP GET request to a URL being identical to URI.

Dereferencable IRIs are those, you can click on and get the content.

There are multiple ways of exploring IRIs.

View ontology specs for situation record type

The first column named “type” shows IRIs for situation record type.

Visiting such a IRI in a browser results in opening the ontology, defining it, and showing relevant section for given situation record type.

First open the url of situation record type in the the first “type” column - open it in a new windows (as we will need the table of results soon again).

This shall open documentation for ontology, describing given situation record type.

For IRI https://cef.uv.es/lodroadtran18/def/transporte/dtx_srti/#AnimalPresenceObstruction we may see following specs.

Ontology Specification - details about animal presence obstruction class

Ontology Specification - details about animal presence obstruction class

View situation record in LOD View

Note

Following examples use IRI of SituationRecord https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/ff808181-7fd6-d35d-0183-a45277145deb_AnimalPresenceObstruction/2

As given situation version can be removed after being expired, it is likely, attempt to view will fail.

For that reason make sure you use another, freshly retrieved IRI.

Go back to the HTML table with query result and click an url in the second column “srti_rec_ver”.

This shall open a page in so called LOD View.

LOD View - Browsable representation of IRI and it's context

LOD View - Browsable representation of IRI and it’s context

LOD View is a web application allowing to present information about respective IRI dereferenced into URL in wider context.

In our case, LOD View is automatically used for IRIs starting with https://lod.tamtamresearch.com/resource/ so it shall cover IRI of any SituationRecord.

The page provides following information:

  • top section (1) shows IRI and it’s type

  • main sections (2) lists all explictily named resource properties

  • bottom section (3) lists so called blank nodes - properties without explicit IRI

  • right side (4) shows either value (so called literal) or IRI

  • icon (5) with three “bubbles” can visualize the IRI on external site https://en.lodlive.it

  • there are many hyperlinks on the page which allow to browse the content from given IRI point of view.

SPARQL query to show situation record version details

Situation records are stored in our triplestore in a graph named https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/

Following SPARQL query retrieves all information about situation record version with IRI https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/ff808181-7fd6-d35d-0183-a45277145deb_AnimalPresenceObstruction/2 as stored within given graph.

CONSTRUCT {
  <https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/ff808181-7fd6-d35d-0183-a45277145deb_AnimalPresenceObstruction/2> ?p_1 ?o_1 .
  ?o_1 ?p_2 ?o_2 .
  ?o_2 ?p_3 ?o_3 .
  ?o_3 ?p_4 ?o_4 .
}
WHERE {
  GRAPH <https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/>
  {
    <https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/b84362ae-9a00-4c92-8af1-7c519bc8c5bf_AbnormalTraffic/3> ?p_1 ?o_1 .
    OPTIONAL {
      ?o_1 ?p_2 ?o_2 .
      OPTIONAL {
        ?o_2 ?p_3 ?o_3 .
        OPTIONAL {
          ?o_3 ?p_4 ?o_4 .
        }
      }
    }
  }
}

Use the SPARQL Query Editor to execute the query and try to experiment with output formats. In case you would choose Turtle, the result could look like:

@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ns1:  <http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti#> .
@prefix ns2:  <http://purl.org/dc/terms/> .
@prefix ns3:  <https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix ogcgs:        <http://www.opengis.net/ont/geosparql#> .
@prefix ns6:  <http://www.geonames.org/ontology#> .
@prefix ns7:  <http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti/administrativeUnit#> .
@prefix ogcsf:        <http://www.opengis.net/ont/sf#> .

<https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/ff808181-7fd6-d35d-0183-a45277145deb_AnimalPresenceObstruction/2>
  rdf:type    ns1:AbnormalTraffic ;
  ns2:isVersionOf     ns3:b84362ae-9a00-4c92-8af1-7c519bc8c5bf_AbnormalTraffic ;
  ns1:hasAbnormalTrafficType  ns1:heavyTraffic ;
  ns1:hasAdministrativeAreaOfPoint    <https://lod.tamtamresearch.com/resource/dtx_srti/administrativeUnit/Okres/3712> ;
  ns1:hasLocationReference    [       rdf:type        ns1:AlertCMethod2Linear ;
        ns1:hasAlertCMethod2PrimaryLocation   [       rdf:type        ns1:AlertCMethod2PrimaryPointLocation ;
            ns1:hasAlertCLocation     [       ns1:specificLocation    "25899"^^ns1:AlertCLocationCode ] ] ;
        ns1:hasAlertCMethod2SecondaryLocation [       rdf:type        ns1:AlertCMethod2SecondaryPointLocation ;
            ns1:hasAlertCLocation     [       ns1:specificLocation    26334 ] ] ;
        ns1:alertCLocationCountryCode "CZ" ;
        ns1:alertCLocationTableNumber "25" ;
        ns1:alertCLocationTableVersion        "9.0" ;
        ns1:hasAlertCDirection        [       rdf:type        ns1:AlertCDirection ;
            ns1:hasAlertCDirectionCoded       ns1:negativeDirection ] ] ;
  ns1:hasProbabilityOfOccurrence      ns1:riskOf ;
  ns1:hasValidity     [       rdf:type        ns1:Validity ;
        ns1:hasValidityStatus ns1:definedByValidityTimeSpec ;
        ns1:validityTimeSpecification [       rdf:type        ns1:OverallPeriod ;
            ns1:overallEndTime        "2022-10-04T19:56:15+02:00"^^xsd:dateTime ;
            ns1:overallStartTime      "2022-10-04T19:22:15+02:00"^^xsd:dateTime ] ] ;
  ns1:situationRecordCreationTime     "2022-10-04T19:26:18+02:00"^^xsd:dateTime ;
  ns1:situationRecordVersionTime      "2022-10-04T19:26:17+02:00"^^xsd:dateTime ;
  ogcgs:hasGeometry   [       rdf:type        ogcsf:Point ;
        ogcgs:asWKT   "POINT(17.06524571243254,49.341745772394724)" ] .
<https://lod.tamtamresearch.com/resource/dtx_srti/administrativeUnit/Okres/3712>
  rdf:type    ns6:Feature , ns7:AdministrativeUnit .

Fetch snapshot of currently valid Situation Records

$ http  --follow https://lod.tamtamresearch.com/srti/snapshot > snap.ttl

count number of lines:

$ wc -l snap.ttl
26886 snap.ttl

Use your editor to explore the content. It is in Turtle format.

@prefix admin_unit: <http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti/administrativeUnit#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix dtx_srti: <http://cef.uv.es/lodroadtran18/def/transporte/dtx_srti#> .
@prefix ns1: <http://www.opengis.net/ont/geosparql#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ttr_sitrec: <https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/00917dda-cb2f-49f7-bf6e-52a632374c18_ConstructionWorks/4> a dtx_srti:ConstructionWorks ;
    rdfs:label "00917dda-cb2f-49f7-bf6e-52a632374c18_ConstructionWorks/4" ;
    dtx_srti:hasAdministrativeAreaOfPoint <https://lod.tamtamresearch.com/resource/dtx_srti/administrativeUnit/Okres/3304> ;
    dtx_srti:hasConstructionWorkType dtx_srti:constructionWork ;
    dtx_srti:hasLocationReference [ a dtx_srti:AlertCMethod2Linear ;
            dtx_srti:alertCLocationCountryCode "CZ" ;
            dtx_srti:alertCLocationTableNumber "25" ;
            dtx_srti:alertCLocationTableVersion "9.0" ;
            dtx_srti:hasAlertCDirection [ a dtx_srti:AlertCDirection ;
                    dtx_srti:hasAlertCDirectionCoded dtx_srti:positiveDirection ] ;
            dtx_srti:hasAlertCMethod2PrimaryLocation [ a dtx_srti:AlertCMethod2PrimaryPointLocation ;
                    dtx_srti:hasAlertCLocation [ dtx_srti:specificLocation "3549"^^dtx_srti:AlertCLocationCode ] ] ;
            dtx_srti:hasAlertCMethod2SecondaryLocation [ a dtx_srti:AlertCMethod2SecondaryPointLocation ;
                    dtx_srti:hasAlertCLocation [ dtx_srti:specificLocation 41105 ] ] ] ;
    dtx_srti:hasProbabilityOfOccurrence dtx_srti:riskOf ;
    dtx_srti:hasValidity [ a dtx_srti:Validity ;
            dtx_srti:hasValidityStatus dtx_srti:definedByValidityTimeSpec ;
            dtx_srti:validityTimeSpecification [ a dtx_srti:OverallPeriod ;
                    dtx_srti:overallEndTime "2022-11-15T23:59:00+01:00"^^xsd:dateTime ;
                    dtx_srti:overallStartTime "2022-11-01T00:00:00+01:00"^^xsd:dateTime ] ] ;
    dtx_srti:situationRecordCreationTime "2022-11-01T00:00:44+01:00"^^xsd:dateTime ;
    dtx_srti:situationRecordVersionTime "2022-11-01T00:00:34+01:00"^^xsd:dateTime ;
    dcterms:isVersionOf ttr_sitrec:00917dda-cb2f-49f7-bf6e-52a632374c18_ConstructionWorks ;
    dcterms:title "ConstructionWorks" ;
    ns1:hasGeometry [ a <http://www.opengis.net/ont/sf#Point> ;
            ns1:asWKT "POINT(15.191033294979373 49.43855672216489)"^^<http://www.openlinksw.com/schemas/virtrdf#Geometry> ] .

<https://lod.tamtamresearch.com/resource/dtx_srti/SituationRecord/00917dda-cb2f-49f7-bf6e-52a632374c18_RoadOrCarriagewayOrLaneManagement/4> a dtx_srti:RoadOrCarriagewayOrLaneManagement ;
    rdfs:label "00917dda-cb2f-49f7-bf6e-52a632374c18_RoadOrCarriagewayOrLaneManagement/4" ;
    dtx_srti:hasAdministrativeAreaOfPoint <https://lod.tamtamresearch.com/resource/dtx_srti/administrativeUnit/Okres/3304> ;
    dtx_srti:hasLocationReference [ a dtx_srti:AlertCMethod2Linear ;
            dtx_srti:alertCLocationCountryCode "CZ" ;
            dtx_srti:alertCLocationTableNumber "25" ;
            dtx_srti:alertCLocationTableVersion "9.0" ;
            dtx_srti:hasAlertCDirection [ a dtx_srti:AlertCDirection ;
                    dtx_srti:hasAlertCDirectionCoded dtx_srti:positiveDirection ] ;
            dtx_srti:hasAlertCMethod2PrimaryLocation [ a dtx_srti:AlertCMethod2PrimaryPointLocation ;
                    dtx_srti:hasAlertCLocation [ dtx_srti:specificLocation "3549"^^dtx_srti:AlertCLocationCode ] ] ;
            dtx_srti:hasAlertCMethod2SecondaryLocation [ a dtx_srti:AlertCMethod2SecondaryPointLocation ;
                    dtx_srti:hasAlertCLocation [ dtx_srti:specificLocation 41105 ] ] ] ;
    dtx_srti:hasProbabilityOfOccurrence dtx_srti:riskOf ;
    dtx_srti:hasRoadOrCarriagewayOrLaneManagementType dtx_srti:singleAlternateLineTraffic ;
    dtx_srti:hasValidity [ a dtx_srti:Validity ;
            dtx_srti:hasValidityStatus dtx_srti:definedByValidityTimeSpec ;
            dtx_srti:validityTimeSpecification [ a dtx_srti:OverallPeriod ;
                    dtx_srti:overallEndTime "2022-11-15T23:59:00+01:00"^^xsd:dateTime ;
                    dtx_srti:overallStartTime "2022-11-01T00:00:00+01:00"^^xsd:dateTime ] ] ;
    dtx_srti:situationRecordCreationTime "2022-11-01T00:00:44+01:00"^^xsd:dateTime ;
    dtx_srti:situationRecordVersionTime "2022-11-01T00:00:34+01:00"^^xsd:dateTime ;
    dcterms:isVersionOf ttr_sitrec:00917dda-cb2f-49f7-bf6e-52a632374c18_RoadOrCarriagewayOrLaneManagement ;
    dcterms:title "RoadOrCarriagewayOrLaneManagement" ;
    ns1:hasGeometry [ a <http://www.opengis.net/ont/sf#Point> ;
            ns1:asWKT "POINT(15.191033294979373 49.43855672216489)"^^<http://www.openlinksw.com/schemas/virtrdf#Geometry> ] .

Actual sample has many more situation records.

Previous: Guides | Next: SPARQL Query Editor