You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.5 KiB

#!/usr/bin/php
<?php
$tag2link = array();
$files = array('data/tag2link-wikidata.json', 'data/tag2link-sophox.json');
foreach ($files as $file) {
$data = json_decode(file_get_contents($file), true);
foreach ($data['results']['bindings'] as $entry) {
$key = substr($entry['OSM_key']['value'], 4);
$link = $entry['formatter_URL']['value'];
if (array_key_exists($key, $tag2link)) {
// avoid duplicates
$duplicates = array_filter($tag2link[$key]['formatter'], function ($e) use ($link) {
return $e['link'] === $link;
});
if (sizeof($duplicates)) {
if (array_key_exists('operatorLabel', $entry)) {
foreach ($duplicates as $i => $d) {
$tag2link[$key]['formatter'][$i]['operator'] = $entry['operatorLabel']['value'];
}
}
continue;
}
}
else {
$tag2link[$key] = array(
'label' => $entry['itemLabel']['value'],
'formatter' => array(),
);
}
$formatter = array(
'link' => $link,
);
if (array_key_exists('operatorLabel', $entry)) {
$formatter['operator'] = $entry['operatorLabel']['value'];
print "{$formatter['operator']}\n";
}
else if (preg_match("/^https?:\/\/([^\/]*)(\/.*|)$/", $link, $m)) {
$formatter['operator'] = $m[1];
}
$tag2link[$key]['formatter'][] = $formatter;
}
}
file_put_contents('dist/tag2link.json', json_encode($tag2link, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE));