Skip to content

Commit

Permalink
opLEM: removed debug output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodmo committed Dec 12, 2024
1 parent 8b0ee4a commit b75338b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 67 deletions.
5 changes: 3 additions & 2 deletions doTestQuery
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ QL="cosmas2"

Query="&Fes-&Mann"
Query="&Mann+"
#Query="ab /s0 &?&+&*&Mann"

Query="ab /s &Mann"
#Query="&Manno*"

echo -e "Query = '$Query' in QL='$QL'..."

#java -jar $KJAR $MCL "$Query" $QL -show
Expand Down
2 changes: 1 addition & 1 deletion src/main/antlr/cosmas/c2ps.g
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// excluded from searchword now.
// - a comma inside a searchword is accepted if enclosed by "...".
// 10.12.24/FB
// - skip wildcards [?*+] in lemma search expression, as regex/wildcards are not allowed
// - reject wildcards [?*+] in lemma search expression, as regex/wildcards are not allowed
// in &opts&lemma, but instead they may appear as options in 'opts'.
// E.g. &F+&Prüfung -> lemma with F+ as an option.
// - test added for F+.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class c2ps_opREG

{
private static boolean DEBUG = true;
private static boolean DEBUG = false;

/*
* encode():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
public class c2ps_opWF

{
//static final int OPWF = 5; // must be same value than OPWF in c2ps_opWF.g
//static final int OPLEM = 7; // must be same value than OPLEM in c2ps_opWF.g
/* Arguments:
static final boolean bDebug = false;

/* check:
* Arguments:
* bStrip: true: 'input' contains "wort" -> strip " away -> wort.
* false: 'input' contains no " -> nothing to strip.
* bLem: true: input contains a Lemma; generates tree ^(OPLEM...).
Expand All @@ -26,13 +27,6 @@ public class c2ps_opWF

public static Tree check (String input, boolean bStrip, boolean bLem, int pos)
{
if( bLem )
{
System.out.printf("c2ps_opWF.check: input='%s' bStrip=%b bLem=%b pos=%d.\n",
input, bStrip, bLem, pos);
System.out.flush();
}

if (bStrip)
input = input.substring(1, input.length() - 1);

Expand Down Expand Up @@ -66,7 +60,7 @@ public static Tree check (String input, boolean bStrip, boolean bLem, int pos)
// AST Tree anzeigen:
Tree tree = bLem ? (Tree)c2PQLEMReturn.getTree() : (Tree)c2PQWFReturn.getTree();

if( bLem )
if( bDebug && bLem )
{
System.out.printf("c2ps_opWF.check: %s: '%s'.\n", bLem ? "opLEM" : "opWF",
tree.toStringTree() );
Expand Down Expand Up @@ -104,6 +98,8 @@ public static Tree encode (String wf, int tokenType, int pos)
sbWF.deleteCharAt(i);
}

// reject wildcards in lemmata:

if( tokenType == c2ps_opWFLexer.OPLEM )
{
boolean hasOpts = false; // true if a '&' occurs: e.g. "Fes+C&lemma"
Expand All @@ -125,65 +121,17 @@ else if (sbWF.charAt(i) == '?' || sbWF.charAt(i) == '*' || sbWF.charAt(i) == '+'
// error if hasFound==true:
if( hasFound )
{
System.out.printf("c2ps_opWF.encode: Syntax error: '%s' contains wildcards inside lemma expression!\n", wf);
return buildErrorTree(wf, StatusCodes.ERR_LEM_WILDCARDS, pos);
if( bDebug )
System.out.printf("c2ps_opWF.encode: Syntax error: '%s' contains wildcards inside lemma expression!\n", wf);
return StatusCodes.buildErrorTree(wf, StatusCodes.ERR_LEM_WILDCARDS, pos);
}
}

return new CommonTree(new CommonToken(tokenType, "\"" + sbWF.toString() + "\""));
}

/**
* 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)

private static CommonTree buildErrorTree(String text, int errCode, int pos)
{
/*
CommonTree
//errorTree = new CommonTree(new CommonToken(typeDIST, "DIST"));
errorTree = new CommonTree(new CommonToken(c2ps_opPROX.typeERROR, "Fehlercherchen"));
*/
CommonTree
errorNode = new CommonTree(new CommonToken(c2ps_opPROX.typeERROR, "ERROR"));
CommonTree
errorPos = new CommonTree(new CommonToken(c2ps_opPROX.typeERROR, String.valueOf(pos)));
CommonTree
errorCode = new CommonTree(new CommonToken(c2ps_opPROX.typeERROR, String.valueOf(errCode)));
CommonTree
errorMes;
String
mess;

mess = c2ps_opPROX.getErrMess(errCode, c2ps_opPROX.messLang, text);
errorMes = new CommonTree(new CommonToken(c2ps_opPROX.typeERROR, mess));

// new:
errorNode.addChild(errorPos);
errorNode.addChild(errorCode);
errorNode.addChild(errorMes);

return errorNode;

/* old, no need for errorTree(typeXY).
errorTree.addChild(errorNode);
errorNode.addChild(errorPos);
errorNode.addChild(errorCode);
errorNode.addChild(errorMes);
return errorTree;
*/
}

/*
* main testprogram:
* main testprogram
*/

public static void main (String args[]) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package de.ids_mannheim.korap.query.serialize.util;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.tree.CommonTree;

import de.ids_mannheim.korap.query.parse.cosmas.c2ps_opPROX;

public class StatusCodes {

// type of an Error CommonToken:
public final static int typeERROR = 1;

public final static int NO_QUERY = 301;
public final static int MALFORMED_QUERY = 302;
public final static int DEPRECATED_QUERY_ELEMENT = 303;
Expand All @@ -26,4 +35,54 @@ public class StatusCodes {

// error codes for WF and LEM syntax/semantic errors:
public final static int ERR_LEM_WILDCARDS = 350;


/**
* 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)

public static CommonTree buildErrorTree(String text, int errCode, int pos)
{
/*
CommonTree
//errorTree = new CommonTree(new CommonToken(typeDIST, "DIST"));
errorTree = new CommonTree(new CommonToken(c2ps_opPROX.typeERROR, "Fehlercherchen"));
*/
CommonTree
errorNode = new CommonTree(new CommonToken(typeERROR, "ERROR"));
CommonTree
errorPos = new CommonTree(new CommonToken(typeERROR, String.valueOf(pos)));
CommonTree
errorCode = new CommonTree(new CommonToken(typeERROR, String.valueOf(errCode)));
CommonTree
errorMes;
String
mess;

mess = c2ps_opPROX.getErrMess(errCode, c2ps_opPROX.messLang, text);
errorMes = new CommonTree(new CommonToken(typeERROR, mess));

// new:
errorNode.addChild(errorPos);
errorNode.addChild(errorCode);
errorNode.addChild(errorMes);

return errorNode;

/* old, no need for errorTree(typeXY).
errorTree.addChild(errorNode);
errorNode.addChild(errorPos);
errorNode.addChild(errorCode);
errorNode.addChild(errorMes);
return errorTree;
*/
}
}

0 comments on commit b75338b

Please sign in to comment.