Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crstn/6131797 to your computer and use it in GitHub Desktop.
Save crstn/6131797 to your computer and use it in GitHub Desktop.
Demo for point in time data in HXL. See comments below for a how-to.
prefix hxl: <http://hxl.humanitarianresponse.info/ns/#>
SELECT ?population ?count ?date
WHERE {
GRAPH ?g {
?population hxl:personCount ?count .
?g hxl:validOn ?date .
}
} ORDER BY ?population DESC(?date)
prefix hxl: <http://hxl.humanitarianresponse.info/ns/#>
SELECT ?population ?count (MAX(?date) as ?lastCountDate)
WHERE {
GRAPH ?g {
?population hxl:personCount ?count .
?g hxl:validOn ?date .
}
} GROUP BY ?population
population count date
http://hxl.humanitarianresponse.info/data/idp/test 7700 2013-07-01
http://hxl.humanitarianresponse.info/data/idp/test 9800 2013-06-01
http://hxl.humanitarianresponse.info/data/idp/test 9000 2013-05-01
http://hxl.humanitarianresponse.info/data/idp/test 7000 2013-04-01
http://hxl.humanitarianresponse.info/data/idp/test2 27700 2013-07-01
http://hxl.humanitarianresponse.info/data/idp/test2 19800 2013-06-01
http://hxl.humanitarianresponse.info/data/idp/test2 15900 2013-05-01
http://hxl.humanitarianresponse.info/data/idp/test2 13400 2013-04-01
population count lastCountDate
http://hxl.humanitarianresponse.info/data/idp/test2 27700 2013-07-01
http://hxl.humanitarianresponse.info/data/idp/test 7700 2013-07-01
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-04-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#personCount> "7000" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306191> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-05-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#personCount> "9000" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306192> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-06-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#personCount> "9800" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306193> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-07-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#personCount> "7700" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/idp/test> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306194> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-04-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#personCount> "13400" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306195> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-05-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#personCount> "15900" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306196> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-06-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#personCount> "19800" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306197> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#DataContainer> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> <http://hxl.humanitarianresponse.info/ns/#validOn> "2013-07-01" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> <http://purl.org/dc/terms/date> "2013-07-31" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> <http://hxl.humanitarianresponse.info/ns/#comment> "Test data" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> <http://hxl.humanitarianresponse.info/ns/#reportedBy> <http://hxl.humanitarianresponse.info/data/persons/unocha/carsten_kessler> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://hxl.humanitarianresponse.info/ns/#IDP> <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#personCount> "27700" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
<http://hxl.humanitarianresponse.info/data/idp/test2> <http://hxl.humanitarianresponse.info/ns/#method> "Estimate" <http://hxl.humanitarianresponse.info/data/datacontainers/unocha/1375306198> .
@crstn
Copy link
Author

crstn commented Aug 1, 2013

Shows how to handle point in time data in HXL. The demo dataset is in n-quads notation and contains 4 different population counts on 4 different dates for 2 different populations of internally displaced populations. This adds up to 8 distinct counts, which are stored in a separate HXL data container (i.e., named graph) each. The metadata (such as the point in time at which the respective count was valid) is then attached to this data container.

To play around with this small dataset, load it into a triple store. I'm using 4store here because it is very quick to set up on a desktop. After setting it up, import the dataset via

4s-import -v demo -f nquads test.nq

and start the SPARQL server via

4s-httpd -p 8000 demo

You can then query the dataset via cURL à la

curl -H "Accept: text/csv" --data-urlencode "query=YOUR QUERY GOES HERE" http://localhost:8000/sparql/ > results.csv

which will save the server response in results.csv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment