autoformat
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java b/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java
index 8680742..2526e94 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/DocIdentifier.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.response.match;
+
import java.util.*;
import java.util.regex.*;
@@ -6,19 +7,23 @@
public class DocIdentifier {
protected String corpusID, docID;
+
public String getCorpusID () {
return this.corpusID;
};
+
public void setCorpusID (String id) {
if (id != null && !id.contains("!"))
this.corpusID = id;
};
+
public String getDocID () {
return this.docID;
};
+
public void setDocID (String id) {
if (id != null && !id.contains("!"))
this.docID = id;
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinator.java b/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinator.java
index adce408..8292e4a 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinator.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/HighlightCombinator.java
@@ -21,56 +21,65 @@
private LinkedList<HighlightCombinatorElement> combine;
private Stack<Integer> balanceStack = new Stack<>();
- private Stack<Integer> tempStack = new Stack<>();
+ private Stack<Integer> tempStack = new Stack<>();
+
// Empty constructor
public HighlightCombinator () {
this.combine = new LinkedList<>();
};
+
// Return the combination list
public LinkedList<HighlightCombinatorElement> list () {
return this.combine;
};
+
// get the first element (without removing)
public HighlightCombinatorElement getFirst () {
return this.combine.getFirst();
};
+
// get the last element (without removing)
public HighlightCombinatorElement getLast () {
return this.combine.getLast();
};
+
// get an element by index (without removing)
public HighlightCombinatorElement get (int index) {
return this.combine.get(index);
};
+
// Get the size of the combinator stack
public short size () {
return (short) this.combine.size();
};
+
// Add primary data to the stack
public void addString (String characters) {
this.combine.add(new HighlightCombinatorElement(characters));
};
+
// Add opening highlight combinator to the stack
public void addOpen (int number) {
this.combine.add(new HighlightCombinatorElement((byte) 1, number));
this.balanceStack.push(number);
};
+
// Add closing highlight combinator to the stack
public void addClose (int number) {
HighlightCombinatorElement lastComb;
// Clean up temporary stack
this.tempStack.clear();
-
+
// Check if there is an opening tag at least
if (this.balanceStack.empty()) {
if (DEBUG)
@@ -80,7 +89,8 @@
// Just some debug information
if (DEBUG) {
- StringBuilder sb = new StringBuilder("Stack for checking with class ");
+ StringBuilder sb = new StringBuilder(
+ "Stack for checking with class ");
sb.append(number).append(" is ");
for (int s : this.balanceStack) {
sb.append('[').append(s).append(']');
@@ -91,26 +101,22 @@
// class number of the last element
// It's already ensured the stack is not empty
int eold = this.balanceStack.pop();
-
+
// the closing element is not balanced, i.e. the last element differs
while (eold != number) {
-
+
// Retrieve last combinator on stack
lastComb = this.combine.peekLast();
-
+
if (DEBUG)
- log.trace("Closing element is unbalanced - {} " +
- "!= {} with lastComb {}|{}|{}",
- eold,
- number,
- lastComb.type,
- lastComb.number,
- lastComb.characters);
+ log.trace("Closing element is unbalanced - {} "
+ + "!= {} with lastComb {}|{}|{}", eold, number,
+ lastComb.type, lastComb.number, lastComb.characters);
// combinator is opening and the number is not equal to the last
// element on the balanceStack
if (lastComb.type == 1 && lastComb.number == eold) {
-
+
// Remove the last element - it's empty and uninteresting!
this.combine.removeLast();
}
@@ -120,9 +126,10 @@
if (DEBUG)
log.trace("close element a) {}", eold);
-
+
// Add a closer for the old element (this has following elements)
- this.combine.add(new HighlightCombinatorElement((byte) 2, eold, false));
+ this.combine.add(new HighlightCombinatorElement((byte) 2, eold,
+ false));
};
// add this element number temporarily on the stack
@@ -136,20 +143,12 @@
lastComb = this.combine.peekLast();
if (DEBUG) {
- log.trace("LastComb: " +
- lastComb.type +
- '|' +
- lastComb.number +
- '|' + lastComb.characters +
- " for " +
- number);
- log.trace("Stack for checking 2: {}|{}|{}|{}",
- lastComb.type,
- lastComb.number,
- lastComb.characters,
- number);
+ log.trace("LastComb: " + lastComb.type + '|' + lastComb.number
+ + '|' + lastComb.characters + " for " + number);
+ log.trace("Stack for checking 2: {}|{}|{}|{}", lastComb.type,
+ lastComb.number, lastComb.characters, number);
};
-
+
if (lastComb.type == 1 && lastComb.number == number) {
while (lastComb.type == 1 && lastComb.number == number) {
// Remove the damn thing - It's empty and uninteresting!
@@ -160,7 +159,7 @@
else {
if (DEBUG)
log.trace("close element b) {}", number);
-
+
// Add a closer
this.combine.add(new HighlightCombinatorElement((byte) 2, number));
};
@@ -174,6 +173,7 @@
};
};
+
// Get all combined elements as a string
public String toString () {
StringBuilder sb = new StringBuilder();
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 8eee7f0..55837b8 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
@@ -22,29 +22,33 @@
public String characters;
public boolean terminal = true;
+
// Constructor for highlighting elements
public HighlightCombinatorElement (byte type, int number) {
this.type = type;
this.number = number;
};
+
// Constructor for highlighting elements,
// that may not be terminal, i.e. they were closed and will
// be reopened for overlapping issues.
public HighlightCombinatorElement (byte type, int number, boolean terminal) {
- this.type = type;
- this.number = number;
+ this.type = type;
+ this.number = number;
this.terminal = terminal;
};
+
// Constructor for textual data
public HighlightCombinatorElement (String characters) {
this.type = (byte) 0;
this.characters = characters;
};
+
// Return html fragment for this combinator element
- public String toHTML (Match match, FixedBitSet level, byte[] levelCache) {
+ public String toHTML (Match match, FixedBitSet level, byte[] levelCache) {
// Opening
if (this.type == 1) {
StringBuilder sb = new StringBuilder();
@@ -54,24 +58,22 @@
else if (this.number < -1) {
sb.append("<span xml:id=\"")
- .append(match.getPosID(match.getClassID(this.number)))
- .append("\">");
+ .append(match.getPosID(match.getClassID(this.number)))
+ .append("\">");
}
-
+
else if (this.number >= 256) {
sb.append("<span ");
if (this.number < 2048) {
sb.append("title=\"")
- .append(match.getAnnotationID(this.number))
- .append('"');
+ .append(match.getAnnotationID(this.number))
+ .append('"');
}
else {
Relation rel = match.getRelationID(this.number);
- sb.append("xlink:title=\"")
- .append(rel.annotation)
- .append("\" xlink:type=\"simple\" xlink:href=\"#")
- .append(match.getPosID(rel.ref))
- .append('"');
+ sb.append("xlink:title=\"").append(rel.annotation)
+ .append("\" xlink:type=\"simple\" xlink:href=\"#")
+ .append(match.getPosID(rel.ref)).append('"');
};
sb.append('>');
}
@@ -88,11 +90,8 @@
level.clear(pos);
levelCache[this.number] = pos;
};
- sb.append("<mark class=\"class-")
- .append(this.number)
- .append(" level-")
- .append(pos)
- .append("\">");
+ sb.append("<mark class=\"class-").append(this.number)
+ .append(" level-").append(pos).append("\">");
};
return sb.toString();
}
@@ -100,59 +99,60 @@
else if (this.type == 2) {
if (this.number < -1 || this.number >= 256)
return "</span>";
-
+
if (this.number == -1)
return "</mark>";
-
+
if (this.terminal)
level.set((int) levelCache[this.number]);
return "</mark>";
- };
+ };
- // HTML encode primary data
- return escapeHTML(this.characters);
+ // HTML encode primary data
+ return escapeHTML(this.characters);
};
+
// Return bracket fragment for this combinator element
public String toBrackets (Match match) {
- if (this.type == 1) {
- StringBuilder sb = new StringBuilder();
-
- // Match
- if (this.number == -1) {
- sb.append("[");
- }
+ if (this.type == 1) {
+ StringBuilder sb = new StringBuilder();
- // Identifier
- else if (this.number < -1) {
- sb.append("{#");
- sb.append(match.getClassID(this.number));
- sb.append(':');
- }
+ // Match
+ if (this.number == -1) {
+ sb.append("[");
+ }
- // Highlight, Relation, Span
- else {
- sb.append("{");
- if (this.number >= 256) {
- if (this.number < 2048)
- sb.append(match.getAnnotationID(this.number));
- else {
- Relation rel = match.getRelationID(this.number);
- sb.append(rel.annotation);
- sb.append('>').append(rel.ref);
- };
- sb.append(':');
- }
- else if (this.number != 0)
- sb.append(this.number).append(':');
- };
- return sb.toString();
- }
- else if (this.type == 2) {
- if (this.number == -1)
- return "]";
- return "}";
- };
- return this.characters;
+ // Identifier
+ else if (this.number < -1) {
+ sb.append("{#");
+ sb.append(match.getClassID(this.number));
+ sb.append(':');
+ }
+
+ // Highlight, Relation, Span
+ else {
+ sb.append("{");
+ if (this.number >= 256) {
+ if (this.number < 2048)
+ sb.append(match.getAnnotationID(this.number));
+ else {
+ Relation rel = match.getRelationID(this.number);
+ sb.append(rel.annotation);
+ sb.append('>').append(rel.ref);
+ };
+ sb.append(':');
+ }
+ else if (this.number != 0)
+ sb.append(this.number).append(':');
+ };
+ return sb.toString();
+ }
+ else if (this.type == 2) {
+ if (this.number == -1)
+ return "]";
+ return "}";
+ };
+ return this.characters;
};
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java b/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java
index 5b954d6..5f13a3b 100644
--- a/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java
+++ b/src/main/java/de/ids_mannheim/korap/response/match/MatchIdentifier.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.response.match;
+
import java.util.*;
import java.util.regex.*;
@@ -7,16 +8,15 @@
private ArrayList<int[]> pos = new ArrayList<>(8);
- Pattern idRegex = Pattern.compile(
- "^match-(?:([^!]+?)!)?" +
- "([^!]+)-p([0-9]+)-([0-9]+)" +
- "((?:\\(-?[0-9]+\\)-?[0-9]+--?[0-9]+)*)" +
- "(?:c.+?)?$");
- Pattern posRegex = Pattern.compile(
- "\\(([0-9]+)\\)([0-9]+)-([0-9]+)");
+ Pattern idRegex = Pattern.compile("^match-(?:([^!]+?)!)?"
+ + "([^!]+)-p([0-9]+)-([0-9]+)"
+ + "((?:\\(-?[0-9]+\\)-?[0-9]+--?[0-9]+)*)" + "(?:c.+?)?$");
+ Pattern posRegex = Pattern.compile("\\(([0-9]+)\\)([0-9]+)-([0-9]+)");
+
public MatchIdentifier () {};
-
+
+
public MatchIdentifier (String id) {
Matcher matcher = idRegex.matcher(id);
if (matcher.matches()) {
@@ -28,45 +28,51 @@
if (matcher.group(5) != null) {
matcher = posRegex.matcher(matcher.group(5));
while (matcher.find()) {
- this.addPos(
- Integer.parseInt(matcher.group(2)),
- Integer.parseInt(matcher.group(3)),
- Integer.parseInt(matcher.group(1))
- );
+ this.addPos(Integer.parseInt(matcher.group(2)),
+ Integer.parseInt(matcher.group(3)),
+ Integer.parseInt(matcher.group(1)));
};
};
};
};
+
public int getStartPos () {
return this.startPos;
};
+
public void setStartPos (int pos) {
if (pos >= 0)
this.startPos = pos;
};
+
public int getEndPos () {
return this.endPos;
};
+
public void setEndPos (int pos) {
if (pos >= 0)
this.endPos = pos;
};
- public void addPos(int start, int end, int number) {
+
+ public void addPos (int start, int end, int number) {
if (start >= 0 && end >= 0 && number >= 0)
- this.pos.add(new int[]{start, end, number});
+ this.pos.add(new int[] { start, end, number });
};
+
public ArrayList<int[]> getPos () {
return this.pos;
};
+
public String toString () {
- if (this.docID == null) return null;
+ if (this.docID == null)
+ return null;
StringBuilder sb = new StringBuilder("match-");
@@ -77,7 +83,7 @@
sb.append(this.docID);
sb.append('-');
- sb.append(this.getPositionString());
+ sb.append(this.getPositionString());
return sb.toString();
};
@@ -91,7 +97,7 @@
sb.append('(').append(i[2]).append(')');
sb.append(i[0]).append('-').append(i[1]);
};
-
+
return sb.toString();
};
};
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 8606aa6..eaa8d9e 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
@@ -1,22 +1,28 @@
package de.ids_mannheim.korap.response.match;
+
import java.util.*;
public class PosIdentifier extends DocIdentifier {
private int pos;
+
public PosIdentifier () {};
+
public void setPos (int pos) {
if (pos >= 0)
this.pos = pos;
};
+
public int getPos () {
return this.pos;
};
+
public String toString () {
- if (this.docID == null) return null;
+ if (this.docID == null)
+ return null;
StringBuilder sb = new StringBuilder("word-");
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 1587ed3..fc34b23 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
@@ -2,10 +2,12 @@
/**
* Class for relational highlights.
- */
+ */
public class Relation {
public int ref;
public String annotation;
+
+
public Relation (String annotation, int ref) {
this.annotation = annotation;
this.ref = ref;