1 | package org.greenstone.atlas.server;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | public class GazetteerHelper
|
---|
6 | {
|
---|
7 | /**
|
---|
8 | * Gets the population from the line in the gazetteer file
|
---|
9 | * @param columns is the line in the file that has been split
|
---|
10 | * @return the population (if available)
|
---|
11 | */
|
---|
12 | public static int getPopulation(String[] columns)
|
---|
13 | {
|
---|
14 | // If the row has a sixth element it is the population of the place
|
---|
15 | if (columns.length > 5 && columns[5].length() > 0)
|
---|
16 | {
|
---|
17 | return Integer.parseInt(columns[5]);
|
---|
18 | }
|
---|
19 | return -1;
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Gets the longitude from the line in the gazetteer file
|
---|
24 | * @param columns is the line in the file that has been split
|
---|
25 | * @return the longitude (if available)
|
---|
26 | */
|
---|
27 | public static Float getLongitude(String[] columns)
|
---|
28 | {
|
---|
29 | try
|
---|
30 | {
|
---|
31 | // If the row has a seventh element it is the longitude of the place
|
---|
32 | if (columns.length > 7 && columns[7].length() > 0)
|
---|
33 | {
|
---|
34 | return (Float.parseFloat(columns[7]) / 100);
|
---|
35 | }
|
---|
36 | return null;
|
---|
37 | }
|
---|
38 | catch(Exception ex)
|
---|
39 | {
|
---|
40 | return null;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Gets the latitude from the line in the gazetteer file
|
---|
46 | * @param columns is the line in the file that has been split
|
---|
47 | * @return the latitude (if available)
|
---|
48 | */
|
---|
49 | public static Float getLatitude(String[] columns)
|
---|
50 | {
|
---|
51 | try
|
---|
52 | {
|
---|
53 | // If the row has a eighth element it is the latitude of the place
|
---|
54 | if (columns.length > 6 && columns[6].length() > 0)
|
---|
55 | {
|
---|
56 | return (Float.parseFloat(columns[6]) / 100);
|
---|
57 | }
|
---|
58 | return null;
|
---|
59 | }
|
---|
60 | catch(Exception ex)
|
---|
61 | {
|
---|
62 | return null;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Gets the country name from the line in the gazetteer file
|
---|
68 | * @param columns is the line in the file that has been split
|
---|
69 | * @return the country name
|
---|
70 | */
|
---|
71 | public static String getCountryName(String[] columns)
|
---|
72 | {
|
---|
73 | // If the row has a ninth element it is the name of the country that
|
---|
74 | // this place is in
|
---|
75 | if (columns.length > 8 && columns[8].length() > 0)
|
---|
76 | {
|
---|
77 | return columns[8];
|
---|
78 | }
|
---|
79 | return null;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Gets the region name from the line in the gazetteer file
|
---|
84 | * @param columns is the line in the file that has been split
|
---|
85 | * @return the region name
|
---|
86 | */
|
---|
87 | public static String getRegionName(String[] columns)
|
---|
88 | {
|
---|
89 | // If the row has a tenth element it is the name of the region in
|
---|
90 | // the country that this place is in
|
---|
91 | if (columns.length > 9 && columns[9].length() > 0)
|
---|
92 | {
|
---|
93 | return columns[9];
|
---|
94 | }
|
---|
95 | return null;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Gets the sub region name from the line in the gazetteer file
|
---|
100 | * @param columns is the line in the file that has been split
|
---|
101 | * @return the sub region name
|
---|
102 | */
|
---|
103 | public static String getSubRegionName(String[] columns)
|
---|
104 | {
|
---|
105 | // If the row has an eleventh element is is the name of the
|
---|
106 | // sub-region in the country that this place is in
|
---|
107 | if (columns.length > 10 && columns[10].length() > 0)
|
---|
108 | {
|
---|
109 | return columns[10];
|
---|
110 | }
|
---|
111 | return null;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Gets the place type (e.g. county, locality etc.) from the line in the gazetteer file
|
---|
116 | * @param columns is the line in the file that has been split
|
---|
117 | * @return the place type
|
---|
118 | */
|
---|
119 | public static String getPlaceType(String[] columns)
|
---|
120 | {
|
---|
121 | if (columns.length > 4 && columns[4].length() > 0)
|
---|
122 | {
|
---|
123 | return columns[4];
|
---|
124 | }
|
---|
125 | return null;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Gets the place name that this place is most commonly known as
|
---|
130 | * @param columns is a tab seperated line in the gazetteer file that has been split
|
---|
131 | * @return the most common place name
|
---|
132 | */
|
---|
133 | public static String getMainPlaceName(String[] columns)
|
---|
134 | {
|
---|
135 | if(columns.length > 1 && columns[1].length() > 0)
|
---|
136 | {
|
---|
137 | return columns[1];
|
---|
138 | }
|
---|
139 | return null;
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Adds the alternative names for a place to the list of alternative place names that map back to the most common place name
|
---|
144 | * @param columns is a tab seperated line in the gazetteer file that has been split
|
---|
145 | */
|
---|
146 | protected static ArrayList<String> getAlternativePlaceNames(String[] columns)
|
---|
147 | {
|
---|
148 | ArrayList<String> placeNames = new ArrayList<String>();
|
---|
149 |
|
---|
150 | //If the row has a 3rd element it is a list of alternate names for this place
|
---|
151 | if(columns.length > 2 && columns[2].length() > 0)
|
---|
152 | {
|
---|
153 | String[] names = columns[2].split(", ");
|
---|
154 |
|
---|
155 | for(String name : names)
|
---|
156 | {
|
---|
157 | if(!placeNames.contains(name))
|
---|
158 | {
|
---|
159 | placeNames.add(name);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | //If the row has a 4th element it is the name of this place in it's home language
|
---|
165 | if(columns.length > 3 && columns[3].length() > 0)
|
---|
166 | {
|
---|
167 | if(!placeNames.contains(columns[3]))
|
---|
168 | {
|
---|
169 | placeNames.add(columns[3]);
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | return placeNames;
|
---|
174 | }
|
---|
175 |
|
---|
176 | protected static Integer getID(String[] columns)
|
---|
177 | {
|
---|
178 | try
|
---|
179 | {
|
---|
180 | if(columns.length > 0 && columns[0].length() > 0)
|
---|
181 | {
|
---|
182 | return Integer.parseInt(columns[0]);
|
---|
183 | }
|
---|
184 | return null;
|
---|
185 | }
|
---|
186 | catch(Exception ex)
|
---|
187 | {
|
---|
188 | return null;
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|