Skip to content

Commit

Permalink
opBED: Korrektur von #BED(word,sa) ohne Leerzeichen vor dem Komma.
Browse files Browse the repository at this point in the history
Change-Id: If6289e2777d31b2319f807c969ec9381b468b891
  • Loading branch information
Bodmo committed Nov 7, 2023
1 parent cfbe25b commit 44769cc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
23 changes: 22 additions & 1 deletion src/main/antlr/cosmas/c2ps.g
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
//
// v0.7 - 25.07.23/FB
// - added: #REG(x)
// v0.8 - 06.11.23/FB
// - accepts #BED(searchword, sa) : comma attached to searchword.
// - more generally: comma at end of searchword, which is not enclosed by "..." is
// excluded from searchword.
// - a comma inside a searchword is accepted if enclosed by "...".
//
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

grammar c2ps;
Expand Down Expand Up @@ -124,8 +130,23 @@ SEARCHLEMMA
: '&' SEARCHWORD1 ; // rewrite rules funktionieren im lexer nicht: -> ^(OPLEM $SEARCHWORD1.text);

// SEARCHWORD2: schluckt Blanks. Diese müssen nachträglich als Wortdelimiter erkannt werden.

// current syntax, drawback is:
// e.g. aber, -> SEARCHWORD1 = "aber,"
// but correct should be -> SEARCHWORD1 = "aber"
//SEARCHWORD1
// : ~('"' | ' ' | '#' | ')' | '(' )+ ;

// new syntax (06.11.23/FB):
// accept for searchword1 either a single ',' or exclude trailing ',' from searchword1:
// E.g. Haus, -> searchword1=Haus.
// For a ',' inside a search word, see searchword2.
// exclude trailing "," from searchword1.
SEARCHWORD1
: ~('"' | ' ' | '#' | ')' | '(' )+ ;
: (',' | ~('"' | ' ' | '#' | ')' | '(' | ',')+) ;

// searchword2 accepts a ',' inside a searchword enclosed by "...".
// E.g. "Haus,tür": OK.

SEARCHWORD2
: '"' (~('"') | '\\"')+ '"' ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class Cosmas2QueryProcessor extends Antlr3AbstractQueryProcessor {

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

private static Logger log =
LoggerFactory.getLogger(Cosmas2QueryProcessor.class);
Expand Down Expand Up @@ -483,7 +483,7 @@ private void processOPREG (Tree node)
boolean
bDebug = false;

if( DEBUG )
if( bDebug )
{
//System.out.printf("Debug: processOPREG: node='%s' nChilds=%d.\n", node.toStringTree(), nChild+1);
System.out.printf("Debug: processOPREG: child: >>%s<< cat=%s type=%d.\n",
Expand Down Expand Up @@ -646,7 +646,8 @@ private void processOPIN_OPOV (Tree node) {
// Map<String, Object> posgroup =
// makePosition(null);
boolean isExclusion = isExclusion(node);

boolean bDebug = false;

int focusClassCounter = classCounter;
Map<String, Object> posGroup;

Expand All @@ -660,7 +661,7 @@ private void processOPIN_OPOV (Tree node) {
}
else {
posGroup = KoralObjectGenerator.makeGroup(KoralOperation.POSITION);
if (DEBUG) log.debug(posGroup.toString());
if (bDebug) log.debug(posGroup.toString());
}

Map<String, Object> positionOptions;
Expand Down Expand Up @@ -1607,7 +1608,9 @@ private Map<String, Object> wrap (Map<String, Object>[] wrapCascade) {
private void putIntoSuperObject (Map<String, Object> object, int objStackPosition)

{
if( DEBUG )
boolean bDebug = false;

if( bDebug )
{
System.out.printf("Debug: putIntosuperObject(<>,int): objectStack.size=%d objStackPos=%d object=%s.\n",
objectStack.size(), objStackPosition, object == null ? "null" : "not null");
Expand All @@ -1625,7 +1628,7 @@ private void putIntoSuperObject (Map<String, Object> object, int objStackPositio
ArrayList<Object> topObjectOperands =
(ArrayList<Object>) objectStack.get(objStackPosition).get("operands");

if( DEBUG )
if( bDebug )
System.out.printf("Debug: putIntosuperObject: topObjectOperands = [%s].\n", topObjectOperands == null ? "null" : "not null");

objectStack.get(objStackPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1925,4 +1925,28 @@ public void testREGremoveBlanksAtBothSides () {
StringUtils.removeBlanksAtBothSides(sb);
assertEquals("abc",sb.toString());
}

/* Testing #BED(expr,sa).
* 06.11.23/FB
*/

@Test
public void testBED () throws JsonProcessingException, IOException {

boolean
debug = true;
String
query = "#BED(Haus , se)";

qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
if( debug )
System.out.printf("testBED: query: >>%s<< -> key: >>%s<<.\n", query, res.at("/query/operands/0").asText());
/*
assertEquals("\"Abend\"-Ticket",res.at("/query/wrap/key").asText()); // key must be escaped, because converted to in "...".
assertEquals("type:regex", res.at("/query/wrap/type").asText());
assertEquals("orth", res.at("/query/wrap/layer").asText());
*/
}

}

0 comments on commit 44769cc

Please sign in to comment.