diff --git a/Changes b/Changes
index c7704005..d1ccfc21 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.43 2024-06-11
+ - [feature] Support opProx in C2 (bodmer)
+
0.42 2024-01-11
- [feature] Support #REG in C2 (bodmer)
- [bugfix] Fix comma in #BED in C2 (bodmer)
diff --git a/pom.xml b/pom.xml
index b409fe5c..049b3952 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
de.ids-mannheim.korap.koral
Koral
- 0.42.0
+ 0.43.0
jar
Koral
https://korap.ids-mannheim.de
diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g
index 1569d1a5..58e00f4d 100644
--- a/src/main/antlr/cosmas/c2ps_opPROX.g
+++ b/src/main/antlr/cosmas/c2ps_opPROX.g
@@ -38,8 +38,8 @@ DISTVALUE
// 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') (~ ' ')* ;
-
+ : ~(','|'a'|'i'|'m'|'n'|'p'|'s'|'t'|'w'|'x'|'A'|'I'|'M'|'N'|'P'|'S'|'T'|'W'|'X'|'0'..'9'|'+'|'-'|':'|'/'|'%') (~ ' ')* ;
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// PROX-Parser
@@ -102,4 +102,4 @@ proxGroup
| ('max'|'MAX') -> ^(GRP MAX);
-
\ No newline at end of file
+
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 62297195..737c7ad0 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,121 @@
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);
+
+ case StatusCodes.UNKNOWN_QUERY_ERROR:
+ return String.format("Unknown error!");
+
+ 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);
+
+ case StatusCodes.UNKNOWN_QUERY_ERROR:
+ return String.format("Unbekannter Fehler!");
+
+ 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);
+ }
+
+
+ /**
+ * in this version, the pre-stored message language is used.
+ * @param errCode
+ * @param text
+ * @return
+ * 10.06.24/FB
+ */
+
+ public static String getErrMess(int errCode, 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 +146,8 @@ private static CommonTree buildErrorTree(String text, int errCode, int typeDIST,
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);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index a6c7bd9d..16af2a3e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -9,6 +9,7 @@
import de.ids_mannheim.korap.query.object.KoralOperation;
import de.ids_mannheim.korap.query.object.KoralTermGroupRelation;
import de.ids_mannheim.korap.query.object.KoralType;
+import de.ids_mannheim.korap.query.parse.cosmas.c2ps_opPROX;
import de.ids_mannheim.korap.query.parse.cosmas.c2psLexer;
import de.ids_mannheim.korap.query.parse.cosmas.c2psParser;
import de.ids_mannheim.korap.query.serialize.util.Antlr3DescriptiveErrorListener;
@@ -150,7 +151,7 @@ public class Cosmas2QueryProcessor extends Antlr3AbstractQueryProcessor {
private boolean reportErrorsinTree(Tree node)
{
- final String func = "reportErrorsinTree";
+ // not used when not debugging: final String func = "reportErrorsinTree";
//System.err.printf("Debug: %s: '%s' has %d children.\n",
// func, node.getText(), node.getChildCount());
@@ -178,8 +179,8 @@ private boolean reportErrorsinTree(Tree node)
int
errCode = node.getChild(1) != null ? Integer.parseInt(node.getChild(1).getText()) : StatusCodes.ERR_PROX_UNKNOWN;
String
- errMess = node.getChild(2) != null ? node.getChild(2).getText() : "Genaue Fehlermeldung nicht auffindbar.";
-
+ errMess = node.getChild(2) != null ? node.getChild(2).getText() : c2ps_opPROX.getErrMess(StatusCodes.UNKNOWN_QUERY_ERROR, "");
+
ArrayList