3 require_once(CONST_BasePath.'/lib/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);
17 include(CONST_Phrase_Config);
19 if ($aCMDResult['wiki-import']) {
20 $oNormalizer = Transliterator::createFromRules(CONST_Term_Normalization_Rules);
23 $sLanguageIn = CONST_Languages ? CONST_Languages :
24 ('af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'.
25 'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi');
27 foreach (explode(',', $sLanguageIn) as $sLanguage) {
28 $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
29 $sWikiPageXML = file_get_contents($sURL);
32 '#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#',
40 foreach ($aMatches as $aMatch) {
41 $sLabel = trim($aMatch[1]);
42 if ($oNormalizer !== null) {
43 $sTrans = pg_escape_string($oNormalizer->transliterate($sLabel));
47 $sClass = trim($aMatch[2]);
48 $sType = trim($aMatch[3]);
49 // hack around a bug where building=yes was imported with
50 // quotes into the wiki
51 $sType = preg_replace('/("|")/', '', $sType);
52 // sanity check, in case somebody added garbage in the wiki
53 if (preg_match('/^\\w+$/', $sClass) < 1
54 || preg_match('/^\\w+$/', $sType) < 1
56 trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
59 // blacklisting: disallow certain class/type combinations
60 if (isset($aTagsBlacklist[$sClass]) && in_array($sType, $aTagsBlacklist[$sClass])) {
61 // fwrite(STDERR, "Blacklisted: ".$sClass."/".$sType."\n");
64 // whitelisting: if class is in whitelist, allow only tags in the list
65 if (isset($aTagsWhitelist[$sClass]) && !in_array($sType, $aTagsWhitelist[$sClass])) {
66 // fwrite(STDERR, "Non-Whitelisted: ".$sClass."/".$sType."\n");
69 $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
71 switch (trim($aMatch[4])) {
74 "SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'near');\n",
75 pg_escape_string($sLabel),
83 "SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'in');\n",
84 pg_escape_string($sLabel),
92 "SELECT getorcreate_amenity(make_standard_name('%s'), '%s', '%s', '%s');\n",
93 pg_escape_string($sLabel),
103 echo 'CREATE INDEX idx_placex_classtype ON placex (class, type);';
105 foreach ($aPairs as $aPair) {
106 $sql_tablespace = CONST_Tablespace_Aux_Data ? ' TABLESPACE '.CONST_Tablespace_Aux_Data : '';
109 'CREATE TABLE place_classtype_%s_%s'
112 . ' SELECT place_id AS place_id,st_centroid(geometry) AS centroid FROM placex'
113 . " WHERE class = '%s' AND type = '%s'"
115 pg_escape_string($aPair[0]),
116 pg_escape_string($aPair[1]),
117 pg_escape_string($aPair[0]),
118 pg_escape_string($aPair[1])
122 'CREATE INDEX idx_place_classtype_%s_%s_centroid'
123 . ' ON place_classtype_%s_%s USING GIST (centroid)'
126 pg_escape_string($aPair[0]),
127 pg_escape_string($aPair[1]),
128 pg_escape_string($aPair[0]),
129 pg_escape_string($aPair[1])
133 'CREATE INDEX idx_place_classtype_%s_%s_place_id'
134 . ' ON place_classtype_%s_%s USING btree(place_id)'
137 pg_escape_string($aPair[0]),
138 pg_escape_string($aPair[1]),
139 pg_escape_string($aPair[0]),
140 pg_escape_string($aPair[1])
144 'GRANT SELECT ON place_classtype_%s_%s TO "%s"'
146 pg_escape_string($aPair[0]),
147 pg_escape_string($aPair[1]),
148 CONST_Database_Web_User
152 echo 'DROP INDEX idx_placex_classtype;';