From 78e828c4af4140dfa59cf735039a7fe54fde1b39 Mon Sep 17 00:00:00 2001 From: Franck Bodmer Date: Thu, 11 Jan 2024 18:06:35 +0100 Subject: [PATCH] PROX: Tests with RecognitionExceptions removed. All Error Codes in StatusCodes.java. Change-Id: Id6355ddf859f35b8d0f20b4ce53c0f3da2122b03 --- src/main/antlr/cosmas/c2ps_opPROX.g | 8 +---- .../korap/query/parse/cosmas/c2ps_opPROX.java | 31 +++++++------------ .../serialize/Cosmas2QueryProcessor.java | 2 +- .../query/serialize/util/StatusCodes.java | 8 +++++ 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g index 9193de09..1bf077e5 100644 --- a/src/main/antlr/cosmas/c2ps_opPROX.g +++ b/src/main/antlr/cosmas/c2ps_opPROX.g @@ -49,15 +49,9 @@ proxTyp : '/' -> ^(TYP PROX) // klassischer Abstand. // proxDist: e.g. +5w or -s0 or /w2:4 etc. // kein proxDirection? hier, weil der Default erst innerhalb von Regel proxDirection erzeugt werden kann. -/* incomplete original version: -proxDist: proxDirection (v1=proxDistValue m1=proxMeasure | m2=proxMeasure v2=proxDistValue) - - -> {$v1.tree != null}? ^(DIST {$proxDirection.tree} {$v1.tree} {$m1.tree}) - -> ^(DIST {$proxDirection.tree} {$v2.tree} {$m2.tree}); -*/ // new rule: accepts options in any order: -// count each option type and find out if any one is missing or occures multiple times. +// count each option type and find out if any one is missing or occures multiple times. // 28.11.23/FB proxDist[int pos] 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 79871682..da3ea4a5 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 @@ -17,15 +17,9 @@ public class c2ps_opPROX { // type of an Error CommonToken: final static int typeERROR = 1; - // error codes returned to client: - final public static int ERR_PROX_UNKNOWN = 300; - final static int ERR_MEAS_NULL = 301; - final static int ERR_MEAS_TOOGREAT = 302; - final static int ERR_VAL_NULL = 303; - final static int ERR_VAL_TOOGREAT = 304; - final static int ERR_DIR_TOOGREAT = 305; + // Prox error codes defined in StatusCodes.java. - private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, int pos) throws RecognitionException + private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, int pos) { CommonTree @@ -43,24 +37,24 @@ private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, switch( errCode ) { - case ERR_MEAS_NULL: + 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 ERR_MEAS_TOOGREAT: + 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 ERR_VAL_NULL: + 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 ERR_VAL_TOOGREAT: + 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 ERR_DIR_TOOGREAT: + 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; @@ -97,7 +91,6 @@ private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text, int countD, int countM, int countV, int pos) - throws RecognitionException { CommonTree tree1 = (CommonTree)ctDir; @@ -108,13 +101,13 @@ public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object text, countM, countD, countV, pos); if( countM == 0 ) - return buildErrorTree(text, ERR_MEAS_NULL, typeDIST, pos); + return buildErrorTree(text, StatusCodes.ERR_PROX_MEAS_NULL, typeDIST, pos); if( countM > 1 ) - return buildErrorTree(text, ERR_MEAS_TOOGREAT, typeDIST, pos); + return buildErrorTree(text, StatusCodes.ERR_PROX_MEAS_TOOGREAT, typeDIST, pos); if( countV == 0 ) - return buildErrorTree(text, ERR_VAL_NULL, typeDIST, pos); + return buildErrorTree(text, StatusCodes.ERR_PROX_VAL_NULL, typeDIST, pos); if( countV > 1 ) - return buildErrorTree(text, ERR_VAL_TOOGREAT, typeDIST, pos); + return buildErrorTree(text, StatusCodes.ERR_PROX_VAL_TOOGREAT, typeDIST, pos); if( countD == 0 ) { @@ -128,7 +121,7 @@ public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object tree1 = treeDIR; } else if( countD > 1 ) - return buildErrorTree(text, ERR_DIR_TOOGREAT, typeDIST, pos); + return buildErrorTree(text, StatusCodes.ERR_PROX_DIR_TOOGREAT, typeDIST, pos); // create DIST tree: CommonTree 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 525bcb6f..e733f525 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 @@ -177,7 +177,7 @@ private boolean reportErrorsinTree(Tree node) int errPos = node.getChild(0) != null ? Integer.parseInt(node.getChild(0).getText()) : 0; int - errCode = node.getChild(1) != null ? Integer.parseInt(node.getChild(1).getText()) : c2ps_opPROX.ERR_PROX_UNKNOWN; + 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."; diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java index 656228d6..9dab8116 100644 --- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java +++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java @@ -14,4 +14,12 @@ public class StatusCodes { public final static int QUERY_TOO_COMPLEX = 311; public final static int UNKNOWN_QUERY_ERROR = 399; public final static int SERIALIZATION_FAILED = 300; + + // error codes for PROX syntax errors: + final public static int ERR_PROX_UNKNOWN = 320; + public final static int ERR_PROX_MEAS_NULL = 321; + public final static int ERR_PROX_MEAS_TOOGREAT = 322; + public final static int ERR_PROX_VAL_NULL = 323; + public final static int ERR_PROX_VAL_TOOGREAT = 324; + public final static int ERR_PROX_DIR_TOOGREAT = 325; } \ No newline at end of file