forked from AKSW/transform-bvl-pages-to-csv-file
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-files.php
More file actions
362 lines (315 loc) · 13.4 KB
/
create-files.php
File metadata and controls
362 lines (315 loc) · 13.4 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
/**
* This file creates a CSV file based on the different homepages about place information and
* their degree of access for disabled people. These homepages where created by the
* Behindertenverband Leipzig e.V (http://www.le-online.de/).
*
* The following implementation is a basic web scraper which analyses the HTML and tries to
* extract as much information as possible about the places. Used images (e.g. 1111.gif) are
* very helpful to determine exact thematical classification.
*/
require 'vendor/autoload.php';
setlocale(LC_CTYPE, 'de_DE.UTF-8');
/*
* Important variables
*/
$htmlPages = array(
'http://www.le-online.de/bildung.htm' => 'Bildung',
'http://www.le-online.de/dienst.htm' => 'Dienst',
'http://www.le-online.de/gast.htm' => 'Gastwirtschaft',
'http://www.le-online.de/gesund.htm' => 'Gesundheit',
'http://www.le-online.de/recht.htm' => 'Recht',
'http://www.le-online.de/verband.htm' => 'Verbände',
'http://www.le-online.de/verkehr.htm' => 'Verkehr'
);
$infoArray = array();
$matches = null;
$fileContentArray = array();
$key = 0;
$curl = new Curl\Curl();
// go through html pages, download and parse them to extract relevant information later on
foreach ($htmlPages as $url => $category) {
// use $url to ask for HTML to analyse later on
$curl->get($url);
// store HTML
$fileContent = $curl->response;
// create an array, based on HTML-areas separated by <h2> tags
// there was no other way to determine each place.
$fileContentArray = explode('<h2>', $fileContent);
// go through list of entries (created by split HTML by <h2> tags)
foreach ($fileContentArray as $a => $entry) {
$infoArray[++$key] = array();
// transform encoding to UTF-8
$entry = iconv('iso-8859-1', 'utf-8', $entry);
// remove <br> tags for better readability
$entry = str_replace('<br>', '', $entry);
/*
* title
*/
preg_match(
'/(.*)<\/h2>/si',
$entry,
$matches
);
if (isset($matches[1])) {
$title = $matches[1];
// search for <a name=""> </a> stuff and remove it
preg_match(
'/<a.*>(.*)<\/a>/si',
$title,
$matches
);
if (isset($matches[1])) {
$title = $matches[1];
}
$infoArray[$key]['title'] = fixTitle($title);
} else {
$infoArray[$key]['title'] = '';
}
/*
* street
*/
if ('Verkehr' != $category) {
$regex = '/\n([^<]*)([0-9]{5})([^\n]*)/si';
} else {
$regex = '/\n\s*[a-z]+(.*?)([0-9]{5})\s*([äöüßa-z\-\s]{0,})\n*/s';
}
$matches = array();
$return = preg_match(
$regex,
$entry,
$matches
);
$infoArray[$key]['street'] = '';
if (isset($matches[1])) {
$infoArray[$key]['street'] = fixStreet($matches[1]);
}
if (isset($matches[2])) {
$infoArray[$key]['street'] .= ' / '. fixStreet($matches[2]);
}
if (isset($matches[3])) {
$infoArray[$key]['street'] .= ' // '. fixStreet($matches[3]);
}
if (!isset($matches[1]) && !isset($matches[2]) && !isset($matches[3]) && 'Verkehr' != $category) {
unset($infoArray[$key]);
continue;
}
/*
* email
*/
preg_match(
'/E-Mail:\s*<a href="mailto:([a-z0-9\/\-\:\.#@]{0,})">[a-z0-9\/\-\:\.#@]{0,}<\/a>[\s|\n|<br>]{1}/mi',
$entry,
$matches
);
if (isset($matches[1])) {
$infoArray[$key]['email'] = $matches[1];
} else {
$infoArray[$key]['email'] = '';
}
/*
* webUrl
*/
preg_match(
'/Internet:\s*<a href="([a-z0-9\/\-\:\.#]{0,})">[a-z0-9\/\-\:\.#]{0,}<\/a>[\s|\n|<br>]{1}/mi',
$entry,
$matches
);
if (isset($matches[1])) {
$infoArray[$key]['webUrl'] = $matches[1];
} else {
$infoArray[$key]['webUrl'] = '';
}
/*
* phone
*/
preg_match(
'/Tel.:\s*(.*?)[,|\n]/si',
$entry,
$matches
);
if (isset($matches[1])) {
$infoArray[$key]['phone'] = strip_tags($matches[1]);
$infoArray[$key]['phone'] = preg_replace('/[\(\)]*/s', '', $infoArray[$key]['phone']);
} else {
$infoArray[$key]['phone'] = '';
}
/*
* notification
*/
preg_match(
'/Hinweise:(.*)<a name=/si',
$entry,
$matches
);
if (isset($matches[1])) {
$infoArray[$key]['notice'] = strip_tags($matches[1]);
$infoArray[$key]['notice'] = preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "\n\n", $infoArray[$key]['notice']);
} else {
$infoArray[$key]['notice'] = '';
}
/*
* support
*/
// entry area fully accessable for wheelchair users
if (false !== strpos($entry, '1111.gif')) {
$infoArray[$key]['entryArea-wheelchair-access'] = 'Zugang: ebenerdig (max. 3 cm) oder über Rampe mit <= 6% Steigung';
$infoArray[$key]['entryArea-wheelchair-doorWidth'] = '>= 90 cm';
$infoArray[$key]['entryArea-wheelchair-support'] = 'vollständig';
} else {
// entry area teilweisely accessable for wheelchair users
if (false !== strpos($entry, '2222.gif')) {
$infoArray[$key]['entryArea-wheelchair-access'] = 'maximal 1 Stufe oder über Rampe mit <= 12% Steigung';
$infoArray[$key]['entryArea-wheelchair-doorWidth'] = '>= 70 cm';
$infoArray[$key]['entryArea-wheelchair-support'] = 'teilweise';
} else {
$infoArray[$key]['entryArea-wheelchair-access'] = '';
$infoArray[$key]['entryArea-wheelchair-doorWidth'] = '';
$infoArray[$key]['entryArea-wheelchair-support'] = '';
}
}
// lift fully accessable for wheelchair users
if (false !== strpos($entry, '3333.gif')) {
$infoArray[$key]['lift-wheelchair-doorWidth'] = '>= 90cm';
$infoArray[$key]['lift-wheelchair-cageDepth'] = '>= 140cm';
$infoArray[$key]['lift-wheelchair-cageWidth'] = '>= 110cm';
$infoArray[$key]['lift-wheelchair-distanceFromGroundControlsOutsideInside'] = '70-115cm';
$infoArray[$key]['lift-wheelchair-support'] = 'ja';
$infoArray[$key]['lift-persons-available'] = 'vorhanden';
} else {
$infoArray[$key]['lift-wheelchair-doorWidth'] = '';
$infoArray[$key]['lift-wheelchair-cageDepth'] = '';
$infoArray[$key]['lift-wheelchair-cageWidth'] = '';
$infoArray[$key]['lift-wheelchair-distanceFromGroundControlsOutsideInside'] = '';
$infoArray[$key]['lift-wheelchair-support'] = '';
// lift for persons vorhanden
if (false !== strpos($entry, '4444.gif')) {
$infoArray[$key]['lift-persons-available'] = 'vorhanden';
} else {
$infoArray[$key]['lift-persons-available'] = '';
}
}
// WC fully accessable for wheelchair users
if (false !== strpos($entry, '5555.gif')) {
$infoArray[$key]['toilets-wheelchair-noSteps'] = 'ja';
$infoArray[$key]['toilets-wheelchair-doorWidth'] = '';
$infoArray[$key]['toilets-wheelchair-spaceLeftOfWC'] = '>= 95cm';
$infoArray[$key]['toilets-wheelchair-spaceRightOfWC'] = '>= 95cm';
$infoArray[$key]['toilets-wheelchair-spaceBeforeWC'] = '>= Breite: 150cm, Tiefe: 150cm';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceLeftOfWCAvailable'] = 'ja';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceRightOfWCAvailable'] = 'ja';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceLeftOrRightOfWCAvailable'] = 'ja';
$infoArray[$key]['toilets-wheelchair-support'] = 'vollständig';
} else {
// WC partly accessable for wheelchair users
if (false !== strpos($entry, '6666.gif')) {
$infoArray[$key]['toilets-wheelchair-noSteps'] = '';
$infoArray[$key]['toilets-wheelchair-doorWidth'] = '>= 70cm';
$infoArray[$key]['toilets-wheelchair-spaceLeftOfWC'] = '>= 70cm';
$infoArray[$key]['toilets-wheelchair-spaceRightOfWC'] = '>= 70cm';
$infoArray[$key]['toilets-wheelchair-spaceBeforeWC'] = '>= Breite: 100cm, Tiefe: 100cm';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceLeftOfWCAvailable'] = '';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceRightOfWCAvailable'] = '';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceLeftOrRightOfWCAvailable'] = 'ja';
$infoArray[$key]['toilets-wheelchair-support'] = 'teilweise';
} else {
$infoArray[$key]['toilets-wheelchair-noSteps'] = '';
$infoArray[$key]['toilets-wheelchair-doorWidth'] = '';
$infoArray[$key]['toilets-wheelchair-spaceLeftOfWC'] = '';
$infoArray[$key]['toilets-wheelchair-spaceRightOfWC'] = '';
$infoArray[$key]['toilets-wheelchair-spaceBeforeWC'] = '';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceLeftOfWCAvailable'] = '';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceRightOfWCAvailable'] = '';
$infoArray[$key]['toilets-wheelchair-foldableHoldingDeviceLeftOrRightOfWCAvailable'] = '';
$infoArray[$key]['toilets-wheelchair-support'] = '';
}
}
// hearing impaired
if (false !== strpos($entry, '7777.gif')) {
$infoArray[$key]['hearingImpaired-support'] = 'vorhanden';
} else {
$infoArray[$key]['hearingImpaired-support'] = '';
}
// blind and teilweisely blind
if (false !== strpos($entry, 'aaaa.gif')) {
$infoArray[$key]['blindAndPartiallyBlind-support'] = 'vorhanden';
} else {
$infoArray[$key]['blindAndPartiallyBlind-support'] = '';
}
// parking lots for handicaped persons
if (false !== strpos($entry, '8888.gif')) {
$infoArray[$key]['parkingLotForHandicapedPersons-support'] = 'vorhanden';
} else {
$infoArray[$key]['parkingLotForHandicapedPersons-support'] = '';
}
// special or general support for handicaped persons
if (false !== strpos($entry, '9999.gif')) {
$infoArray[$key]['specialOrGeneralSupportForHandicapedPersons-support'] = 'vorhanden';
} else {
$infoArray[$key]['specialOrGeneralSupportForHandicapedPersons-support'] = '';
}
// category of the building
$infoArray[$key]['category'] = $category;
// remove entries which only have one entry, which means its usually something like:
// <a name="sport"> Sportanlagen </a></h2>
// <p></p><p></p>
if (2 > count($infoArray[$key])) {
echo 'ÜRKS - Eintrag '. $key .' gelöscht.';
unset($infoArray[$key]);
}
/**
* Exception handling of certain entries of Verkehr category, which will be kept
*/
$exceptionalEntries = array(
'Augustusplatz (Tiefgarage)',
'Augustusplatz (zwischen Gewandhaus und Moritzbastei, vor dem Park)',
'DRK Bahnhofsdienst',
'Flughafen Leipzig - Halle GmbH',
'Hauptbahnhof',
'Lotterstr. / Martin-Luther-Ring (Neues Rathaus)',
'Martin-Luther-Ring (Haupteingang Neues Rathaus)',
'Mobilitätszentrum am Hauptbahnhof',
'Neumarkt 1- 5 (Galeria Kaufhof)',
'Neumarkt 9 (Städtisches Kaufhaus)',
'Ökumenische Bahnhofsmission Leipzig',
'Osthalle Hauptbahnhof (Parkhaus)',
'Petersbogen (Parkhaus)',
'Service-Center des MDV und der Leipziger Stadtwerke',
'Westhalle Hauptbahnhof (Parkhaus)',
'Zentraler Bushalt - Hbf. Osthalle',
'ZOO (Parkhaus)',
);
if (!in_array($infoArray[$key]['title'], $exceptionalEntries) && 'Verkehr' == $category) {
unset($infoArray[$key]);
// replace HTML-shortcodes with real special signs (e.g. ü => ü)
} else {
foreach ($infoArray[$key] as $key2 => $value) {
$infoArray[$key][$key2] = str_replace(
array('ä', 'ö', 'ü', 'ß', 'ß'),
array('ä', 'ö', 'ü', 'ß', '&'),
$value
);
}
}
}
}
function fixTitle($s) {
$s=trim($s);
$s=str_replace('&','&',$s);
$s=str_replace('"','\"',$s);
$s=str_replace("\r",' ',$s);
$s=str_replace("\n",' ',$s);
return $s;
}
function fixStreet($s) {
$s=trim($s);
$s=strip_tags($s);
$s=str_replace('"','\"',$s);
$s=str_replace('Postanschrift:', '', $s);
return $s;
}
// Generate CSV file
//createCSVFile('le-online-extracted-places.csv', $infoArray);
// Generate RDF/n-triples file
//createRDFTurtleFile('le-online-extracted-places.nt', $infoArray);
createRDFTurtleFile('uhu.nt', $infoArray);