-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataAccess.php
129 lines (113 loc) · 5.15 KB
/
dataAccess.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
require_once("sparqllib.php");
class DataAccess {
private $db;
private $endpoint = "http://lod.cedar-project.nl:8080/sparql/cedar";
private $result;
function __construct() {
$this->db = sparql_connect($this->endpoint);
if (!$this->db ) {
print sparql_errno() . ": " . sparql_error(). "\n";
exit;
}
$this->initializeNamespaces();
}
function initializeNamespaces() {
sparql_ns("d2s", "http://www.data2semantics.org/core/");
sparql_ns("cd", "http://www.data2semantics.org/data/BRT_1889_08_T1_marked/Tabel_1/");
sparql_ns("ns1", "http://www.data2semantics.org/core/Tabel_1/");
sparql_ns("skos", "http://www.w3.org/2004/02/skos/core#");
}
function executeQuery($params, $target) {
switch ($target) {
case "population":
$groupby = "";
$gender = "";
$marital = "";
if (sizeof($params["gender"]) > 1) {
$groupby = "d2s:populationSize";
} else {
$groupby = "cd:".$params["gender"][0];
}
foreach ($params["gender"] as $param) {
$gender .= "cd:$param,";
}
$gender = rtrim($gender, ",");
foreach ($params["marital"] as $param) {
$marital .= "cd:$param,";
}
$marital = rtrim($marital, ",");
$sparql = "SELECT SUM(?population)
FROM <http://lod.cedar-project.nl/resource/BRT_1889_08_T1>
WHERE {
?cell d2s:isObservation [ d2s:dimension ?gender ;
d2s:dimension ?marital_status ;
d2s:dimension ?age ;
ns1:BENAMING_van_de_onderdeelen_der_onderscheidene_beroepsklassen__met_de_daartoe_behoordende_beroepen ?occupation ;
d2s:populationSize ?population ] .
OPTIONAL {
?cell d2s:isObservation [ns1:Positie_in_het_beroep__aangeduid_met_A__B__C_of_D_ ?position] .
?position skos:prefLabel ?position_s .
}
?occupation skos:broader ?occ_subclass .
?occ_subclass skos:broader ?occ_class .
?occ_class skos:broader ?municipality .
?municipality skos:prefLabel ?municipality_s .
?occ_class skos:prefLabel ?occ_class_s .
?occ_subclass skos:prefLabel ?occ_subclass_s .
?cell d2s:cell ?cell_s .
?age skos:prefLabel ?age_s .
?gender skos:prefLabel ?gender_s .
?marital_status skos:prefLabel ?marital_status_s .
?occupation skos:prefLabel ?occupation_s .
FILTER (?gender IN ($gender))
FILTER (?marital_status IN ($marital))
FILTER (?age IN (cd:12___1878, cd:13___1876, cd:14_---_15__1875___---_1874, cd:16_---_17__1873___---_1872, cd:1878_en_later__beneden_12_j_, cd:18_---_22__1871___---_1867, cd:Geboortejaren___leeftijd_in_j_, cd:25_---_35__1864___---_1854, cd:36_---_50__1853___---_1839, cd:51_---_60__1838___---_1829, cd:61_---_65__1828___---_1824, cd:66_---_70__1823_---_1818, cd:71_en_daarboven__1818_en_vroeger, cd:Van_onbekenden_leeftijd, cd:23_---_24__1866___---_1865))
} GROUP BY ($groupby) LIMIT 100";
break;
default:
$sparql = "SELECT DISTINCT (str(?age_s) AS ?age_c) (str(?gender_s) AS ?gender_c) (str(?marital_status_s) AS ?marital_status_c) (str(?municipality_s) AS ?municipality_c) (str(?occ_class_s) AS ?occ_class_c) (str(?occ_subclass_s) AS ?occ_subclass_c) (str(?occupation_s) AS ?occupation_c) ?occupation (REPLACE(?position_s, \"^ +| +$\", \"\") AS ?position_c) ?population
FROM <http://lod.cedar-project.nl/resource/BRT_1889_08_T1>
WHERE {
?cell d2s:isObservation [ d2s:dimension ?gender ;
d2s:dimension ?marital_status ;
d2s:dimension ?age ;
ns1:BENAMING_van_de_onderdeelen_der_onderscheidene_beroepsklassen__met_de_daartoe_behoordende_beroepen ?occupation ;
d2s:populationSize ?population ] .
OPTIONAL {
?cell d2s:isObservation [ns1:Positie_in_het_beroep__aangeduid_met_A__B__C_of_D_ ?position] .
?position skos:prefLabel ?position_s .
}
?occupation skos:broader ?occ_subclass .
?occ_subclass skos:broader ?occ_class .
?occ_class skos:broader ?municipality .
?municipality skos:prefLabel ?municipality_s .
?occ_class skos:prefLabel ?occ_class_s .
?occ_subclass skos:prefLabel ?occ_subclass_s .
?cell d2s:cell ?cell_s .
?age skos:prefLabel ?age_s .
?gender skos:prefLabel ?gender_s .
?marital_status skos:prefLabel ?marital_status_s .
?occupation skos:prefLabel ?occupation_s .
FILTER (?gender IN (cd:$params[0]))
FILTER (?marital_status IN (cd:O, cd:G))
FILTER (?age IN (cd:12___1878, cd:13___1876, cd:14_---_15__1875___---_1874, cd:16_---_17__1873___---_1872, cd:1878_en_later__beneden_12_j_, cd:18_---_22__1871___---_1867, cd:Geboortejaren___leeftijd_in_j_, cd:25_---_35__1864___---_1854, cd:36_---_50__1853___---_1839, cd:51_---_60__1838___---_1829, cd:61_---_65__1828___---_1824, cd:66_---_70__1823_---_1818, cd:71_en_daarboven__1818_en_vroeger, cd:Van_onbekenden_leeftijd, cd:23_---_24__1866___---_1865))
} ORDER BY (?cell)";
}
$this->result = sparql_query( $sparql );
if (!$this->result) {
print sparql_errno() . ": " . sparql_error(). "\n";
exit;
}
}
function getResultFields() {
return sparql_field_array($this->result);
}
function getResultNumRows() {
return sparql_num_rows($this->result);
}
function getResultArray() {
return sparql_fetch_array($this->result);
}
}
?>