From 0711f07572212834e7e76337975c73ac6fc04e23 Mon Sep 17 00:00:00 2001 From: Franck Bodmer Date: Wed, 20 Dec 2023 23:28:29 +0100 Subject: [PATCH] Prox... Change-Id: I4287658e0157593eb934fe1723df8ea1bb4fdc26 --- src/main/antlr/cosmas/c2ps_opPROX.g | 21 ++++++------------- .../korap/query/parse/cosmas/c2ps_opPROX.java | 12 ++++++----- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g index eda044e2..4e80d82a 100644 --- a/src/main/antlr/cosmas/c2ps_opPROX.g +++ b/src/main/antlr/cosmas/c2ps_opPROX.g @@ -90,19 +90,16 @@ proxDist: proxDirection (v1=proxDistValue m1=proxMeasure | m2=proxMeasure v2=pro */ // new rule: accepts options in any order: -// but how to handle multiple values for those options? +// count each option type and find out if any one is missing or occures multiple times. // 28.11.23/FB proxDist -@init{ int countM=0;} +@init{ int countM=0; int countD=0; int countV=0;} : - //((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+ {countM == 1}? - - ((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+ - - -> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text, countM)}; + (m=proxMeasure {countM++;}|d=proxDirection {countD++;}|v=proxDistValue {countV++;} )+ + + -> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text, $proxDist.index, countD, countM, countV)}; -// -> {c2ps_opPROX.checkDIST($proxDist.text) == true } ? {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text)}; // new rule accepts only '+' and '-'; default tree for direction is // set in c2ps_opPROX.encodeDIST() now. @@ -117,12 +114,6 @@ proxDistValue : (m1=proxDistMin ) (':' m2=proxDistMax)? -> {$m2.text != null}? ^(RANGE $m1 $m2) -> ^(RANGE VAL0 $m1); -/* calling c2ps_opPROX.checkMeasure() as a check will not compile by ANTLR, - reason unknown! 01.12.23/FB -proxMeasure - : (meas='w'|meas='s'|meas='p'|meas='t') -> {c2ps_opPROX.checkMeasure($meas)} ? ^(MEAS $meas) ; -*/ - // mentioning >1 measures will be checked/rejected in c2ps_opPROX.encodeDIST(). proxMeasure @@ -137,4 +128,4 @@ proxDistMax proxGroup : 'min' -> ^(GRP MIN) | '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 efa5a411..efad8a34 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 @@ -35,17 +35,19 @@ private static boolean duplicateOptions(String text) * 28.11.23/FB */ - public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text, int countM) - //throws C2RecognitionException + public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text, int start, + int countD, int countM, int countV) + { boolean multiple = false; CommonTree tree1 = (CommonTree)ctDir; CommonTree tree2 = (CommonTree)ctMeas; CommonTree tree3 = (CommonTree)ctVal; - - System.err.printf("Debug: encodeDIST: scanned input='%s' countM=%d.\n", text, countM); + //String text = "for debugging only"; + int pos = -1; + System.err.printf("Debug: encodeDIST: scanned input='%s' start=%d countM=%d countD=%d countV=%d.\n", + text, start, countM, countD, countV); - if( duplicateOptions(text) == true ) { CommonTree errorTree, errorNode, errorPos, errorArg, errorMes;