# HG changeset patch # User Sascha L. Teichmann # Date 1367835351 -7200 # Node ID 24f9c5146384667d302c530e4994f82337c076d5 # Parent 92bc0aa3831db3717c07d4939894e54f5a05d896 Backend: Fixed recognition of main values in STA parser. diff -r 92bc0aa3831d -r 24f9c5146384 backend/src/main/java/org/dive4elements/river/importer/parsers/StaFileParser.java --- 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 result = new ArrayList(); 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 :