4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 ini_set('memory_limit', '800M');
7 ini_set('display_errors', 'stderr');
11 "Import and export special phrases",
12 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
13 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
14 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
15 array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
17 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
19 include(CONST_InstallPath.'/settings/phrase_settings.php');
21 if ($aCMDResult['wiki-import']) {
24 $sLanguageIn = CONST_Languages ? CONST_Languages :
25 ('af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'.
26 'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi');
28 foreach (explode(',', $sLanguageIn) as $sLanguage) {
29 $sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
30 $sWikiPageXML = file_get_contents($sURL);
31 if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
32 foreach ($aMatches as $aMatch) {
33 $sLabel = trim($aMatch[1]);
34 $sClass = trim($aMatch[2]);
35 $sType = trim($aMatch[3]);
36 // hack around a bug where building=yes was imported with
37 // quotes into the wiki
38 $sType = preg_replace('/"/', '', $sType);
39 // sanity check, in case somebody added garbage in the wiki
40 if (preg_match('/^\\w+$/', $sClass) < 1
41 || preg_match('/^\\w+$/', $sType) < 1
43 trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
46 // blacklisting: disallow certain class/type combinations
47 if (isset($aTagsBlacklist[$sClass]) && in_array($sType, $aTagsBlacklist[$sClass])) {
48 // fwrite(STDERR, "Blacklisted: ".$sClass."/".$sType."\n");
51 // whitelisting: if class is in whitelist, allow only tags in the list
52 if (isset($aTagsWhitelist[$sClass]) && !in_array($sType, $aTagsWhitelist[$sClass])) {
53 // fwrite(STDERR, "Non-Whitelisted: ".$sClass."/".$sType."\n");
56 $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
58 switch (trim($aMatch[4])) {
60 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
63 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n";
66 echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
73 echo "create index idx_placex_classtype on placex (class, type);";
75 foreach ($aPairs as $aPair) {
76 echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]);
77 if (CONST_Tablespace_Aux_Data)
78 echo " tablespace ".CONST_Tablespace_Aux_Data;
79 echo " as select place_id as place_id,st_centroid(geometry) as centroid from placex where ";
80 echo "class = '".pg_escape_string($aPair[0])."' and type = '".pg_escape_string($aPair[1])."'";
83 echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_centroid ";
84 echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING GIST (centroid)";
85 if (CONST_Tablespace_Aux_Index)
86 echo " tablespace ".CONST_Tablespace_Aux_Index;
89 echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_place_id ";
90 echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING btree(place_id)";
91 if (CONST_Tablespace_Aux_Index)
92 echo " tablespace ".CONST_Tablespace_Aux_Index;
95 echo "GRANT SELECT ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n";
98 echo "drop index idx_placex_classtype;";