Set getTermRelations() to deprecated
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index 6343456..b22f2fc 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -881,6 +881,7 @@
};
+ @Deprecated
public HashMap getTermRelation (String field) throws Exception {
return this.getTermRelation(new KorapCollection(this), field);
};
@@ -889,6 +890,7 @@
/**
* Analyze how terms relate
*/
+ @Deprecated
public HashMap getTermRelation (KorapCollection kc, String field) throws Exception {
HashMap<String,Long> map = new HashMap<>(100);
long docNumber = 0, checkNumber = 0;
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index 78267a2..d46fa0e 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -90,7 +90,7 @@
snippetBrackets,
identifier;
- private HighlightCombinator snippetStack;
+ private HighlightCombinator snippetArray;
public boolean startMore = true,
endMore = true;
@@ -924,7 +924,7 @@
int pos = 0, oldPos = 0;
- this.snippetStack = new HighlightCombinator();
+ this.snippetArray = new HighlightCombinator();
for (int[] element : stack) {
pos = element[3] != 0 ? element[0] : element[1];
@@ -935,21 +935,21 @@
pos = clean.length() - 1;
};
- snippetStack.addString(clean.substring(oldPos, pos));
+ snippetArray.addString(clean.substring(oldPos, pos));
oldPos = pos;
};
if (element[3] != 0) {
- snippetStack.addOpen(element[2]);
+ snippetArray.addOpen(element[2]);
}
else {
- snippetStack.addClose(element[2]);
+ snippetArray.addClose(element[2]);
};
};
if (clean.length() > pos) {
- snippetStack.addString(clean.substring(pos));
+ snippetArray.addString(clean.substring(pos));
};
};
@@ -974,42 +974,52 @@
// Snippet stack sizes
short start = (short) 0;
- short end = this.snippetStack.size();
+ short end = this.snippetArray.size();
+ end--;
+ // Set levels for highlights
FixedBitSet level = new FixedBitSet(16);
level.set(0, 15);
byte[] levelCache = new byte[16];
- // Get the first elem
- HighlightCombinatorElement elem = this.snippetStack.getFirst();
+ // First element of sorted array
+ HighlightCombinatorElement elem = this.snippetArray.getFirst();
// Create context
sb.append("<span class=\"context-left\">");
- if (startMore)
+ if (this.startMore)
sb.append("<span class=\"more\"></span>");
+ // First element is textual
if (elem.type == 0) {
sb.append(elem.toHTML(this, level, levelCache));
+ // Move start position
start++;
};
sb.append("</span>");
- elem = this.snippetStack.getLast();
+ // Last element of sorted array
+ elem = this.snippetArray.getLast();
StringBuilder rightContext = new StringBuilder();
- // Create context, if trhere is any
+ // Create right context, if there is any
rightContext.append("<span class=\"context-right\">");
+
+ // Last element is textual
if (elem != null && elem.type == 0) {
rightContext.append(elem.toHTML(this, level, levelCache));
+
+ // decrement end
end--;
};
- if (endMore)
+ if (this.endMore)
rightContext.append("<span class=\"more\"></span>");
rightContext.append("</span>");
- for (short i = start; i < end; i++) {
- sb.append(this.snippetStack.get(i).toHTML(this, level,levelCache));
+ // Iterate through all remaining elements
+ for (short i = start; i <= end; i++) {
+ sb.append(this.snippetArray.get(i).toHTML(this, level,levelCache));
};
sb.append(rightContext);
@@ -1033,14 +1043,14 @@
StringBuilder sb = new StringBuilder();
- if (startMore)
+ if (this.startMore)
sb.append("... ");
- for (HighlightCombinatorElement hce : this.snippetStack.stack()) {
+ for (HighlightCombinatorElement hce : this.snippetArray.list()) {
sb.append(hce.toBrackets(this));
};
- if (endMore)
+ if (this.endMore)
sb.append(" ...");
return (this.snippetBrackets = sb.toString());
diff --git a/src/main/java/de/ids_mannheim/korap/match/HighlightCombinator.java b/src/main/java/de/ids_mannheim/korap/match/HighlightCombinator.java
index 4cff483..d379d94 100644
--- a/src/main/java/de/ids_mannheim/korap/match/HighlightCombinator.java
+++ b/src/main/java/de/ids_mannheim/korap/match/HighlightCombinator.java
@@ -13,24 +13,23 @@
*/
public class HighlightCombinator {
- // Logger
+ // Logger (use the KorapMatch class)
private final static Logger log = LoggerFactory.getLogger(KorapMatch.class);
// This advices the java compiler to ignore all loggings
public static final boolean DEBUG = false;
-
private LinkedList<HighlightCombinatorElement> combine;
- private LinkedList<Integer> balanceStack = new LinkedList<>();
- private ArrayList<Integer> tempStack = new ArrayList<>(32);
+ private Stack<Integer> balanceStack = new Stack<>();
+ private Stack<Integer> tempStack = new Stack<>();
// Empty constructor
public HighlightCombinator () {
this.combine = new LinkedList<>();
};
- // Return the combination stack
- public LinkedList<HighlightCombinatorElement> stack () {
+ // Return the combination list
+ public LinkedList<HighlightCombinatorElement> list () {
return this.combine;
};
@@ -49,7 +48,7 @@
return this.combine.get(index);
};
- // Get the size of te combinator stack
+ // Get the size of the combinator stack
public short size () {
return (short) this.combine.size();
};
@@ -62,16 +61,18 @@
// Add opening highlight combinator to the stack
public void addOpen (int number) {
this.combine.add(new HighlightCombinatorElement((byte) 1, number));
- this.balanceStack.add(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();
- // Shouldn't happen
- if (this.balanceStack.size() == 0) {
+ // Check if there is an opening tag at least
+ if (this.balanceStack.empty()) {
if (DEBUG)
log.trace("The balance stack is empty");
return;
@@ -88,9 +89,10 @@
};
// class number of the last element
- int eold = this.balanceStack.removeLast();
+ // It's already ensured the stack is not empty
+ int eold = this.balanceStack.pop();
- // the closing element is not balanced
+ // the closing element is not balanced, i.e. the last element differs
while (eold != number) {
// Retrieve last combinator on stack
@@ -124,10 +126,10 @@
};
// add this element number temporarily on the stack
- tempStack.add(eold);
+ tempStack.push(eold);
// Check next element
- eold = this.balanceStack.removeLast();
+ eold = this.balanceStack.pop();
};
// Get last combinator on the stack
@@ -168,7 +170,7 @@
if (DEBUG)
log.trace("Reopen element {}", e);
combine.add(new HighlightCombinatorElement((byte) 1, e));
- balanceStack.add(e);
+ balanceStack.push(e);
};
};