Querying PoolParty History with SPARQL

Note

Although valid, the information provided in this section is outdated. We recommend to retrieve History data via History Services instead.

PoolParty History is based on changeset. History data is stored in a named graph (http://schema.semantic-web.at/ppt/history#context) in your project repository.

In this section you can find some SPARQL queries that cover different use cases when dealing with PoolParty History.

Note

The graph name where the history data is stored depends on the base URL used for the project. "<http://<baseUrl>/<projectId>/thesaurus/history>" has to be substituted by the actual graph name. See information about the repository structure of PoolParty projects.

Run the following SPARQL query on your project repository if you have doubts about how the history graph is called in your project:

SELECT DISTINCT ?g
WHERE {
        GRAPH ?g { ?s ?p ?o } filter(regex(str(?g),"history"))
} ORDER BY ?g

General query to retrieve latest changes

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX changeset:<http://purl.org/vocab/changeset/schema#>
SELECT ?date ?subject ?type ?rdfType
WHERE {
  GRAPH <http://<baseUrl>/<projectId>/thesaurus/history> {
   ?s changeset:subjectOfChange ?subject .
   ?s changeset:changeType ?type .
   ?s changeset:createdDate ?date .
   ?s rdf:type ?rdfType .
  }
}
ORDER BY DESC(?date) LIMIT 10

Query result:

date

subject

type

rdfType

"2014-07-21T09:01:01Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/14

"ADDITION"

http://schema.semantic-web.at/ppt/history#LiteralAddRemoveHistoryEvent

"2014-07-21T09:01:01Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/14

"UPDATE"

http://schema.semantic-web.at/ppt/history#WorkflowAutoUpdateHistoryEvent

"2014-07-21T08:28:55Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/5

"UPDATE"

http://schema.semantic-web.at/ppt/history#WorkflowHistoryEvent

"2014-07-21T08:28:53Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/13

"UPDATE"

http://schema.semantic-web.at/ppt/history#WorkflowHistoryEvent

"2014-07-21T08:20:10Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/15

"UPDATE"

http://schema.semantic-web.at/ppt/history#WorkflowHistoryEvent

"2014-07-21T08:12:46Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/15

"ADDITION"

http://schema.semantic-web.at/ppt/history#ResourceChangeHistoryEvent

"2014-07-21T08:12:46Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/5

"ADDITION"

http://schema.semantic-web.at/ppt/history#RelationAddRemoveHistoryEvent

"2014-07-21T08:12:46Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/15

"ADDITION"

http://schema.semantic-web.at/ppt/history#RelationAddRemoveHistoryEvent

"2014-07-21T08:12:46Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/15

"ADDITION"

http://schema.semantic-web.at/ppt/history#WorkflowHistoryEvent

"2014-07-18T15:11:37Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/14

"UPDATE"

http://schema.semantic-web.at/ppt/history#WorkflowHistoryEvent

Find out concept changes in a specific time frame

A variant of the query could filter based on a time delta.

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX changeset:<http://purl.org/vocab/changeset/schema#>
SELECT ?date ?subject ?type ?rdfType
WHERE {
  GRAPH <http://<baseUrl>/<projectId>/thesaurus/history> {
   ?s changeset:subjectOfChange ?subject .
   ?s changeset:changeType ?type .
   ?s changeset:createdDate ?date .
   ?s rdf:type ?rdfType .
   FILTER (?date >= "2014-07-21T00:00:00Z"^^xsd:dateTime &&
                  ?date <= "2014-07-21T10:00:00Z"^^xsd:dateTime )
  }
}
ORDER BY DESC(?date) 

Query result

SPARQL query to collect deleted concepts from History

PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX changeset:<http://purl.org/vocab/changeset/schema#>
PREFIX swchistory:<http://schema.semantic-web.at/ppt/history#>
SELECT ?date (?subject AS ?deletedConcept) ?label
WHERE {
  GRAPH <http://<baseUrl>/<projectId>/thesaurus/history> {
   ?s changeset:subjectOfChange ?subject .
   ?s changeset:changeType ?type .
   ?s changeset:createdDate ?date .
   ?s rdf:type ?rdfType .
   FILTER (?rdfType = swchistory:ResourceChangeHistoryEvent &&
           ?type = "REMOVAL" )
  }
  ?subject rdfs:label ?label .
} ORDER BY DESC(?date)

Query result

date

deletedConcept

label

"2014-07-22T08:11:37Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/6

"Berlin"@en

"2014-07-18T14:46:25Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/10

"Vienna"@en

"2014-07-18T14:45:23Z"^^

http://vocabulary.semantic-web.at/GeographicThesaurus/11

"Paris"@en

SPARQL query to collect label changes

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX changeset:<http://purl.org/vocab/changeset/schema#>
PREFIX swchistory:<http://schema.semantic-web.at/ppt/history#>
SELECT DISTINCT ?date (?subject AS ?concept) ?changeType ?predicate ?affectedLabel
WHERE {
  GRAPH <http://<baseUrl>/<projectId>/thesaurus/history> {
   ?s changeset:subjectOfChange ?subject .
   ?s changeset:createdDate ?date .
   ?s swchistory:affectedLiteral|swchistory:value ?affectedLabel .
   ?s swchistory:predicate ?predicate .
   ?s changeset:changeType ?changeType .
   ?s rdf:type ?rdfType .
   FILTER(?rdfType IN (swchistory:LiteralAddRemoveHistoryEvent , swchistory:LiteralUpdateHistoryEvent ))
  }
}
ORDER BY DESC(?date) LIMIT 100

Query result