Handled ClassPTI in FocusSpans and added Class PTIs in relation,
reference and expansion spans.
Change-Id: Ifc7e3e28bbaef045a4614230a09f8a06fd217a21
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java
index 16878f4..679b430 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java
@@ -33,8 +33,6 @@
protected SpanQuery operand;
protected Boolean hasmorespans = false;
- protected ByteBuffer bb;
-
private final Logger log = LoggerFactory.getLogger(ClassSpans.class);
// This advices the java compiler to ignore all loggings
@@ -70,7 +68,6 @@
// The highlighted payload
this.classedPayload = new ArrayList<byte[]>(3);
- this.bb = ByteBuffer.allocate(10);
};
@@ -146,8 +143,11 @@
};
// Todo: Better allocate using a Factory!
- bb.clear();
- bb.put((byte) 0).putInt(spans.start()).putInt(spans.end()).put(number);
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ bb.put((byte) 0);
+ bb.putInt(spans.start());
+ bb.putInt(spans.end());
+ bb.put(number);
/*
System.err.println(
"####################### " +
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java
index 6b6fee0..b510282 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java
@@ -332,7 +332,9 @@
* @return a byte array of extension offsets and class number
*/
private byte[] createExtensionPayloads (int start, int end) {
- ByteBuffer buffer = ByteBuffer.allocate(9);
+ ByteBuffer buffer = ByteBuffer.allocate(10);
+ Byte classPTI = 0;
+ buffer.put(classPTI);
buffer.putInt(start);
buffer.putInt(end);
buffer.put(classNumber);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
index 29e8900..14d9746 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
@@ -176,7 +176,9 @@
* @return a byte array of extension offsets and the class number
*/
private byte[] createExtensionPayloads (int start, int end) {
- ByteBuffer buffer = ByteBuffer.allocate(9);
+ ByteBuffer buffer = ByteBuffer.allocate(10);
+ Byte classPTI = 0;
+ buffer.put(classPTI);
buffer.putInt(start);
buffer.putInt(end);
buffer.put(classNumber);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java
index b134c72..84fe076 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java
@@ -165,37 +165,35 @@
for (byte[] payload : firstSpans.getPayload()) {
// No class payload - ignore
// this may be problematic for other calculated payloads!
- /*
- if ((!matchTemporaryClass && payload.length == 9)
- || (matchTemporaryClass && payload.length == 10)) {
- */
- if (payload[0] == 0) {
- if (classNumbers.contains(payload[9])) {
- isClassFound = true;
- classStart = byte2int(payload, 1);
- classEnd = byte2int(payload, 5);
+ if ((!matchTemporaryClass && payload.length == 10)
+ || (matchTemporaryClass && payload.length == 11)) {
- if (isStart || classStart < minPos) {
- minPos = classStart;
- isStart = false;
+ if (payload[0] == 0) {
+ if (classNumbers.contains(payload[9])) {
+ isClassFound = true;
+ classStart = byte2int(payload, 1);
+ classEnd = byte2int(payload, 5);
+
+ if (isStart || classStart < minPos) {
+ minPos = classStart;
+ isStart = false;
+ }
+ if (classEnd > maxPos) {
+ maxPos = classEnd;
+ }
}
- if (classEnd > maxPos) {
- maxPos = classEnd;
- }
+
+ if (removeTemporaryClasses) {
+ continue;
+ };
}
+ }
- if (removeTemporaryClasses) {
- continue;
- };
- }
-
- /*
- if (payload.length == 8
- || (removeTemporaryClasses && payload.length == 10)) {
+ if (//payload.length == 8 ||
+ (removeTemporaryClasses && payload.length == 11)) {
continue;
}
- */
candidateSpan.getPayloads().add(payload.clone());
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java
index 7d855e0..e17bdcf 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java
@@ -51,10 +51,10 @@
matchPayload.clear();
for (byte[] payload : firstSpans.getPayload()) {
- if (payload.length == 9 && payload[8] == classNum) {
+ if (payload.length == 10 && payload[9] == classNum) {
if (isFound) {
- if (start == byte2int(payload, 0)
- && end == byte2int(payload, 4)) {
+ if (start == byte2int(payload, 1)
+ && end == byte2int(payload, 5)) {
match = true;
continue;
}
@@ -62,8 +62,8 @@
break;
}
- start = byte2int(payload, 0);
- end = byte2int(payload, 4);
+ start = byte2int(payload, 1);
+ end = byte2int(payload, 5);
isFound = true;
matchPayload.add(payload);
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
index 72cfc82..c8306ea 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
@@ -285,11 +285,13 @@
boolean keep) {
ByteBuffer buffer = null;
if (keep) {
- buffer = ByteBuffer.allocate(9);
+ buffer = ByteBuffer.allocate(10);
}
else {
- buffer = ByteBuffer.allocate(10);
+ buffer = ByteBuffer.allocate(11);
}
+ Byte classPTI = 0;
+ buffer.put(classPTI);
buffer.putInt(start);
buffer.putInt(end);
buffer.put(classNumber);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java
index e40fbc4..b7125d5 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestReferenceIndex.java
@@ -21,6 +21,7 @@
import de.ids_mannheim.korap.query.SpanRelationMatchQuery;
import de.ids_mannheim.korap.query.SpanRelationQuery;
import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
+import de.ids_mannheim.korap.response.Match;
import de.ids_mannheim.korap.response.Result;
import de.ids_mannheim.korap.util.QueryException;
@@ -70,12 +71,12 @@
SpanReferenceQuery ref = new SpanReferenceQuery(sdq, (byte) 3, true);
// System.out.println(ref.toString());
- kr = ki.search(ref, (short) 10);
- // for (Match km : kr.getMatches()) {
- // System.out.println(km.getStartPos() + "," + km.getEndPos()
- // + " "
- // + km.getSnippetBrackets());
- // }
+ kr = ki.search(ref, (short) 10);
+ for (Match km : kr.getMatches()) {
+ System.out.println(km.getStartPos() + "," + km.getEndPos() + " "
+ + km.getSnippetBrackets());
+ }
+ System.out.println(kr.getTotalResults());
assertEquals(
"spanReference(spanDistance(focus(1: focus(#[1,2]spanSegment("
+ "focus(#1: spanSegment(spanRelation(base:<:child-of), focus(2: spanNext("