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(CONST_Phrase_Config);
21 if ($aCMDResult['wiki-import']) {
22 $oNormalizer = Transliterator::createFromRules(CONST_Term_Normalization_Rules);
25 $sLanguageIn = CONST_Languages ? CONST_Languages :
26 ('af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'.
27 'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi');
29 foreach (explode(',', $sLanguageIn) as $sLanguage) {
30 $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
31 $sWikiPageXML = file_get_contents($sURL);
34 '#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#',
42 foreach ($aMatches as $aMatch) {
43 $sLabel = trim($aMatch[1]);
44 if ($oNormalizer !== null) {
45 $sTrans = pg_escape_string($oNormalizer->transliterate($sLabel));
49 $sClass = trim($aMatch[2]);
50 $sType = trim($aMatch[3]);
51 // hack around a bug where building=yes was imported with
52 // quotes into the wiki
53 $sType = preg_replace('/("|")/', '', $sType);
54 // sanity check, in case somebody added garbage in the wiki
55 if (preg_match('/^\\w+$/', $sClass) < 1
56 || preg_match('/^\\w+$/', $sType) < 1
58 trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
61 // blacklisting: disallow certain class/type combinations
62 if (isset($aTagsBlacklist[$sClass]) && in_array($sType, $aTagsBlacklist[$sClass])) {
63 // fwrite(STDERR, "Blacklisted: ".$sClass."/".$sType."\n");
66 // whitelisting: if class is in whitelist, allow only tags in the list
67 if (isset($aTagsWhitelist[$sClass]) && !in_array($sType, $aTagsWhitelist[$sClass])) {
68 // fwrite(STDERR, "Non-Whitelisted: ".$sClass."/".$sType."\n");
71 $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
73 switch (trim($aMatch[4])) {
76 "SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'near');\n",
77 pg_escape_string($sLabel),
85 "SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'in');\n",
86 pg_escape_string($sLabel),
94 "SELECT getorcreate_amenity(make_standard_name('%s'), '%s', '%s', '%s');\n",
95 pg_escape_string($sLabel),
105 echo 'CREATE INDEX idx_placex_classtype ON placex (class, type);';
107 foreach ($aPairs as $aPair) {
108 $sql_tablespace = CONST_Tablespace_Aux_Data ? ' TABLESPACE '.CONST_Tablespace_Aux_Data : '';
111 'CREATE TABLE place_classtype_%s_%s'
114 . ' SELECT place_id AS place_id,st_centroid(geometry) AS centroid FROM placex'
115 . " WHERE class = '%s' AND type = '%s'"
117 pg_escape_string($aPair[0]),
118 pg_escape_string($aPair[1]),
119 pg_escape_string($aPair[0]),
120 pg_escape_string($aPair[1])
124 'CREATE INDEX idx_place_classtype_%s_%s_centroid'
125 . ' ON place_classtype_%s_%s USING GIST (centroid)'
128 pg_escape_string($aPair[0]),
129 pg_escape_string($aPair[1]),
130 pg_escape_string($aPair[0]),
131 pg_escape_string($aPair[1])
135 'CREATE INDEX idx_place_classtype_%s_%s_place_id'
136 . ' ON place_classtype_%s_%s USING btree(place_id)'
139 pg_escape_string($aPair[0]),
140 pg_escape_string($aPair[1]),
141 pg_escape_string($aPair[0]),
142 pg_escape_string($aPair[1])
146 'GRANT SELECT ON place_classtype_%s_%s TO "%s"'
148 pg_escape_string($aPair[0]),
149 pg_escape_string($aPair[1]),
150 CONST_Database_Web_User
154 echo 'DROP INDEX idx_placex_classtype;';