Mercurial > dive4elements > river
changeset 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 | 92bc0aa3831d |
children | c2f51d283ee2 |
files | backend/src/main/java/org/dive4elements/river/importer/parsers/StaFileParser.java |
diffstat | 1 files changed, 40 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/StaFileParser.java Mon May 06 11:38:50 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/StaFileParser.java Mon May 06 12:15:51 2013 +0200 @@ -49,6 +49,16 @@ Pattern.compile("\\s*([^\\s]+)\\s+([^\\s]+)\\s+([" + Pattern.quote(TYPES) + "]).*"); + // TODO: To be extented. + private static final Pattern MAIN_VALUE = Pattern.compile( + "^(HQ|MHW|GLQ|NMQ|HQEXT)(\\d*)$"); + + private static boolean isMainValue(String s) { + s = s.replace(" ", "").toUpperCase(); + return MAIN_VALUE.matcher(s).matches(); + } + + public static final class NameAndTimeInterval { private String name; private ImportTimeInterval timeInterval; @@ -69,6 +79,11 @@ public ImportTimeInterval getTimeInterval() { return timeInterval; } + + @Override + public String toString() { + return "name: " + name + " time interval: " + timeInterval; + } } // class NameAndTimeInterval public StaFileParser() { @@ -225,7 +240,7 @@ return true; } - protected NameAndTimeInterval parseName(String name) { + protected static NameAndTimeInterval parseName(String name) { List<String> result = new ArrayList<String>(); unbracket(name, 0, result); @@ -240,14 +255,22 @@ return new NameAndTimeInterval(result.get(0).trim()); } - if (length == 2) { // e.g. W(1994) or W(1994 - 1999) - String type = result.get(0).trim(); + if (length == 2) { // e.g. HQ(1994) or HQ(1994 - 1999) - ImportTimeInterval timeInterval = getTimeInterval( - result.get(1).trim()); + String type = result.get(0).trim(); + ImportTimeInterval timeInterval = null; - if (timeInterval == null) { // No date at all. - type = name; + String datePart = result.get(1).trim(); + if (isMainValue(datePart)) { // e.g. W(HQ100) + type += "(" + datePart + ")"; + timeInterval = null; + } + else { + timeInterval = getTimeInterval(result.get(1).trim()); + + if (timeInterval == null) { // No date at all. + type = name; + } } return new NameAndTimeInterval(type, timeInterval); @@ -256,7 +279,7 @@ if (length == 3) { // e.g W(Q(1994)) or W(Q(1994 - 1999)) String type = - result.get(0).trim() + "(" + + result.get(0).trim() + "(" + result.get(1).trim() + ")"; ImportTimeInterval timeInterval = getTimeInterval( @@ -342,5 +365,14 @@ return index; } + + /* + public static void main(String [] args) { + for (String arg: args) { + NameAndTimeInterval nti = parseName(arg); + System.out.println(arg + " -> " + nti); + } + } + */ } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :