Merge pull request #1502 from mtmail/specialphrases-quotes

Specialphrases quotes
This commit is contained in:
Sarah Hoffmann
2019-10-22 21:41:53 +02:00
committed by GitHub

View File

@@ -27,7 +27,16 @@ if ($aCMDResult['wiki-import']) {
foreach (explode(',', $sLanguageIn) as $sLanguage) { foreach (explode(',', $sLanguageIn) as $sLanguage) {
$sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage); $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
$sWikiPageXML = file_get_contents($sURL); $sWikiPageXML = file_get_contents($sURL);
if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
if (!preg_match_all(
'#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#',
$sWikiPageXML,
$aMatches,
PREG_SET_ORDER
)) {
continue;
}
foreach ($aMatches as $aMatch) { foreach ($aMatches as $aMatch) {
$sLabel = trim($aMatch[1]); $sLabel = trim($aMatch[1]);
if ($oNormalizer !== null) { if ($oNormalizer !== null) {
@@ -39,7 +48,7 @@ if ($aCMDResult['wiki-import']) {
$sType = trim($aMatch[3]); $sType = trim($aMatch[3]);
// hack around a bug where building=yes was imported with // hack around a bug where building=yes was imported with
// quotes into the wiki // quotes into the wiki
$sType = preg_replace('/"/', '', $sType); $sType = preg_replace('/("|")/', '', $sType);
// sanity check, in case somebody added garbage in the wiki // sanity check, in case somebody added garbage in the wiki
if (preg_match('/^\\w+$/', $sClass) < 1 if (preg_match('/^\\w+$/', $sClass) < 1
|| preg_match('/^\\w+$/', $sType) < 1 || preg_match('/^\\w+$/', $sType) < 1
@@ -61,43 +70,84 @@ if ($aCMDResult['wiki-import']) {
switch (trim($aMatch[4])) { switch (trim($aMatch[4])) {
case 'near': case 'near':
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sTrans', '$sClass', '$sType', 'near');\n"; printf(
"SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'near');\n",
pg_escape_string($sLabel),
$sTrans,
$sClass,
$sType
);
break; break;
case 'in': case 'in':
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sTrans', '$sClass', '$sType', 'in');\n"; printf(
"SELECT getorcreate_amenityoperator(make_standard_name('%s'), '%s', '%s', '%s', 'in');\n",
pg_escape_string($sLabel),
$sTrans,
$sClass,
$sType
);
break; break;
default: default:
echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sTrans', '$sClass', '$sType');\n"; printf(
"SELECT getorcreate_amenity(make_standard_name('%s'), '%s', '%s', '%s');\n",
pg_escape_string($sLabel),
$sTrans,
$sClass,
$sType
);
break; break;
} }
} }
} }
}
echo 'create index idx_placex_classtype on placex (class, type);'; echo 'CREATE INDEX idx_placex_classtype ON placex (class, type);';
foreach ($aPairs as $aPair) { foreach ($aPairs as $aPair) {
echo 'create table place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]); $sql_tablespace = CONST_Tablespace_Aux_Data ? ' TABLESPACE '.CONST_Tablespace_Aux_Data : '';
if (CONST_Tablespace_Aux_Data)
echo ' tablespace '.CONST_Tablespace_Aux_Data;
echo ' as select place_id as place_id,st_centroid(geometry) as centroid from placex where ';
echo "class = '".pg_escape_string($aPair[0])."' and type = '".pg_escape_string($aPair[1])."'";
echo ";\n";
echo 'CREATE INDEX idx_place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).'_centroid '; printf(
echo 'ON place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).' USING GIST (centroid)'; 'CREATE TABLE place_classtype_%s_%s'
if (CONST_Tablespace_Aux_Index) . $sql_tablespace
echo ' tablespace '.CONST_Tablespace_Aux_Index; . ' AS'
echo ";\n"; . ' SELECT place_id AS place_id,st_centroid(geometry) AS centroid FROM placex'
. " WHERE class = '%s' AND type = '%s'"
. ";\n",
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1]),
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1])
);
echo 'CREATE INDEX idx_place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).'_place_id '; printf(
echo 'ON place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).' USING btree(place_id)'; 'CREATE INDEX idx_place_classtype_%s_%s_centroid'
if (CONST_Tablespace_Aux_Index) . ' ON place_classtype_%s_%s USING GIST (centroid)'
echo ' tablespace '.CONST_Tablespace_Aux_Index; . $sql_tablespace
echo ";\n"; . ";\n",
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1]),
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1])
);
echo 'GRANT SELECT ON place_classtype_'.pg_escape_string($aPair[0]).'_'.pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n"; printf(
'CREATE INDEX idx_place_classtype_%s_%s_place_id'
. ' ON place_classtype_%s_%s USING btree(place_id)'
. $sql_tablespace
. ";\n",
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1]),
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1])
);
printf(
'GRANT SELECT ON place_classtype_%s_%s TO "%s"'
. ";\n",
pg_escape_string($aPair[0]),
pg_escape_string($aPair[1]),
CONST_Database_Web_User
);
} }
echo 'drop index idx_placex_classtype;'; echo 'DROP INDEX idx_placex_classtype;';
} }