fixed shrink bug
diff --git a/CHANGES b/CHANGES
index 9134718..8b95c61 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,7 @@
- [bugfix] #142 Fixed class spans for skipTo() skips (margaretha)
- [feature] Added attribute support to relations (margaretha)
- [bugfix] Make classes and shrink default to 1 instead of 0 (diewald)
+ - [bugfix] shrink now removes all non-classes payloads (diewald)
0.46 2014-10-21
- [feature] Support for relation queries (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index 2f104a0..6d23202 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -1198,9 +1198,14 @@
match.internalDocID = docID;
match.populateDocument(doc, field, fieldsToLoadLocal);
- if (DEBUG)
- log.trace("I've got a match in {} of {}",
- match.getDocID(), count);
+ if (DEBUG) {
+ if (match.getDocID() != null)
+ log.trace("I've got a match in {} of {}",
+ match.getDocID(), count);
+ else
+ log.trace("I've got a match in {} of {}",
+ match.getUID(), count);
+ };
atomicMatches.add(match);
};
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/MatchModifyClassSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/MatchModifyClassSpans.java
index d6a6318..eb3ed27 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/MatchModifyClassSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/MatchModifyClassSpans.java
@@ -37,7 +37,7 @@
private final Logger log = LoggerFactory.getLogger(MatchModifyClassSpans.class);
// This advices the java compiler to ignore all loggings
- public static final boolean DEBUG = true;
+ public static final boolean DEBUG = false;
private int start = -1, end;
private int tempStart = 0, tempEnd = 0;
@@ -111,30 +111,47 @@
// Todo: Implement Divide
// Found class payload of structure <i>start<i>end<b>class
- if (payload.length == 9 && bb.get() == this.number) {
- bb.rewind();
- tempStart = bb.getInt();
- tempEnd = bb.getInt();
+ if (payload.length == 9) {
- if (DEBUG)
- log.trace("Found matching class {}-{}", tempStart, tempEnd);
+ // and classes are matches!
+ if (bb.get() == this.number) {
+ bb.rewind();
+ tempStart = bb.getInt();
+ tempEnd = bb.getInt();
- // Set start position
- if (start == -1)
- start = tempStart;
- else if (tempStart < start)
- start = tempStart;
+ if (DEBUG)
+ log.trace("Found matching class {}-{}", tempStart, tempEnd);
- // Set end position
- if (tempEnd > end)
- end = tempEnd;
+ // Set start position
+ if (start == -1)
+ start = tempStart;
+ else if (tempStart < start)
+ start = tempStart;
+
+ // Set end position
+ if (tempEnd > end)
+ end = tempEnd;
+ }
+
+ // Definately keep class information
+ else {
+ wrappedPayload.add(payload);
+ };
}
- // No class payload - but keep!
+ // No class payload
else {
- if (DEBUG)
- log.trace("Remember old payload {}", payload);
- wrappedPayload.add(payload);
+
+ // Keep as we won't shrink
+ if (start == -1) {
+ if (DEBUG)
+ log.trace("Remember old payload {}", payload);
+ wrappedPayload.add(payload);
+ }
+ else if (DEBUG) {
+ if (DEBUG)
+ log.trace("Ignore old payload {}", payload);
+ };
};
};
};
@@ -151,6 +168,16 @@
end
);
+ // Only keep class information
+ // This may change later on ...
+ for (int i = wrappedPayload.size() - 1; i >= 0; i--) {
+ if (wrappedPayload.get(i).length != 9) {
+ if (DEBUG)
+ log.trace("Forget old payload {}", wrappedPayload.get(i));
+ wrappedPayload.remove(i);
+ };
+ };
+
return true;
};
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index 2ed007e..98b2947 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -12,6 +12,7 @@
#log4j.logger.de.ids_mannheim.korap.query.spans.NextSpans = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.query.spans.SimpleSpans = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.query.spans.ClassSpans = TRACE, stdout
+#log4j.logger.de.ids_mannheim.korap.query.spans.MatchModifyClassSpans = TRACE, stdout
#log4j.logger.de.ids_mannheim.korap.query.spans.MatchSpans = TRACE, stdout
# Wrapper
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
index 8180a23..b2606bc 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKorapSearch.java
@@ -621,24 +621,53 @@
KorapQuery kq = new KorapQuery("tokens");
- // Check with 129
KorapSearch ks = new KorapSearch(
kq.shrink(1,kq.contains(kq.tag("base/s:s"), kq._(1, kq.seg("s:Leben"))))
);
KorapResult kr = ks.run(ki);
- System.err.println(kr.getMatch(0).getSnippetBrackets());
+ assertEquals(
+ kr.getQuery(),
+ "shrink(1: spanContain(<tokens:base/s:s />, {1: tokens:s:Leben}))"
+ );
+ assertEquals(
+ kr.getMatch(0).getSnippetBrackets(),
+ "... Initiative\" eine neue politische Gruppierung ins " +
+ "[Leben] gerufen hatten. Pressemeldungen zufolge haben sich ..."
+ );
- /*
-
- ks = new KorapSearch(json);
+ // Try with high class
+ ks = new KorapSearch(
+ kq.shrink(129, kq.contains(kq.tag("base/s:s"), kq._(129, kq.seg("s:Leben"))))
+ );
kr = ks.run(ki);
- System.err.println(kr.toJSON());
- assertEquals(276, kr.getTotalResults());
+ assertEquals(
+ kr.getQuery(),
+ "shrink(129: spanContain(<tokens:base/s:s />, {129: tokens:s:Leben}))"
+ );
+ assertEquals(
+ kr.getMatch(0).getSnippetBrackets(),
+ "... Initiative\" eine neue politische Gruppierung ins " +
+ "[Leben] gerufen hatten. Pressemeldungen zufolge haben sich ..."
+ );
+
+ ks = new KorapSearch(json);
+ kr = ks.run(ki);
+ assertEquals(
+ kr.getQuery(),
+ "shrink(129: spanElementDistance({129: tokens:s:Namen}, " +
+ "{129: tokens:s:Leben}, [(base/s:s[0:1], notOrdered, notExcluded)]))"
+ );
+ assertEquals(
+ kr.getMatch(0).getSnippetBrackets(),
+ "... ihren Austritt erklärt und unter dem [Namen \"Einheitsbewegung " +
+ "der sozialistischen Initiative\" eine neue politische Gruppierung " +
+ "ins Leben] gerufen hatten. Pressemeldungen zufolge haben sich ..."
+ );
+
+ assertEquals(1, kr.getTotalResults());
assertEquals(0, kr.getStartIndex());
- assertEquals(10, kr.getItemsPerPage());
- */
};
@Test