]> git.openstreetmap.org Git - nominatim.git/blob - utils/specialphrases.php
pull in the special phrases from the wiki
[nominatim.git] / utils / specialphrases.php
1 #!/usr/bin/php -Cq
2 <?php
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5         ini_set('memory_limit', '800M');
6
7         $aCMDOptions = array(
8                 "Import and export special phrases",
9                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
10                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
11                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
12
13                 array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
14         );
15         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
16
17         $aLanguageIn = array(
18                         'af',
19                         'ar',
20                         'br',
21                         'ca',
22                         'cs',
23                         'de',
24                         'en',
25                         'es',
26                         'et',
27                         'eu',
28                         'fa',
29                         'fi',
30                         'fr',
31                         'gl',
32                         'hr',
33                         'hu',
34                         'ia',
35                         'is',
36                         'it',
37                         'ja',
38                         'mk',
39                         'nl',
40                         'no',
41                         'pl',
42                         'ps',
43                         'pt',
44                         'ru',
45                         'sk',
46                         'sv',
47                         'uk',
48                         'vi',
49                 );
50
51         if ($aCMDResult['wiki-import'])
52         {
53                 foreach($aLanguageIn as $sLanguage)
54                 {
55                         $sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
56                         $sWikiPageXML = file_get_contents($sURL);
57                         if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN]) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER))
58                         {
59                                 foreach($aMatches as $aMatch)
60                                 {
61                                         $sLabel = $aMatch[1];
62                                         $sClass = $aMatch[2];
63                                         $sType = $aMatch[3];
64
65                                         switch(trim($aMatch[4]))
66                                         {
67                                         case 'near':
68                                                 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
69                                                 break;
70                                         case 'in':
71                                                 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType','in');\n";
72                                                 break;
73                                         default:
74                                                 echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
75                                                 break;
76                                         }
77                                 }
78                         }
79                 }
80         }