changes for the review.
Change-Id: I653cf6f7ab8477d56565686b62c7d0d56271531c
diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g
index 1569d1a..73ee879 100644
--- a/src/main/antlr/cosmas/c2ps_opPROX.g
+++ b/src/main/antlr/cosmas/c2ps_opPROX.g
@@ -37,9 +37,16 @@
// trying to catch everything (at the end of the option sequence) that should not appear inside the prox. options:
// e.g. /w5umin -> remain = 'umin'.
-PROX_REMAIN
- : (',')? ('b'..'h'|'j'..'l'|'n'|'o'|'q'|'r'|'u'|'v'|'y'|'z'|'B'..'H'|'J'..'L'|'N'|'O'|'Q'|'R'|'U'|'V'|'Y'|'Z') (~ ' ')* ;
+//PROX_REMAIN
+// : (',')? ('b'..'h'|'j'..'l'|'n'|'o'|'q'|'r'|'u'|'v'|'y'|'z'|'B'..'H'|'J'..'L'|'N'|'O'|'Q'|'R'|'U'|'V'|'Y'|'Z') (~ ' ')* ;
+//PROX_REMAIN
+// : (',')? ~('a'|'i'|'m'|'p'|'s'|'t'|'w'|'x'|'A'|'I'|'M'|'P'|'S'|'T'|'W'|'X'|' ') (~ (' '))*;
+
+PROX_REMAIN
+ : ',' ~('a'|'i'|'m'|'p'|'s'|'t'|'w'|'x'|'A'|'I'|'M'|'P'|'S'|'T'|'W'|'X'|'0'..'9') (~ ' ')*
+ | ~('a'|'i'|'m'|'p'|'s'|'t'|'w'|'x'|'A'|'I'|'M'|'P'|'S'|'T'|'W'|'X'|'0'..'9') (~ ' ')*;
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// PROX-Parser
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
index 6229719..06ef8ed 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
@@ -15,12 +15,97 @@
public class c2ps_opPROX
{
- final static boolean bDebug = false;
+ final static boolean
+ bDebug = false;
+
+ public static final int MLANG_ENGLISH = 0;
+ public static final int MLANG_GERMAN = 1;
+
+ public static int
+ messLang = MLANG_ENGLISH; // default.
// type of an Error CommonToken:
- final static int typeERROR = 1;
+ final static int
+ typeERROR = 1;
+
// Prox error codes defined in StatusCodes.java.
+ private static String getErrMessEN(int errCode, String text)
+
+ {
+ switch( errCode )
+ {
+ case StatusCodes.ERR_PROX_MEAS_NULL:
+ return String.format("Proximity operator at '%s': one of the following prox. types is missing: w,s,p!", text);
+
+ case StatusCodes.ERR_PROX_MEAS_TOOGREAT:
+ return String.format("Proximity operator at '%s': Please, specify only 1 of the following prox. types: w,s,p! " +
+ "It is possible to specify several at once by separating them with a ','. E.g.: ' /+w2,s2,p0 '.", text);
+
+ case StatusCodes.ERR_PROX_VAL_NULL:
+ return String.format("Proximity operator at '%s': please specify a numerical value for the distance. E.g. ' /+w5 '.", text);
+
+ case StatusCodes.ERR_PROX_VAL_TOOGREAT:
+ return String.format("Proximity operator at '%s': please specify only 1 distance value. E.g. ' /+w5 '.", text);
+
+ case StatusCodes.ERR_PROX_DIR_TOOGREAT:
+ return String.format("Proximity operator at '%s': please specify either '+' or '-' or none of them for the direction.", text);
+
+ case StatusCodes.ERR_PROX_WRONG_CHARS:
+ return String.format("Proximity operator at '%s': unknown proximity options!", text);
+
+ default:
+ return String.format("Proximity operator at '%s': unknown error. The correct syntax looks like this: E.g. ' /+w2 ' or ' /w10,s0 '.", text);
+ }
+ }
+
+ private static String getErrMessGE(int errCode, String text)
+
+ {
+ switch( errCode )
+ {
+ case StatusCodes.ERR_PROX_MEAS_NULL:
+ return String.format("Abstandsoperator an der Stelle '%s': es fehlt eine der folgenden Angaben: w,s,p!", text);
+
+ case StatusCodes.ERR_PROX_MEAS_TOOGREAT:
+ return String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 der folgenden Angaben einsetzen: w,s,p! " +
+ "Falls Mehrfachangabe erwünscht, müssen diese durch Kommata getrennt werden (z.B.: ' /+w2,s2,p0 ').", text);
+
+ case StatusCodes.ERR_PROX_VAL_NULL:
+ return String.format("Abstandsoperator an der Stelle '%s': Bitte einen numerischen Wert einsetzen (z.B. ' /+w5 ')! ", text);
+
+ case StatusCodes.ERR_PROX_VAL_TOOGREAT:
+ return String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 numerischen Wert einsetzen (z.B. ' /+w5 ')! ", text);
+
+ case StatusCodes.ERR_PROX_DIR_TOOGREAT:
+ return String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 Angabe '+' oder '-' oder keine! ", text);
+
+ case StatusCodes.ERR_PROX_WRONG_CHARS:
+ return String.format("Abstandsoperator an der Stelle '%s': unbekannte Abstandsoption(en)!", text);
+
+ default:
+ return String.format("Abstandsoperator an der Stelle '%s': unbekannter Fehler. Korrekte Syntax z.B.: ' /+w2 ' oder ' /w10,s0 '.", text);
+ }
+ }
+
+ private static String getErrMess(int errCode, int messLang, String text)
+
+ {
+ if( messLang == c2ps_opPROX.MLANG_GERMAN )
+ return getErrMessGE(errCode, text);
+ else
+ return getErrMessEN(errCode, text);
+ }
+
+ /**
+ * buildErrorTree():
+ * @param text = part of the query that contains an error.
+ * @param errCode
+ * @param typeDIST
+ * @param pos
+ * @return
+ */
+
private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, int pos)
{
@@ -37,38 +122,8 @@
String
mess;
- switch( errCode )
- {
- case StatusCodes.ERR_PROX_MEAS_NULL:
- mess = String.format("Abstandsoperator an der Stelle '%s' es fehlt eine der folgenden Angaben: w,s,p!", text);
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- break;
- case StatusCodes.ERR_PROX_MEAS_TOOGREAT:
- mess = String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 der folgenden Angaben einsetzen: w,s,p! " +
- "Falls Mehrfachangabe erwünscht, müssen diese durch Kommata getrennt werden (z.B.: /+w2,s0).", text);
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- break;
- case StatusCodes.ERR_PROX_VAL_NULL:
- mess = String.format("Abstandsoperator an der Stelle '%s': Bitte einen numerischen Wert einsetzen (z.B. /+w5)! ", text);
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- break;
- case StatusCodes.ERR_PROX_VAL_TOOGREAT:
- mess = String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 numerischen Wert einsetzen (z.B. /+w5)! ", text);
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- break;
- case StatusCodes.ERR_PROX_DIR_TOOGREAT:
- mess = String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 Angabe '+' oder '-' oder keine! ", text);
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- break;
- case StatusCodes.ERR_PROX_WRONG_CHARS:
- mess = String.format("Abstandsoperator an der Stelle '%s': unbekannte Abstandsoption(en)!", text);
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- break;
- default:
- mess = String.format("Abstandsoperator an der Stelle '%s': unbekannter Fehler. Korrekte Syntax z.B.: /+w2 oder /w10,s0.", text);
-
- errorMes = new CommonTree(new CommonToken(typeERROR, mess));
- }
+ mess = getErrMess(errCode, messLang, text);
+ errorMes = new CommonTree(new CommonToken(typeERROR, mess));
errorTree.addChild(errorNode);
errorNode.addChild(errorPos);