comparison backend/src/main/java/org/dive4elements/river/importer/parsers/StaFileParser.java @ 5902:24f9c5146384

Backend: Fixed recognition of main values in STA parser.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 06 May 2013 12:15:51 +0200
parents 4dd33b86dc61
children f944cc25484c
comparison
equal deleted inserted replaced
5901:92bc0aa3831d 5902:24f9c5146384
47 47
48 public static final Pattern QWTD_ = 48 public static final Pattern QWTD_ =
49 Pattern.compile("\\s*([^\\s]+)\\s+([^\\s]+)\\s+([" + 49 Pattern.compile("\\s*([^\\s]+)\\s+([^\\s]+)\\s+([" +
50 Pattern.quote(TYPES) + "]).*"); 50 Pattern.quote(TYPES) + "]).*");
51 51
52 // TODO: To be extented.
53 private static final Pattern MAIN_VALUE = Pattern.compile(
54 "^(HQ|MHW|GLQ|NMQ|HQEXT)(\\d*)$");
55
56 private static boolean isMainValue(String s) {
57 s = s.replace(" ", "").toUpperCase();
58 return MAIN_VALUE.matcher(s).matches();
59 }
60
61
52 public static final class NameAndTimeInterval { 62 public static final class NameAndTimeInterval {
53 private String name; 63 private String name;
54 private ImportTimeInterval timeInterval; 64 private ImportTimeInterval timeInterval;
55 65
56 public NameAndTimeInterval(String name) { 66 public NameAndTimeInterval(String name) {
66 return name; 76 return name;
67 } 77 }
68 78
69 public ImportTimeInterval getTimeInterval() { 79 public ImportTimeInterval getTimeInterval() {
70 return timeInterval; 80 return timeInterval;
81 }
82
83 @Override
84 public String toString() {
85 return "name: " + name + " time interval: " + timeInterval;
71 } 86 }
72 } // class NameAndTimeInterval 87 } // class NameAndTimeInterval
73 88
74 public StaFileParser() { 89 public StaFileParser() {
75 } 90 }
223 } 238 }
224 log.info("finished parsing STA file: " + file); 239 log.info("finished parsing STA file: " + file);
225 return true; 240 return true;
226 } 241 }
227 242
228 protected NameAndTimeInterval parseName(String name) { 243 protected static NameAndTimeInterval parseName(String name) {
229 List<String> result = new ArrayList<String>(); 244 List<String> result = new ArrayList<String>();
230 245
231 unbracket(name, 0, result); 246 unbracket(name, 0, result);
232 247
233 int length = result.size(); 248 int length = result.size();
238 253
239 if (length == 1) { // No date at all -> use first part. 254 if (length == 1) { // No date at all -> use first part.
240 return new NameAndTimeInterval(result.get(0).trim()); 255 return new NameAndTimeInterval(result.get(0).trim());
241 } 256 }
242 257
243 if (length == 2) { // e.g. W(1994) or W(1994 - 1999) 258 if (length == 2) { // e.g. HQ(1994) or HQ(1994 - 1999)
259
244 String type = result.get(0).trim(); 260 String type = result.get(0).trim();
245 261 ImportTimeInterval timeInterval = null;
246 ImportTimeInterval timeInterval = getTimeInterval( 262
247 result.get(1).trim()); 263 String datePart = result.get(1).trim();
248 264 if (isMainValue(datePart)) { // e.g. W(HQ100)
249 if (timeInterval == null) { // No date at all. 265 type += "(" + datePart + ")";
250 type = name; 266 timeInterval = null;
267 }
268 else {
269 timeInterval = getTimeInterval(result.get(1).trim());
270
271 if (timeInterval == null) { // No date at all.
272 type = name;
273 }
251 } 274 }
252 275
253 return new NameAndTimeInterval(type, timeInterval); 276 return new NameAndTimeInterval(type, timeInterval);
254 } 277 }
255 278
256 if (length == 3) { // e.g W(Q(1994)) or W(Q(1994 - 1999)) 279 if (length == 3) { // e.g W(Q(1994)) or W(Q(1994 - 1999))
257 280
258 String type = 281 String type =
259 result.get(0).trim() + "(" + 282 result.get(0).trim() + "(" +
260 result.get(1).trim() + ")"; 283 result.get(1).trim() + ")";
261 284
262 ImportTimeInterval timeInterval = getTimeInterval( 285 ImportTimeInterval timeInterval = getTimeInterval(
263 result.get(2).trim()); 286 result.get(2).trim());
264 287
340 } 363 }
341 result.add(0, sb.toString()); 364 result.add(0, sb.toString());
342 365
343 return index; 366 return index;
344 } 367 }
368
369 /*
370 public static void main(String [] args) {
371 for (String arg: args) {
372 NameAndTimeInterval nti = parseName(arg);
373 System.out.println(arg + " -> " + nti);
374 }
375 }
376 */
345 } 377 }
346 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 378 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org