use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestBenchmarkSpans method checkBenchmarkSentences.
@Test
public void checkBenchmarkSentences() throws IOException {
Properties prop = new Properties();
InputStream fr = new FileInputStream(getClass().getResource("/krill.properties").getFile());
prop.load(fr);
// Get the real index
KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(prop.getProperty("krill.indexDir"))));
// Create a container for virtual collections:
KrillCollection kc = new KrillCollection(ki);
long t1 = 0, t2 = 0;
// / cosmas20.json!!!
String json = getString(getClass().getResource("/queries/benchmark4.jsonld").getFile());
int rounds = 10;
Result kr = new Result();
t1 = System.nanoTime();
double length = 0;
for (int i = 1; i <= rounds; i++) {
kr = new Krill(json).apply(ki);
}
;
t2 = System.nanoTime();
// System.err.println(kr.getMatch(0).toJSON());
assertEquals("TotalResults1", kr.getTotalResults(), 4116282);
assertEquals("TotalResults2", kr.getTotalResults(), ki.numberOf("sentences"));
double seconds = (double) (t2 - t1) / 1000000000.0;
// System.out.println("It took " + seconds + " seconds");
// 100 rounds
// 56.253 secs
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestBenchmarkSpans method checkBenchmark2JSON.
@Test
public void checkBenchmark2JSON() throws IOException {
Properties prop = new Properties();
InputStream fr = new FileInputStream(getClass().getResource("/krill.properties").getFile());
prop.load(fr);
// Get the real index
KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(prop.getProperty("krill.indexDir"))));
// Create a container for virtual collections:
KrillCollection kc = new KrillCollection(ki);
long t1 = 0, t2 = 0;
// / cosmas20.json!!!
String json = getString(getClass().getResource("/queries/benchmark2.jsonld").getFile());
int rounds = 10000;
Result kr = new Result();
String result = new String("");
t1 = System.nanoTime();
double length = 0;
for (int i = 1; i <= rounds; i++) {
kr = new Krill(json).apply(ki);
length += kr.toJsonString().length();
}
;
t2 = System.nanoTime();
// assertEquals("TotalResults", 30751, kr.getTotalResults());
// System.err.println(kr.toJSON());
// long seconds = (long) (t2 - t1 / 1000) % 60 ;
double seconds = (double) (t2 - t1) / 1000000000.0;
// System.out.println("It took " + seconds + " seconds");
// 10000 times:
// 77.167124985 sec
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrillCollectionJSON method noCollection.
@Test
public void noCollection() {
String metaQuery = _getJSONString("no_collection.jsonld");
KrillCollection kc = new KrillCollection(metaQuery);
assertTrue(kc.hasErrors());
assertEquals("", kc.toString());
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestKrillCollectionJSON method metaQuery3Legacy.
@Test
public void metaQuery3Legacy() {
String metaQuery = getJsonString(getClass().getResource("/queries/metaquery4.jsonld").getFile());
KrillCollection kc = new KrillCollection(metaQuery);
/*
assertEquals(1, kc.getCount());
assertEquals(
// "filter with QueryWrapperFilter(+pubDate:[20000101 TO 20131231])"
"filter with QueryWrapperFilter(+(+pubDate:[20000101 TO 99999999] +pubDate:[0 TO 20131231]))",
kc.getFilter(0).toString());
*/
assertEquals("AndGroup(pubDate:[20000101 TO 99999999] pubDate:[0 TO 20131231])", kc.toString());
}
use of de.ids_mannheim.korap.KrillCollection in project Krill by KorAP.
the class TestMatchIndex method indexExampleFocusWithSkip.
@Ignore
public void indexExampleFocusWithSkip() throws IOException {
KrillIndex ki = new KrillIndex();
// abcabcabac
FieldDocument fd = new FieldDocument();
fd.addTV("base", "abcabcabac", // The payload should be ignored
// |<>:p#0-10<i>9]" +
"[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2|<>:s$<b>64<i>1<i>5<i>5]" + "[(2-3)s:c|i:c|_2$<i>2<i>3|<>:s$<b>64<i>2<i>7<i>7]" + "[(3-4)s:a|i:a|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
ki.addDoc(fd);
fd = new FieldDocument();
fd.addTV("base", "gbcgbcgbgc", "[(0-1)s:g|i:g|_0$<i>0<i>1|-:t$<i>10|<>:p$<b>64<i>0<i>10<i>9]" + "[(1-2)s:b|i:b|_1$<i>1<i>2|<>:s$<b>64<i>1<i>5<i>5]" + "[(2-3)s:c|i:c|_2$<i>2<i>3|<>:s$<b>64<i>2<i>7<i>7]" + "[(3-4)s:g|i:g|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:g|i:g|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:g|i:g|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
ki.addDoc(fd);
fd = new FieldDocument();
fd.addTV("base", "gbcgbcgbgc", "[(0-1)s:g|i:g|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:g|i:g|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:g|i:g|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:g|i:g|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
ki.addDoc(fd);
fd = new FieldDocument();
// contains(<p>, focus(3: contains({2:<s>}, {3:a})))
fd.addTV("base", "acabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10|<>:p$<b>64<i>0<i>9<i>8]" + "[(1-2)s:b|i:b|_1$<i>1<i>2|<>:s$<b>64<i>1<i>5<i>5]" + "[(2-3)s:a|i:a|_2$<i>2<i>3|<>:s$<b>64<i>2<i>7<i>7]" + "[(3-4)s:b|i:b|_3$<i>3<i>4]" + "[(4-5)s:c|i:c|_4$<i>4<i>5]" + "[(5-6)s:a|i:a|_5$<i>5<i>6]" + "[(6-7)s:b|i:b|_6$<i>6<i>7]" + "[(7-8)s:a|i:a|_7$<i>7<i>8]" + "[(8-9)s:c|i:c|_8$<i>8<i>9]");
ki.addDoc(fd);
ki.commit();
SpanQuery sq;
Result kr;
KrillCollection kc = new KrillCollection(ki);
assertEquals("Documents", 4, kc.numberOf("documents"));
// within(<p>, focus(3:within({2:<s>}, {3:a})))
sq = new SpanWithinQuery(new SpanElementQuery("base", "p"), new SpanFocusQuery(new SpanWithinQuery(new SpanClassQuery(new SpanElementQuery("base", "s"), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 3)), (byte) 3));
// fail("Skipping may go horribly wrong! (Known issue)");
Krill ks = new Krill(sq);
ks.getMeta().setStartIndex(0).setCount((short) 20).setContext(new SearchContext(true, (short) 5, true, (short) 5));
kr = ks.apply(ki);
// kr = ki.search(kc, sq, 0, (short) 20, true, (short) 5, true, (short) 5);
assertEquals(kr.getSerialQuery(), "spanContain(<base:p />, focus(3: spanContain({2: <base:s />}, {3: base:s:a})))");
assertEquals(12, kr.getTotalResults());
assertEquals("[a{2:bc{3:a}b}cabac]", kr.getMatch(0).getSnippetBrackets());
assertEquals("[ab{2:c{3:a}bcab}ac]", kr.getMatch(1).getSnippetBrackets());
assertEquals("[ab{2:cabc{3:a}}bac]", kr.getMatch(2).getSnippetBrackets());
}
Aggregations