forked from AKSW/transform-bvl-pages-to-csv-file
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
197 lines (179 loc) · 6.69 KB
/
functions.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
use Saft\Data\SerializerFactoryImpl;
use Saft\Rdf\ArrayStatementIteratorImpl;
use Saft\Rdf\LiteralImpl;
use Saft\Rdf\NamedNodeImpl;
use Saft\Rdf\StatementImpl;
/**
* Unset empty array entries.
*
* @param array $array
* @return array
*/
function unsetEmptyEntry($array)
{
foreach ($array as $key => $entry) {
if (is_array($entry)) {
$array[$key] = unsetEmptyEntry($entry);
if (empty($array[$key])) {
unset($array[$key]);
}
} elseif (is_array($entry) && 0 == count($entry)) {
unset($array[$key]);
} elseif ('' == $entry || empty($entry)) {
unset($array[$key]);
}
}
if (is_array($array) && 0 == count($array)) {
return '';
} else {
return $array;
}
}
/**
* Generates CSV file
*
* @param string $filename
* @param array $infoArray
*/
function createCSVFile($filename, array $infoArray)
{
$infoArray = array_merge(array(array(
"Titel",
"Straße",
"E-Mail",
"Homepage",
"Telefonnummer",
"Hinweis",
"Eingangsbereich: Zugang",
"Eingangsbereich: Türbreite",
"Eingangsbereich: Rollstuhl geeignet",
"Aufzug: Türbreite",
"Aufzug: Kabinen-Tiefe",
"Aufzug: Kabinen-Breite",
"Aufzug: Höhe der Bedienelemente außen, innen",
"Aufzug: Rollstuhl-geeignet",
"Aufzug: vorhanden?",
"Behinderten-Toilette: stufenlos erreichbar",
"Behinderten-Toilette: Türbreite",
"Behinderten-Toilette: Platz links vom WC",
"Behinderten-Toilette: Platz rechts vom WC",
"Behinderten-Toilette: Platz vor dem WC",
"Behinderten-Toilette: Stützgriffe links klappbar",
"Behinderten-Toilette: Stützgriffe rechts klappbar",
"Behinderten-Toilette: Stützgriffe links oder rechts klappbar",
"Behinderten-Toilette: Rollstuhl geeignet",
"Hilfen für hörgeschädigte Menschen",
"Hilfen für blinde oder sehbehinderte Menschen",
"Markierte Behindertenparkplätze sind vorhanden ",
"Spezielle und persönliche Hilfeleistungen für Menschen mit Behinderungen",
"Kategorie"
)), $infoArray);
$file = fopen($filename, 'w');
foreach ($infoArray as $key => $value) {
fputcsv(
$file,
str_replace(
array('ä', 'ö', 'ü', 'ß', 'ß'),
array('ä', 'ö', 'ü', 'ß', '&'),
$value
),
',', // delimiter
'"' // surrounds a datafield
);
}
fclose($file);
echo 'CSV-file '. $filename .' with '. $key .' entries created.' . PHP_EOL;
}
/**
* Generates RDF/Turtle file
*
* @param string $filename
* @param array $infoArray
*/
function createRDFTurtleFile($filename, array $infoArray)
{
$stmtArray = array();
$bvlRootUrl = 'http://le-online.de/place/';
$bvlNamespaceUrl = 'http://le-online.de/ontology/place/ns#';
foreach ($infoArray as $placeEntry) {
/*
* generate good title for the URL later on (URL encoded, but still human readable)
*/
$placeUri = createGoodURIKonrad($placeEntry['title']);
$placeUria = createGoodURIHGG($placeEntry['title']);
$placeUri = $bvlRootUrl . str_replace(array('&', ), array('-and-',), $placeUri);
// title
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'hggURI'),
new LiteralImpl($placeUria)
);
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'placeName'),
new LiteralImpl($placeEntry['title'])
);
// address information
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'address'),
new LiteralImpl(preg_replace('/\s\s+/', ' ', $placeEntry['street']))
);
// lift infos
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'lift-available'),
new LiteralImpl('vorhanden' == $placeEntry['lift-persons-available'] ? 'yes' : 'no')
);
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'lift-liftWithWheelChairSupportAvailable'),
new LiteralImpl('ja' == $placeEntry['lift-wheelchair-support'] ? 'yes' : 'no')
);
// toilett
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'toilets-toiletForDisabledPeopleAvailable'),
new LiteralImpl('' != $placeEntry['toilets-wheelchair-support'] ? 'yes' : 'no')
);
// parking slot
$stmtArray[] = new StatementImpl(
new NamedNodeImpl($placeUri),
new NamedNodeImpl($bvlNamespaceUrl . 'parkingLot-lotsForDisabledPeopleAvailable'),
new LiteralImpl('vorhanden' == $placeEntry['parkingLotForHandicapedPersons-support'] ? 'yes' : 'no')
);
}
// serialize statement array to n-triples and store it as file
$serializerFactory = new SerializerFactoryImpl();
$serializer = $serializerFactory->createSerializerFor('n-triples');
$serializer->serializeIteratorToStream(
new ArrayStatementIteratorImpl($stmtArray),
__DIR__ . '/'. $filename
);
echo 'N-Triples file '. $filename .' with '. count($stmtArray) .' triples created.' . PHP_EOL;
}
function createGoodURIKonrad($name) { // Originalversion
return str_replace(
array(
' ', 'ß', 'ä', 'ü', 'ö', 'ö', '<br-/>', 'ü', 'ä', 'ö', '"', 'eacute;', '/',
'ouml;', 'auml;', 'uuml;', ',', "'", '>', '<', '`', '´', '\\'
),
array(
'-', 'ss', 'ae', 'ue', 'oe', 'oe', '', 'ue', 'ae', 'oe', '', 'e', '_',
'oe', 'ae', 'ue', '-', '_', '-', '-', '-', '-', ''
),
strtolower(trim(preg_replace('/\s\s+/', ' ', $name)))
);
}
function createGoodURIHGG($name) { // Originalversion
$name=strtolower(trim(preg_replace('/\s\s+/', '', $name)));
$name=str_replace(
array('ß', 'ä', 'ü', 'ö', 'ö', '<br-/>', 'ü', 'ä', 'ö', 'eacute;',
'ouml;', 'auml;', 'uuml;', '\\'),
array('ss', 'ae', 'ue', 'oe', 'oe', '', 'ue', 'ae', 'oe', 'e',
'oe', 'ae', 'ue' , '' ),
$name);
$name=preg_replace('/\W/', '', $name);
return $name;
}