Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######
- #Data-Fu Example Program
- ######
- #Comments are marked with a leading #
- #The whole document has to be valid N3
- #Prefix declaration:
- @prefix http: <http://www.w3.org/2011/http#>.
- @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
- @prefix owl: <http://www.w3.org/2002/07/owl#>.
- @prefix log: <http://www.w3.org/2000/10/swap/log#>.
- @prefix http_m: <http://www.w3.org/2011/http-methods#>.
- @prefix ex: <http://example.org/>.
- @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>.
- @prefix qrl: <http://www.aifb.kit.edu/project/ld-retriever/qrl#>.
- @prefix foaf: <http://xmlns.com/foaf/0.1/>.
- @prefix db: <http://dbpedia.org/resource/>.
- @prefix db-owl: <http://dbpedia.org/ontology/>.
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
- # QB and related
- @prefix sdmx-measure: <http://purl.org/linked-data/sdmx/2009/measure#> .
- @prefix qb: <http://purl.org/linked-data/cube#> .
- @prefix skosclass: <http://ddialliance.org/ontologies/skosclass#> .
- @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
- @prefix olap4ld: <http://example.org/olap4ld#> .
- @prefix cogs: <http://vocab.deri.ie/cogs#> .
- # Domain-specific levels
- @prefix eurostat: <http://ontologycentral.com/2009/01/eurostat/ns#> .
- @prefix dic-geo: <http://estatwrap.ontologycentral.com/dic/geo#> .
- @prefix geo-vocab: <http://geovocab.org/spatial#> .
- @prefix ramon: <http://rdfdata.eionet.europa.eu/ramon/ontology/> .
- #######
- #Rules for interaction with APIs
- #######
- # First, we add possible datasets
- #some RDF facts to start the program (could also be submitted via POST to /{engine name}/{program name})
- # GDP per capita - annual Data
- #<http://estatwrap.ontologycentral.com/id/nama_aux_gph#ds> rdf:type qb:DataSet.
- # GDP and main components - Current prices
- <http://estatwrap.ontologycentral.com/id/nama_gdp_c#ds> rdf:type qb:DataSet.
- # Gross Domestic Product (GDP) per capita in Purchasing Power Standards (PPS)
- #<http://olap4ld.googlecode.com/git/OLAP4LD-trunk/tests/estatwrap/tec00114_ds.rdf#ds> rdf:type qb:DataSet.
- # Regional gross domestic product by NUTS 2 regions [tgs00003] (Estatwrap)
- #<http://estatwrap.ontologycentral.com/id/tgs00003#ds> rdf:type qb:DataSet.
- # Regional gross domestic product by NUTS 2 regions [tgs00003] (Eurostat LD)
- #<http://eurostat.linked-statistics.org/data/tgs00003> rdf:type qb:DataSet.
- # Population on 1 January by age and sex [demo_pjan] (Estatwrap)
- #<http://estatwrap.ontologycentral.com/id/demo_pjan#ds> rdf:type qb:DataSet.
- # Population on 1 January by age and sex [demo_pjan] (Eurostat LD)
- #<http://eurostat.linked-statistics.org/data/demo_pjan> rdf:type qb:DataSet.
- # Real GDP per Capita (real local currency units, various base years)
- #<http://worldbank.270a.info/dataset/GDPPCKN> rdf:type qb:DataSet.
- # Manually retrieve data
- #{
- # _:head http:mthd http_m:GET ;
- # http:requestURI <http://127.0.0.1:8080/Data-Fu-Engine/datasets/nama_aux_gph_dsd.rdf> .
- #}
- # Retrieve data from all datasets
- {
- ?ds rdf:type qb:DataSet.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?ds.
- }.
- # Retrieve DSD
- {
- ?ds qb:structure ?dsd.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?dsd.
- }.
- # ComponentSpecification
- {
- ?x rdf:type qb:ComponentSpecification.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?x.
- }.
- # Retrieve dimension properties
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?dimension.
- }.
- # Retrieve code lists
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?dimension qb:codeList ?codelist.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?codelist.
- }.
- # Retrieve range
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?dimension rdfs:range ?range.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?range.
- }.
- # Retrieve all codelist members
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?dimension qb:codeList ?codelist. ?x skos:inScheme ?codelist.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?x.
- }.
- # Retrieve all range members
- # Problem: Before we have resolved member, we do not know that it is of type range. Therefore 1) domain/range reasoning 2) resolve actively
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?dimension rdfs:range ?range. ?x rdf:type ?range.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?x.
- }.
- # Retrieve all members for dimensions
- # Problem: Retrieving members may lead to error since some ?y may be literal values. Thus, had to add general outgoing triple.
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?x ?dimension ?y. ?y ?anyproperty ?anypropertyvalue.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?y.
- }.
- # XXX retrieve hierarchical code list members
- # Retrieve measure properties
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:measure ?measure.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?measure.
- }.
- # Retrieve attribute properties
- {
- ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:attribute ?attribute.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?attribute.
- }.
- # Observations
- # Problem: Retrieving single observations leads to endless requests, e.g., for Linked-Statistics since obs are no blank nodes
- #{
- # ?obs rdf:type qb:Observation.
- #} =>
- #{
- # _:head http:mthd http_m:GET.
- # _:head http:requestURI ?obs.
- #}.
- # Slice
- {
- ?x rdf:type qb:Slice.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?x.
- }.
- # SliceKey
- {
- ?x rdf:type qb:SliceKey.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?x.
- }.
- # ObservationGroup
- {
- ?x rdf:type qb:ObservationGroup.
- } =>
- {
- _:head http:mthd http_m:GET.
- _:head http:requestURI ?x.
- }.
- # Retrieve all same as links
- # Problem: Retrieving all sameAs links results in endless retrieval, probably because of recursive crawling. Instead, we should crawl for specific sameAs links only and also consider other equivalent representations such as skos:exactMatch and owl:equivalentProperty.
- #{
- # ?x owl:sameAs ?y.
- #} =>
- #{
- # _:head http:mthd http_m:GET.
- # _:head http:requestURI ?y.
- #}.
- # Rules to normalise QB data
- {
- ?x qb:observation ?o.
- } =>
- {
- ?o rdf:type qb:Observation.
- }.
- {
- ?o qb:dataSet ?ds.
- } =>
- {
- ?o rdf:type qb:Observation.
- ?ds rdf:type qb:DataSet.
- }.
- # XXX Slice norm
- {
- ?cs qb:dimension ?p .
- } =>
- {
- ?cs qb:componentProperty ?p .
- ?p rdf:type qb:DimensionProperty .
- }.
- {
- ?cs qb:measure ?p .
- } =>
- {
- ?cs qb:componentProperty ?p .
- ?p rdf:type qb:MeasureProperty .
- }.
- {
- ?cs qb:attribute ?p .
- } =>
- {
- ?cs qb:componentProperty ?p .
- ?p rdf:type qb:AttributeProperty .
- }.
- # XXX Push down attachement levels
- # Rules for OWL/RDF reasoning?
- # prp-dom
- #{
- # ?p rdfs:domain ?c . ?x ?p ?y .
- #} => {
- # ?x rdf:type ?c .
- #}.
- # prp-rng
- # Needs to be formulated this way, since otherwise does not work for literal values
- #{
- # ?p rdfs:range ?c . ?x ?p ?y. ?y ?a ?b.
- #} => {
- # ?y rdf:type ?c.
- #}.
- # specific reasoning (not needed, since takes very long and I create the hierarchies from observations
- #{
- # ?x <http://ontologycentral.com/2009/01/eurostat/ns#geo> ?y.
- #} => {
- # ?y rdf:type <http://rdfdata.eionet.europa.eu/ramon/ontology/NUTSRegion>.
- #}.
- # Derived datasets
- # Example to use template to create new URIs
- # You can use data to fill in Uri templates as requestURI:
- # This rule uses all identified lat/long values from db-owl:Town entities to retrieve nearby places from geonames.
- # No. 3
- #{
- #?p rdf:type db-owl:Town.
- #?p geo:long ?long .
- #?p geo:lat ?lat .
- #} =>
- #{
- # _:head http:mthd http_m:GET ;
- # http:requestURI <http://km.aifb.kit.edu/services/geonameswrap/findNearby?lat={?lat}&lng={?long}> .
- #}.
- # MIO_EUR2EUR (on schema level + with Linked Data service)
- #
- #{
- # ?dataset a qb:DataSet.
- # ?dataset qb:structure ?dsd.
- # ?dsd qb:component ?comp.
- # ?comp qb:dimension <http://ontologycentral.com/2009/01/eurostat/ns#unit>.
- #
- # # Previous dataset should have an observation that uses MIO_EUR.
- # ?obs1 qb:dataSet ?dataset.
- # ?obs1 <http://ontologycentral.com/2009/01/eurostat/ns#unit> <http://estatwrap.ontologycentral.com/dic/unit#MIO_EUR>.
- #
- #} =>
- #{
- # XXX: Should also include schema information.
- # _:head http:mthd http_m:GET ;
- # http:requestURI <http://141.52.218.13:8080/QB-Slicer/rest/mioeur2eur?dsUri={?dataset}> .
- #}.
- # Rules to create abbreviations for multidimensional elements (to implement mapping from QB to olap4ld)
- # XXX See experiment not small
- # Define linked data cubes dataset (integrated global cube)
- # We do not explicitly create a global cube
- #olap4ld:globalcube rdf:type olap4ld:DataCube.
- #olap4ld:globalcube qb:structure olap4ld:globalcubeschema.
- #olap4ld:globalcubeschema qb:component olap4ld:globalcubeschemacomponentspecification.
- #{
- # ?x rdf:type olap4ld:Dimension.
- #} =>
- #{
- # olap4ld:globalcubeschemacomponentspecification qb:dimension ?x.
- #}.
- #{
- # ?x rdf:type olap4ld:Measure.
- #} =>
- #{
- # olap4ld:globalcubeschemacomponentspecification qb:measure ?x.
- #}.
- # Rules to validate data, e.g., using QB integrity constraints
- # IC-1. Unique DataSet
- # Since limited expressivity (FILTER etc.), not possible, yet.
- # Anyway, rules can only be applied to a fully loaded cube. Thus, we would need to first fully load all datasets and possibly derive from there
- # the needed lookups?
- # Question, how do I see that all relevant data has been retrieved?
- # Output of the data-fu program is defined with sparql queries (in N3 notation)
- # Simply be asking the metadata queries
- _:datacubes qrl:select ( ?cube ?schema );
- qrl:where {?cube qb:structure ?schema.} .
- _:measures qrl:select ( ?cube ?schema ?measure );
- qrl:where {?cube qb:structure ?schema. ?schema qb:measure ?measure. } .
- _:dimensions qrl:select ( ?cube ?schema ?dimension );
- qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. } .
- _:hierarchies qrl:select ( ?cube ?schema ?dimension ?hierarchy );
- qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. } .
- _:levels qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level );
- qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. } .
- _:rolluplevels qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level ?rolluplevel );
- qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. ?level olap4ld:rolluplevel ?rolluplevel. } .
- _:members qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level ?member );
- qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. ?level olap4ld:levelToMember ?member. } .
- _:rollupmembers qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level ?member ?rollupmember );
- qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. ?level olap4ld:levelToMember ?member. ?member olap4ld:rollupmember ?rollupmember.} .
- _:facts qrl:select ( ?fact ?cube );
- qrl:where {?fact qb:dataSet ?cube. } .
- #saves all processed triples under /{engine}/{program name}/triples:
- #No. 7
- _:triples qrl:construct {?s ?p ?o . };
- qrl:where {?s ?p ?o . } .
- # For documentation, see GDP per capita experiment
Advertisement
Add Comment
Please, Sign In to add comment