Added getStartPos(classNr) and getEndPos(classNr)
diff --git a/CHANGES b/CHANGES
index baed170..8006069 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,8 @@
-0.41 2014-09-05
+0.41 2014-09-17
+ - [feature] getStartPos(classNr) and getEndPos(classNr)
+ in KorapMatch (diewald)
+ - [bugfix] SpanExpansionQuery with fixed Constructor
+ and Exclusion handling (margaretha)
- [feature] Early implementation of match collector (diewald)
0.40 2014-09-03
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index 038f1cc..26cd3ca 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -84,6 +84,10 @@
import org.slf4j.LoggerFactory;
/*
+
+ TODO: DON'T STORE THE TEXT IN THE TOKENS FIELD!
+ It has only to be lifted for match views!!!
+
TODO: Support layer for specific foundries (IMPORTANT)
TODO: Implement timeout!!!
- https://lucene.apache.org/core/2_9_4/api/all/org/apache/lucene/search/TimeLimitingCollector.html
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index b014903..62fbebb 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -438,6 +438,26 @@
/**
+ * Get the positional start offset of the class.
+ *
+ * @param number Class number of the highlight.
+ */
+ @JsonIgnore
+ public int getStartPos (int number) {
+ if (number > 256 || this.highlight == null)
+ return -1;
+
+ // Iterate over highlights to find matching class
+ for (Highlight h : this.highlight) {
+ if (h.number == number)
+ return h.start;
+ };
+
+ return -1;
+ };
+
+
+ /**
* Set the positional start offset of the match.
*
* @param pos The positional offset.
@@ -452,12 +472,34 @@
* Get the positional end offset of the match.
*/
@JsonIgnore
- public int getEndPos() {
+ public int getEndPos () {
return this.endPos;
};
/**
+ * Get the positional end offset of the class.
+ *
+ * @param number Class number of the highlight.
+ */
+ @JsonIgnore
+ public int getEndPos (int number) {
+ if (number > 256 || this.highlight == null)
+ return -1;
+
+ // Iterate over highlights to find matching class
+ for (Highlight h : this.highlight) {
+
+ // Get the number (incremented by 1)
+ if (h.number == number)
+ return h.end + 1;
+ };
+
+ return -1;
+ };
+
+
+ /**
* Set the positional end offset of the match.
*
* @param pos The positional offset.
diff --git a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
index e9a214b..7541af6 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestHighlight.java
@@ -48,24 +48,44 @@
KorapQuery kq = new KorapQuery("tokens");
KorapResult kr = ki.search((SpanQuery) kq.seq(kq._(1, kq.seg("s:b"))).toQuery());
KorapMatch km = kr.getMatch(0);
+ assertEquals(km.getStartPos(), 1);
+ assertEquals(km.getEndPos(), 2);
+ assertEquals(km.getStartPos(1), 1);
+ assertEquals(km.getEndPos(1), 2);
assertEquals("<span class=\"context-left\">a</span><span class=\"match\"><em class=\"class-1 level-0\">b</em></span><span class=\"context-right\">c</span>", km.getSnippetHTML());
kr = ki.search((SpanQuery) kq.seq(kq._(1, kq.seg("s:b"))).append(kq._(2, kq.seg("s:c"))).toQuery());
km = kr.getMatch(0);
+ assertEquals(km.getStartPos(), 1);
+ assertEquals(km.getEndPos(), 3);
+ assertEquals(km.getStartPos(1), 1);
+ assertEquals(km.getEndPos(1), 2);
+ assertEquals(km.getStartPos(2), 2);
+ assertEquals(km.getEndPos(2), 3);
assertEquals("<span class=\"context-left\">a</span><span class=\"match\"><em class=\"class-1 level-0\">b</em><em class=\"class-2 level-0\">c</em></span><span class=\"context-right\"></span>", km.getSnippetHTML());
- kr = ki.search((SpanQuery) kq.seq(kq._(1, kq.seg("s:b"))).append(kq._(2, kq.seg("s:c"))).toQuery());
- km = kr.getMatch(0);
- assertEquals("<span class=\"context-left\">a</span><span class=\"match\"><em class=\"class-1 level-0\">b</em><em class=\"class-2 level-0\">c</em></span><span class=\"context-right\"></span>", km.getSnippetHTML());
-
kr = ki.search((SpanQuery) kq.seq(kq._(1, kq.seq(kq.seg("s:a")).append(kq.seg("s:b")))).append(kq._(2, kq.seg("s:c"))).toQuery());
km = kr.getMatch(0);
+ assertEquals(km.getStartPos(), 0);
+ assertEquals(km.getEndPos(), 3);
+ assertEquals(km.getStartPos(1), 0);
+ assertEquals(km.getEndPos(1), 2);
+ assertEquals(km.getStartPos(2), 2);
+ assertEquals(km.getEndPos(2), 3);
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><em class=\"class-1 level-0\">ab</em><em class=\"class-2 level-0\">c</em></span><span class=\"context-right\"></span>", km.getSnippetHTML());
kr = ki.search((SpanQuery) kq._(3, kq.seq(kq._(1, kq.seq(kq.seg("s:a")).append(kq.seg("s:b")))).append(kq._(2, kq.seg("s:c")))).toQuery());
km = kr.getMatch(0);
+ assertEquals(km.getStartPos(), 0);
+ assertEquals(km.getEndPos(), 3);
+ assertEquals(km.getStartPos(1), 0);
+ assertEquals(km.getEndPos(1), 2);
+ assertEquals(km.getStartPos(2), 2);
+ assertEquals(km.getEndPos(2), 3);
+ assertEquals(km.getStartPos(3), 0);
+ assertEquals(km.getEndPos(3), 3);
assertEquals("<span class=\"context-left\"></span><span class=\"match\"><em class=\"class-3 level-0\"><em class=\"class-1 level-1\">ab</em><em class=\"class-2 level-1\">c</em></em></span><span class=\"context-right\"></span>", km.getSnippetHTML());
};