bkaempgen

gdp_per_capita_experiment_prepared_gci_2015-09-07.df

Sep 7th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.45 KB | None | 0 0
  1. ######
  2. #Data-Fu Example Program
  3. ######
  4.  
  5. #Comments are marked with a leading #
  6. #The whole document has to be valid N3
  7.  
  8.  
  9. #Prefix declaration:
  10. @prefix http: <http://www.w3.org/2011/http#>.
  11. @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
  12. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  13. @prefix log: <http://www.w3.org/2000/10/swap/log#>.
  14. @prefix http_m: <http://www.w3.org/2011/http-methods#>.
  15. @prefix ex: <http://example.org/>.
  16. @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>.
  17. @prefix qrl: <http://www.aifb.kit.edu/project/ld-retriever/qrl#>.
  18. @prefix foaf: <http://xmlns.com/foaf/0.1/>.
  19. @prefix db: <http://dbpedia.org/resource/>.
  20. @prefix db-owl: <http://dbpedia.org/ontology/>.
  21. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
  22.  
  23. # QB and related
  24. @prefix sdmx-measure: <http://purl.org/linked-data/sdmx/2009/measure#> .
  25. @prefix qb: <http://purl.org/linked-data/cube#> .
  26. @prefix skosclass: <http://ddialliance.org/ontologies/skosclass#> .
  27. @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
  28. @prefix olap4ld: <http://example.org/olap4ld#> .
  29. @prefix cogs: <http://vocab.deri.ie/cogs#> .
  30.  
  31. # Domain-specific levels
  32. @prefix eurostat: <http://ontologycentral.com/2009/01/eurostat/ns#> .
  33. @prefix dic-geo: <http://estatwrap.ontologycentral.com/dic/geo#> .
  34. @prefix geo-vocab: <http://geovocab.org/spatial#> .
  35. @prefix ramon: <http://rdfdata.eionet.europa.eu/ramon/ontology/> .
  36.  
  37. #######
  38. #Rules for interaction with APIs
  39. #######
  40.  
  41. # First, we add possible datasets
  42.  
  43. #some RDF facts to start the program (could also be submitted via POST to /{engine name}/{program name})
  44. # GDP per capita - annual Data
  45. #<http://estatwrap.ontologycentral.com/id/nama_aux_gph#ds> rdf:type qb:DataSet.
  46. # GDP and main components - Current prices
  47. <http://estatwrap.ontologycentral.com/id/nama_gdp_c#ds> rdf:type qb:DataSet.
  48.  
  49. # Gross Domestic Product (GDP) per capita in Purchasing Power Standards (PPS)
  50. #<http://olap4ld.googlecode.com/git/OLAP4LD-trunk/tests/estatwrap/tec00114_ds.rdf#ds> rdf:type qb:DataSet.
  51. # Regional gross domestic product by NUTS 2 regions [tgs00003] (Estatwrap)
  52. #<http://estatwrap.ontologycentral.com/id/tgs00003#ds> rdf:type qb:DataSet.
  53. # Regional gross domestic product by NUTS 2 regions [tgs00003] (Eurostat LD)
  54. #<http://eurostat.linked-statistics.org/data/tgs00003> rdf:type qb:DataSet.
  55. # Population on 1 January by age and sex [demo_pjan] (Estatwrap)
  56. #<http://estatwrap.ontologycentral.com/id/demo_pjan#ds> rdf:type qb:DataSet.
  57. # Population on 1 January by age and sex [demo_pjan] (Eurostat LD)
  58. #<http://eurostat.linked-statistics.org/data/demo_pjan> rdf:type qb:DataSet.
  59. # Real GDP per Capita (real local currency units, various base years)
  60. #<http://worldbank.270a.info/dataset/GDPPCKN> rdf:type qb:DataSet.
  61.  
  62. # Manually retrieve data
  63. #{
  64. # _:head http:mthd http_m:GET ;
  65. # http:requestURI <http://127.0.0.1:8080/Data-Fu-Engine/datasets/nama_aux_gph_dsd.rdf> .
  66. #}
  67.  
  68. # Retrieve data from all datasets
  69.  
  70. {
  71. ?ds rdf:type qb:DataSet.
  72. } =>
  73. {
  74. _:head http:mthd http_m:GET.
  75. _:head http:requestURI ?ds.
  76. }.
  77.  
  78. # Retrieve DSD
  79.  
  80. {
  81. ?ds qb:structure ?dsd.
  82. } =>
  83. {
  84. _:head http:mthd http_m:GET.
  85. _:head http:requestURI ?dsd.
  86. }.
  87.  
  88. # ComponentSpecification
  89.  
  90. {
  91. ?x rdf:type qb:ComponentSpecification.
  92. } =>
  93. {
  94. _:head http:mthd http_m:GET.
  95. _:head http:requestURI ?x.
  96. }.
  97.  
  98. # Retrieve dimension properties
  99.  
  100. {
  101. ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension.
  102. } =>
  103. {
  104. _:head http:mthd http_m:GET.
  105. _:head http:requestURI ?dimension.
  106. }.
  107.  
  108. # Retrieve code lists
  109.  
  110. {
  111. ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?dimension qb:codeList ?codelist.
  112. } =>
  113. {
  114. _:head http:mthd http_m:GET.
  115. _:head http:requestURI ?codelist.
  116. }.
  117.  
  118. # Retrieve range
  119.  
  120. {
  121. ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?dimension rdfs:range ?range.
  122. } =>
  123. {
  124. _:head http:mthd http_m:GET.
  125. _:head http:requestURI ?range.
  126. }.
  127.  
  128. # Retrieve all codelist members
  129.  
  130. {
  131. ?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.
  132. } =>
  133. {
  134. _:head http:mthd http_m:GET.
  135. _:head http:requestURI ?x.
  136. }.
  137.  
  138. # Retrieve all range members
  139. # Problem: Before we have resolved member, we do not know that it is of type range. Therefore 1) domain/range reasoning 2) resolve actively
  140.  
  141. {
  142. ?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.
  143. } =>
  144. {
  145. _:head http:mthd http_m:GET.
  146. _:head http:requestURI ?x.
  147. }.
  148.  
  149. # Retrieve all members for dimensions
  150. # Problem: Retrieving members may lead to error since some ?y may be literal values. Thus, had to add general outgoing triple.
  151. {
  152. ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:dimension ?dimension. ?x ?dimension ?y. ?y ?anyproperty ?anypropertyvalue.
  153. } =>
  154. {
  155. _:head http:mthd http_m:GET.
  156. _:head http:requestURI ?y.
  157. }.
  158.  
  159. # XXX retrieve hierarchical code list members
  160.  
  161. # Retrieve measure properties
  162.  
  163. {
  164. ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:measure ?measure.
  165. } =>
  166. {
  167. _:head http:mthd http_m:GET.
  168. _:head http:requestURI ?measure.
  169. }.
  170.  
  171. # Retrieve attribute properties
  172.  
  173. {
  174. ?ds rdf:type qb:DataSet. ?ds qb:structure ?dsd. ?dsd qb:component ?component. ?component qb:attribute ?attribute.
  175. } =>
  176. {
  177. _:head http:mthd http_m:GET.
  178. _:head http:requestURI ?attribute.
  179. }.
  180.  
  181. # Observations
  182. # Problem: Retrieving single observations leads to endless requests, e.g., for Linked-Statistics since obs are no blank nodes
  183. #{
  184. # ?obs rdf:type qb:Observation.
  185. #} =>
  186. #{
  187. # _:head http:mthd http_m:GET.
  188. # _:head http:requestURI ?obs.
  189. #}.
  190.  
  191. # Slice
  192.  
  193. {
  194. ?x rdf:type qb:Slice.
  195. } =>
  196. {
  197. _:head http:mthd http_m:GET.
  198. _:head http:requestURI ?x.
  199. }.
  200.  
  201. # SliceKey
  202.  
  203. {
  204. ?x rdf:type qb:SliceKey.
  205. } =>
  206. {
  207. _:head http:mthd http_m:GET.
  208. _:head http:requestURI ?x.
  209. }.
  210.  
  211. # ObservationGroup
  212.  
  213. {
  214. ?x rdf:type qb:ObservationGroup.
  215. } =>
  216. {
  217. _:head http:mthd http_m:GET.
  218. _:head http:requestURI ?x.
  219. }.
  220.  
  221.  
  222. # Retrieve all same as links
  223. # 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.
  224.  
  225. #{
  226. # ?x owl:sameAs ?y.
  227. #} =>
  228. #{
  229. # _:head http:mthd http_m:GET.
  230. # _:head http:requestURI ?y.
  231. #}.
  232.  
  233. # Rules to normalise QB data
  234.  
  235. {
  236. ?x qb:observation ?o.
  237. } =>
  238. {
  239. ?o rdf:type qb:Observation.
  240. }.
  241.  
  242. {
  243. ?o qb:dataSet ?ds.
  244. } =>
  245. {
  246. ?o rdf:type qb:Observation.
  247. ?ds rdf:type qb:DataSet.
  248. }.
  249.  
  250. # XXX Slice norm
  251.  
  252. {
  253. ?cs qb:dimension ?p .
  254. } =>
  255. {
  256. ?cs qb:componentProperty ?p .
  257. ?p rdf:type qb:DimensionProperty .
  258. }.
  259.  
  260. {
  261. ?cs qb:measure ?p .
  262. } =>
  263. {
  264. ?cs qb:componentProperty ?p .
  265. ?p rdf:type qb:MeasureProperty .
  266. }.
  267.  
  268. {
  269. ?cs qb:attribute ?p .
  270. } =>
  271. {
  272. ?cs qb:componentProperty ?p .
  273. ?p rdf:type qb:AttributeProperty .
  274. }.
  275.  
  276. # XXX Push down attachement levels
  277.  
  278. # Rules for OWL/RDF reasoning?
  279.  
  280. # prp-dom
  281. #{
  282. # ?p rdfs:domain ?c . ?x ?p ?y .
  283. #} => {
  284. # ?x rdf:type ?c .
  285. #}.
  286.  
  287. # prp-rng
  288. # Needs to be formulated this way, since otherwise does not work for literal values
  289. #{
  290. # ?p rdfs:range ?c . ?x ?p ?y. ?y ?a ?b.
  291. #} => {
  292. # ?y rdf:type ?c.
  293. #}.
  294.  
  295. # specific reasoning (not needed, since takes very long and I create the hierarchies from observations
  296. #{
  297. # ?x <http://ontologycentral.com/2009/01/eurostat/ns#geo> ?y.
  298. #} => {
  299. # ?y rdf:type <http://rdfdata.eionet.europa.eu/ramon/ontology/NUTSRegion>.
  300. #}.
  301.  
  302. # Derived datasets
  303. # Example to use template to create new URIs
  304. # You can use data to fill in Uri templates as requestURI:
  305. # This rule uses all identified lat/long values from db-owl:Town entities to retrieve nearby places from geonames.
  306. # No. 3
  307. #{
  308. #?p rdf:type db-owl:Town.
  309. #?p geo:long ?long .
  310. #?p geo:lat ?lat .
  311. #} =>
  312. #{
  313. # _:head http:mthd http_m:GET ;
  314. # http:requestURI <http://km.aifb.kit.edu/services/geonameswrap/findNearby?lat={?lat}&lng={?long}> .
  315. #}.
  316.  
  317. # MIO_EUR2EUR (on schema level + with Linked Data service)
  318. #
  319. #{
  320. # ?dataset a qb:DataSet.
  321. # ?dataset qb:structure ?dsd.
  322. # ?dsd qb:component ?comp.
  323. # ?comp qb:dimension <http://ontologycentral.com/2009/01/eurostat/ns#unit>.
  324. #
  325. # # Previous dataset should have an observation that uses MIO_EUR.
  326. # ?obs1 qb:dataSet ?dataset.
  327. # ?obs1 <http://ontologycentral.com/2009/01/eurostat/ns#unit> <http://estatwrap.ontologycentral.com/dic/unit#MIO_EUR>.
  328. #
  329. #} =>
  330. #{
  331. # XXX: Should also include schema information.
  332. # _:head http:mthd http_m:GET ;
  333. # http:requestURI <http://141.52.218.13:8080/QB-Slicer/rest/mioeur2eur?dsUri={?dataset}> .
  334. #}.
  335.  
  336. # Rules to create abbreviations for multidimensional elements (to implement mapping from QB to olap4ld)
  337.  
  338. # XXX See experiment not small
  339.  
  340. # Define linked data cubes dataset (integrated global cube)
  341. # We do not explicitly create a global cube
  342. #olap4ld:globalcube rdf:type olap4ld:DataCube.
  343. #olap4ld:globalcube qb:structure olap4ld:globalcubeschema.
  344. #olap4ld:globalcubeschema qb:component olap4ld:globalcubeschemacomponentspecification.
  345.  
  346. #{
  347. # ?x rdf:type olap4ld:Dimension.
  348. #} =>
  349. #{
  350. # olap4ld:globalcubeschemacomponentspecification qb:dimension ?x.
  351. #}.
  352.  
  353. #{
  354. # ?x rdf:type olap4ld:Measure.
  355. #} =>
  356. #{
  357. # olap4ld:globalcubeschemacomponentspecification qb:measure ?x.
  358. #}.
  359.  
  360. # Rules to validate data, e.g., using QB integrity constraints
  361.  
  362. # IC-1. Unique DataSet
  363.  
  364. # Since limited expressivity (FILTER etc.), not possible, yet.
  365.  
  366. # 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
  367. # the needed lookups?
  368.  
  369. # Question, how do I see that all relevant data has been retrieved?
  370.  
  371. # Output of the data-fu program is defined with sparql queries (in N3 notation)
  372.  
  373. # Simply be asking the metadata queries
  374.  
  375. _:datacubes qrl:select ( ?cube ?schema );
  376. qrl:where {?cube qb:structure ?schema.} .
  377.  
  378. _:measures qrl:select ( ?cube ?schema ?measure );
  379. qrl:where {?cube qb:structure ?schema. ?schema qb:measure ?measure. } .
  380.  
  381. _:dimensions qrl:select ( ?cube ?schema ?dimension );
  382. qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. } .
  383.  
  384. _:hierarchies qrl:select ( ?cube ?schema ?dimension ?hierarchy );
  385. qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. } .
  386.  
  387. _:levels qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level );
  388. qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. } .
  389.  
  390. _:rolluplevels qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level ?rolluplevel );
  391. qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. ?level olap4ld:rolluplevel ?rolluplevel. } .
  392.  
  393. _:members qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level ?member );
  394. qrl:where {?cube qb:structure ?schema. ?schema qb:dimension ?dimension. ?dimension olap4ld:dimensionToHierarchy ?hierarchy. ?hierarchy olap4ld:hierarchyToLevel ?level. ?level olap4ld:levelToMember ?member. } .
  395.  
  396. _:rollupmembers qrl:select ( ?cube ?schema ?dimension ?hierarchy ?level ?member ?rollupmember );
  397. 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.} .
  398.  
  399. _:facts qrl:select ( ?fact ?cube );
  400. qrl:where {?fact qb:dataSet ?cube. } .
  401.  
  402. #saves all processed triples under /{engine}/{program name}/triples:
  403. #No. 7
  404. _:triples qrl:construct {?s ?p ?o . };
  405. qrl:where {?s ?p ?o . } .
  406.  
  407. # For documentation, see GDP per capita experiment
Advertisement
Add Comment
Please, Sign In to add comment