Added match highlight to sentence scoped matchinfos
Change-Id: I6a1b914316d79394a3b3025b4eddc324f111d348
diff --git a/Changes b/Changes
index e643469..caaa268 100644
--- a/Changes
+++ b/Changes
@@ -14,6 +14,8 @@
- [feature] Added experimental KrillStats class (diewald)
- [bugfix] Escape quotes in JSON strings (diewald)
- [bugfix] Escape XML and Brackets in snippets correctly (diewald)
+ - [feature] Added match highlight to match API,
+ in case the match was extended to the sentence scope (diewald)
0.55.5 2016-05-02
- [performance] Changed to a dynamic window for sorting in FocusSpans (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 97576cf..48ce9d0 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -918,6 +918,8 @@
if (match.getStartPos() == -1)
return match;
+ // Todo: add match-highlight
+
// Create a filter based on the corpusID and the docID
BooleanQuery bool = new BooleanQuery();
if (match.getTextSigle() != null) {
@@ -944,7 +946,6 @@
if (DEBUG)
log.trace("The bool query is {}", bool.toString());
-
Filter filter = (Filter) new QueryWrapperFilter(bool);
CompiledAutomaton fst = null;
@@ -1098,6 +1099,11 @@
String element = "base/s:s";
int[] spanContext = match.expandContextToSpan(element);
+ // Add match highlight with class number -1
+ // TODO: This is very specific behaviour here and should probably
+ // be added elsewhere, too.
+ match.addHighlight(match.getStartPos(), match.getEndPos() - 1, -1);
+
if (DEBUG)
log.trace("Extend to sentence element '{}'", element);
diff --git a/src/main/java/de/ids_mannheim/korap/response/Match.java b/src/main/java/de/ids_mannheim/korap/response/Match.java
index a3aeee7..acba433 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -192,6 +192,7 @@
public Highlight (int start, int end, String annotation) {
this.start = start;
this.end = end;
+
// TODO: This can overflow!
if (annotationNumberCounter < 2048) {
this.number = annotationNumberCounter++;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
index 03bafcc..8b1985f 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -94,12 +94,6 @@
id = new MatchIdentifier("match-corpus-1/doc-1/text-1/p2105-2106");
assertEquals("match-corpus-1/doc-1/text-1-p2105-2106", id.toString());
assertEquals("corpus-1/doc-1/text-1", id.getTextSigle());
- /*
- assertEquals(2105, id.getStartPos());
- assertEquals(2106, id.getEndPos());
- assertEquals(null, id.getCorpusID());
- assertEquals(null, id.getDocID());
- */
};
@@ -415,9 +409,45 @@
km = ki.getMatchInfo("match-c1!d1-p3-4", "tokens", null, null, false,
false, true); // extendToSentence
+ // This will
+ // [{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:c}}}}{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}{f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:b}}}}]
assertEquals(
- "[{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:c}}}}{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}{f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:b}}}}]",
+ "[{f/m:drei:{f/y:three:{it/is:3:{x/o:drittens:c}}}}[{f/m:vier:{f/y:four:{it/is:4:{x/o:viertens:a}}}}]{f/m:fuenf:{f/y:five:{it/is:5:{x/o:fünftens:b}}}}]",
km.getSnippetBrackets());
+
+ assertEquals(
+ "<span class=\"context-left\"></span>"+
+ "<mark>"+
+ "<span title=\"f/m:drei\">"+
+ "<span title=\"f/y:three\">"+
+ "<span title=\"it/is:3\">"+
+ "<span title=\"x/o:drittens\">c</span>"+
+ "</span>"+
+ "</span>"+
+ "</span>"+
+ "<mark>"+
+ "<span title=\"f/m:vier\">"+
+ "<span title=\"f/y:four\">"+
+ "<span title=\"it/is:4\">"+
+ "<span title=\"x/o:viertens\">a</span>"+
+ "</span>"+
+ "</span>"+
+ "</span>"+
+ "</mark>"+
+ "<span title=\"f/m:fuenf\">"+
+ "<span title=\"f/y:five\">"+
+ "<span title=\"it/is:5\">"+
+ "<span title=\"x/o:fünftens\">b</span>"+
+ "</span>"+
+ "</span>"+
+ "</span>"+
+ "</mark>"+
+ "<span class=\"context-right\"></span>",
+ km.getSnippetHTML());
+
+
+
+
/*
km = ki.getMatchInfo("match-c1!d3-p3-4", "tokens", null, null, false,
false, true); // extendToSentence