3 require_once(CONST_LibDir.'/init-cmd.php');
4 ini_set('memory_limit', '800M');
5 ini_set('display_errors', 'stderr');
9 'Import and export special phrases',
10 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
11 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
12 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
13 array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
15 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
19 include(getSettingConfig('PHRASE_CONFIG', 'phrase_settings.php'));
21 if ($aCMDResult['wiki-import']) {
22 $oNormalizer = Transliterator::createFromRules(getSetting('TERM_NORMALIZATION'));
25 $sLanguageIn = getSetting(
27 'af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'.
28 'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi';
31 foreach (explode(',', $sLanguageIn) as $sLanguage) {
32 $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
33 $sWikiPageXML = file_get_contents($sURL);
36 '#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#',
44 foreach ($aMatches as $aMatch) {
45 $sLabel = trim($aMatch[1]);
46 if ($oNormalizer !== null) {
47 $sTrans = pg_escape_string($oNormalizer->transliterate($sLabel));
51 $sClass = trim($aMatch[2]);
52 $sType = trim($aMatch[3]);
53 // hack around a bug where building=yes was imported with
54 // quotes into the wiki
55 $sType = preg_replace('/("|")/', '', $sType);
56 // sanity check, in case somebody added garbage in the wiki
57 if (preg_match('/^\\w+$/', $sClass) < 1
58 || preg_match('/^\\w+$/', $sType) < 1
60 trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
63 // blacklisting: disallow certain class/type combinations
64 if (isset($aTagsBlacklist[$sClass]) && in_array($sType, $aTagsBlacklist[$sClass])) {
65 // fwrite(STDERR, "Blacklisted: ".$sClass."/".$sType."\n");
68 // whitelisting: if class is in whitelist, allow only tags in the list
69 if (isset($aTagsWhitelist[$sClass]) && !in_array($sType, $aTagsWhitelist[$sClass])) {
70 // fwrite(STDERR, "Non-Whitelisted: ".$sClass."/".$sType."\n");
73 $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
75 switch (trim($aMatch[4])) {
78 "SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'near');\n",
79 pg_escape_string($sLabel),
87 "SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'in');\n",
88 pg_escape_string($sLabel),
96 "SELECT getorcreate_amenity(make_standard_name('%s'), '%s', '%s', '%s');\n",
97 pg_escape_string($sLabel),
107 echo 'CREATE INDEX idx_placex_classtype ON placex (class, type);';
109 foreach ($aPairs as $aPair) {
110 $sql_tablespace = CONST_Tablespace_Aux_Data ? ' TABLESPACE '.CONST_Tablespace_Aux_Data : '';
113 'CREATE TABLE place_classtype_%s_%s'
116 . ' SELECT place_id AS place_id,st_centroid(geometry) AS centroid FROM placex'
117 . " WHERE class = '%s' AND type = '%s'"
119 pg_escape_string($aPair[0]),
120 pg_escape_string($aPair[1]),
121 pg_escape_string($aPair[0]),
122 pg_escape_string($aPair[1])
126 'CREATE INDEX idx_place_classtype_%s_%s_centroid'
127 . ' ON place_classtype_%s_%s USING GIST (centroid)'
130 pg_escape_string($aPair[0]),
131 pg_escape_string($aPair[1]),
132 pg_escape_string($aPair[0]),
133 pg_escape_string($aPair[1])
137 'CREATE INDEX idx_place_classtype_%s_%s_place_id'
138 . ' ON place_classtype_%s_%s USING btree(place_id)'
141 pg_escape_string($aPair[0]),
142 pg_escape_string($aPair[1]),
143 pg_escape_string($aPair[0]),
144 pg_escape_string($aPair[1])
148 'GRANT SELECT ON place_classtype_%s_%s TO "%s"'
150 pg_escape_string($aPair[0]),
151 pg_escape_string($aPair[1]),
152 getSetting('DATABASE_WEBUSER');
156 echo 'DROP INDEX idx_placex_classtype;';