Skip to content

Commit

Permalink
opPROX: correcting order of Prox options: WIP.
Browse files Browse the repository at this point in the history
Change-Id: I7976484475b2f9116c7df7feed43b777b05bc713
  • Loading branch information
Bodmo committed Nov 28, 2023
1 parent 839b0ca commit 760fe93
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
35 changes: 32 additions & 3 deletions src/main/antlr/cosmas/c2ps_opPROX.g
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tokens { PROX_OPTS;
MEAS; // measure
DIR; PLUS; MINUS; BOTH;
GRP; MIN; MAX; }

@header {package de.ids_mannheim.korap.query.parse.cosmas;}
@lexer::header {package de.ids_mannheim.korap.query.parse.cosmas;}

Expand All @@ -39,25 +40,53 @@ opPROX : proxTyp proxDist (',' proxDist)* (',' proxGroup)?

-> ^(PROX_OPTS {$proxTyp.tree} ^(DIST_LIST proxDist+) {$proxGroup.tree});

proxTyp : '/' -> ^(TYP PROX) // klassischer Abstand.
| '%' -> ^(TYP EXCL); // ausschließender Abstand.
proxTyp : '/' -> ^(TYP PROX) // klassischer Abstand.
| '%' -> ^(TYP EXCL); // ausschließender 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 version: accepts any order (28.11.23/FB):

/*
proxDist: ('s'|'w'|'p'|'t'|'+'|'-'|DISTVALUE)+

-> {c2ps_opPROX.encode($proxDist.text, DIST)};
*/

// new version: just use the grammar another way (28.11.23/FB):

proxDist: (d=proxDirection|v=proxDistValue|m=proxMeasure)+
//-> {$v.tree != null && $m.tree != null} ? ^(DIST DIST); //{c2ps_opPROX.encodeDIST(DIR, $d.tree, $m.tree, $v.tree)} );
-> {c2ps_opPROX.encodeDIST(DIST, $d.tree, $m.tree, $v.tree)};

/* old rule for optional direction with default setting:
proxDirection:
(p='+'|m='-')? -> {$p != null}? ^(DIR PLUS)
-> {$m != null}? ^(DIR MINUS)
-> ^(DIR BOTH) ;
*/

// new rule with default setting. Default tree for direction set in c2ps_opPROX.encode():
// 28.11.23/FB

proxDirection
: '+' -> ^(DIR PLUS)
| '-' -> ^(DIR MINUS);

/*
proxDistValue // proxDistMin ( ':' proxDistMax)? ;
: (m1=proxDistMin -> ^(DIST_RANGE VAL0 $m1)) (':' m2=proxDistMax -> ^(DIST_RANGE $m1 $m2))? ;
*/
proxDistValue // proxDistMin ( ':' proxDistMax)? ;

// proxDistMin ( ':' proxDistMax)? ;
proxDistValue
: (m1=proxDistMin ) (':' m2=proxDistMax)?

-> {$m2.text != null}? ^(RANGE $m1 $m2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,73 @@ public class c2ps_opPROX

{

public static Tree check (String input, int index) {
/* encode():
* - encodes Distance type, Direction and Distance value
* which are written in any order.
* 28.11.23/FB
*/

public static Tree encode(String input, int type)
{
StringBuffer sb = new StringBuffer("(DIST (DIR MINUS) (RANGE VAL0 0) (MEAS w))");
System.err.printf("Debug: encode: input = '%s' output = >>%s<<.\n", input, sb.toString());
CommonTree ctree = new CommonTree(new CommonToken(type, sb.toString()));
//CommonTree treeType = new CommonTree(new CommonToken(1, ""))
//CommonToken ct = ct.
System.err.printf("Debug: encode: CommonTree : '%s'.\n", ctree.toStringTree());
//return new CommonTree(new CommonToken(type, sb.toString()));
return ctree;
} // encode

/* encodeDefaultDir():
* - return a tree containing the default Prox Direction when there is no
* direction indication in the input query.
* 28.11.23/FB
*/

public static Tree encodeDefautDir(String input, int type)
{
StringBuffer sb = new StringBuffer("BOTH");
CommonTree tree = new CommonTree(new CommonToken(type, sb.toString()));

System.err.printf("Debug: encodeDefaultDir: CommonTree : '%s'.\n", tree.toStringTree());

return tree;
} // encode

/* encodeDefaultDir():
* - return a tree containing the default Prox Direction when there is no
* direction indication in the input query.
* 28.11.23/FB
*/

public static Object encodeDIST(int type, Object ctDir, Object ctMeas, Object ctVal)
{
StringBuffer sb = new StringBuffer("BOTH");
CommonTree tree1 = (CommonTree)ctDir;
CommonTree tree2 = (CommonTree)ctMeas;
CommonTree tree3 = (CommonTree)ctVal;

System.err.printf("Debug: encodeDIST: ctDir='%s' ctMeas='%s' ctVal='%s'.\n",
tree1 != null ? tree1.toStringTree() : "null",
tree2 != null ? tree2.toStringTree() : "null",
tree3 != null ? tree3.toStringTree() : "null");

if( ctDir == null )
{

}
CommonTree
tree = new CommonTree(new CommonToken(type, "DIST"));

tree.addChild(tree1);
tree.addChild(tree3); // tree3 before tree2.
tree.addChild(tree2);

return tree;
} // encodeDIST

public static Tree check (String input, int index) {
ANTLRStringStream ss = new ANTLRStringStream(input);
c2ps_opPROXLexer lex = new c2ps_opPROXLexer(ss);
CommonTokenStream tokens = new CommonTokenStream(lex);
Expand Down

0 comments on commit 760fe93

Please sign in to comment.