Support serialization of different relation types (a bit hacky)
Change-Id: Ie5b34958dd4f677f5cc6b7b101a397a5671be7dd
diff --git a/src/main/java/de/ids_mannheim/korap/index/TermInfo.java b/src/main/java/de/ids_mannheim/korap/index/TermInfo.java
index 3f132c2..eb8472e 100644
--- a/src/main/java/de/ids_mannheim/korap/index/TermInfo.java
+++ b/src/main/java/de/ids_mannheim/korap/index/TermInfo.java
@@ -183,6 +183,8 @@
this.targetStartPos = this.payload.getInt();
this.targetEndPos = this.payload.getInt();
}
+
+ // Span to token
else if (pti == 34) {
/*
* 1 byte for PTI (34),
@@ -192,6 +194,11 @@
* 1 integer for end position of the right part, and
* and 0-3 TUIs as above.
*/
+
+ // Ignore offsets
+ this.payload.getInt();
+ this.endPos = this.payload.getInt();
+ this.targetStartPos = this.payload.getInt();
}
else if (pti == 35) {
/*
@@ -205,6 +212,16 @@
* 1 integer for end position of the right part,
* and 0-3 TUIs as above.
*/
+
+ // Ignore offsets
+ this.payload.getInt();
+ this.payload.getInt();
+ this.payload.getInt();
+ this.payload.getInt();
+
+ this.endPos = this.payload.getInt();
+ this.targetStartPos = this.payload.getInt();
+ this.targetEndPos = this.payload.getInt();
}
else {
this.endPos = this.payload.getInt() - 1;
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 7b9e09d..7d6670e 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -216,12 +216,12 @@
public int number = -1;
// Relational highlight
- public Highlight (int start, int end, String annotation, int ref) {
+ public Highlight (int start, int end, String annotation, int refStart, int refEnd) {
this.start = start;
this.end = end;
// TODO: This can overflow!
this.number = relationNumberCounter++;
- relationNumber.put(this.number, new Relation(annotation, ref));
+ relationNumber.put(this.number, new Relation(annotation, refStart, refEnd));
};
@@ -438,10 +438,10 @@
if (srcEnd == -1) {
// Add source token
- this.addHighlight(new Highlight(srcStart, srcStart, annotation, targetStart));
+ this.addHighlight(new Highlight(srcStart, srcStart, annotation, targetStart, targetEnd));
}
else {
- this.addHighlight(new Highlight(srcStart, srcEnd, annotation, targetStart));
+ this.addHighlight(new Highlight(srcStart, srcEnd, annotation, targetStart, targetEnd));
};
int id = identifierNumberCounter--;
@@ -684,15 +684,27 @@
return id;
};
-
/**
* Get identifier for a specific position.
*
* @param int
* Position to get identifier on.
*/
- @JsonIgnore
+ @JsonIgnore
public String getPosID (int pos) {
+ return this.getPosID(pos, -1);
+ };
+
+ /**
+ * Get identifier for a specific position.
+ *
+ * @param int
+ * Start position to get identifier on.
+ * @param int
+ * End position to get identifier on.
+ */
+ @JsonIgnore
+ public String getPosID (int start, int end) {
if (DEBUG)
log.trace("Retrieve the identifier for pos");
@@ -713,7 +725,8 @@
id.setDocID(this.getDocID());
// </legacy>
id.setTextSigle(this.getTextSigle());
- id.setPos(pos);
+ id.setStart(start);
+ id.setEnd(end);
if (DEBUG)
log.trace(
@@ -722,7 +735,7 @@
this.getTextSigle(),
this.getCorpusID(),
this.getDocID(),
- pos
+ start
);
return id.toString();
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinatorElement.java b/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinatorElement.java
index 9270847..93e4ff2 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinatorElement.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinatorElement.java
@@ -89,14 +89,14 @@
if (DEBUG) {
log.trace("Annotation is a relation with id {}", this.number);
- log.trace("Resulting in relation {}: {}", rel.annotation, rel.ref);
+ log.trace("Resulting in relation {}: {}-{}", rel.annotation, rel.refStart, rel.refEnd);
};
sb.append("xlink:title=\"")
- .append(escapeHTML(rel.annotation))
- .append("\" xlink:type=\"simple\" xlink:href=\"#")
- .append(escapeHTML(match.getPosID(rel.ref)))
- .append('"');
+ .append(escapeHTML(rel.annotation))
+ .append("\" xlink:type=\"simple\" xlink:href=\"#")
+ .append(escapeHTML(match.getPosID(rel.refStart, rel.refEnd)))
+ .append('"');
};
sb.append('>');
}
@@ -168,7 +168,10 @@
else {
Relation rel = match.getRelationID(this.number);
sb.append(rel.annotation);
- sb.append('>').append(rel.ref);
+ sb.append('>').append(rel.refStart);
+
+ if (rel.refEnd != -1)
+ sb.append('-').append(rel.refEnd);
};
sb.append(':');
}
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/PosIdentifier.java b/src/main/java/de/ids_mannheim/korap/response/match/PosIdentifier.java
index a7f7729..f854b0d 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/PosIdentifier.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/PosIdentifier.java
@@ -3,21 +3,29 @@
import java.util.*;
public class PosIdentifier extends DocIdentifier {
- private int pos;
+ private int start = -1;
+ private int end = -1;
public PosIdentifier () {};
- public void setPos (int pos) {
+ public void setStart (int pos) {
if (pos >= 0)
- this.pos = pos;
+ this.start = pos;
};
-
- public int getPos () {
- return this.pos;
+ public int getStart () {
+ return this.start;
};
+ public void setEnd (int pos) {
+ if (pos >= 0)
+ this.end = pos;
+ };
+
+ public int getEnd () {
+ return this.end;
+ };
public String toString () {
if (this.textSigle == null && this.docID == null)
@@ -40,7 +48,9 @@
};
sb.append("-p");
- sb.append(this.pos);
+ sb.append(this.getStart());
+ if (this.getEnd() != -1)
+ sb.append("-").append(this.end);
return sb.toString();
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/Relation.java b/src/main/java/de/ids_mannheim/korap/response/match/Relation.java
index fc34b23..c54a3d8 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/Relation.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/Relation.java
@@ -4,12 +4,13 @@
* Class for relational highlights.
*/
public class Relation {
- public int ref;
+ public int refStart;
+ public int refEnd;
public String annotation;
-
- public Relation (String annotation, int ref) {
+ public Relation (String annotation, int refStart, int refEnd) {
this.annotation = annotation;
- this.ref = ref;
+ this.refStart = refStart;
+ this.refEnd = refEnd;
};
};
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 f6c6bf5..20c680d 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIdentifier.java
@@ -103,13 +103,27 @@
PosIdentifier id = new PosIdentifier();
id.setCorpusID("c1");
id.setDocID("d1");
- id.setPos(8);
+ id.setStart(8);
assertEquals(id.getCorpusID(), "c1");
assertEquals(id.getDocID(), "d1");
- assertEquals(id.getPos(), 8);
+ assertEquals(id.getStart(), 8);
assertEquals(id.toString(), "token-c1!d1-p8");
};
+ @Test
+ public void posIdentifierExample2 () throws IOException {
+ PosIdentifier id = new PosIdentifier();
+ id.setCorpusID("c1");
+ id.setDocID("d1");
+ id.setStart(8);
+ id.setEnd(12);
+ assertEquals(id.getCorpusID(), "c1");
+ assertEquals(id.getDocID(), "d1");
+ assertEquals(id.getStart(), 8);
+ assertEquals(id.getEnd(), 12);
+ assertEquals(id.toString(), "token-c1!d1-p8-12");
+ };
+
@Test
public void indexExample1 () throws IOException {