blob: a401916505a7e1e6d8648ad8ae6ec541fd1e5c21 [file] [log] [blame]
margaretha144983d2015-05-07 11:52:17 +02001package de.ids_mannheim.korap.query;
2
3import static de.ids_mannheim.korap.TestSimple.getJSONQuery;
4import static org.junit.Assert.assertEquals;
5
6import java.io.IOException;
7
8import org.apache.lucene.search.spans.SpanQuery;
9import org.junit.Test;
10
11import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
12import de.ids_mannheim.korap.util.QueryException;
13
14public class TestSpanReferenceQueryJSON {
15
16 @Test
Akron746b0482015-06-22 01:22:40 +020017 public void testFirstOperandRef () throws IOException, QueryException {
margaretha144983d2015-05-07 11:52:17 +020018
19 String filepath = getClass().getResource(
20 "/queries/reference/first-operand-reference.jsonld").getFile();
21 SpanQueryWrapper sqwi = getJSONQuery(filepath);
22 SpanQuery sq = sqwi.toQuery();
23
24 // 'cat="V" & cat="NP" & cat="PP" & #2 . #1 & #1 ->dep #3 &
25 // #3 . #2
26 assertEquals(
27 "spanReference(spanNext({3: tokens:p:P}, focus(2: focus(#[1,2]spanSegment(focus(#2: "
28 + "spanSegment(spanRelation(tokens:>:mate/d:HEAD), focus(1: spanNext("
29 + "{2: tokens:p:V}, {1: <tokens:c:NP />})))), {3: tokens:p:P})))), 3)",
30 sq.toString());
31 }
32
Akron746b0482015-06-22 01:22:40 +020033
margaretha144983d2015-05-07 11:52:17 +020034 @Test
Akron746b0482015-06-22 01:22:40 +020035 public void testSecondOperandRef () throws QueryException {
margaretha144983d2015-05-07 11:52:17 +020036
37 String filepath = getClass().getResource(
38 "/queries/reference/second-operand-reference.jsonld").getFile();
39 SpanQueryWrapper sqwi = getJSONQuery(filepath);
40 SpanQuery sq = sqwi.toQuery();
41
42 // 'cat="V" & cat="NP" & cat="PP" & #2 . #1 & #1 ->dep #3 &
43 // #2 . #3
44 assertEquals(
45 "spanReference(spanNext(focus(2: focus(#[1,2]spanSegment(focus(#2: "
46 + "spanSegment(spanRelation(tokens:>:mate/d:HEAD), focus(1: spanNext("
47 + "{2: tokens:p:V}, {1: <tokens:c:NP />})))), {3: tokens:p:P}))), "
48 + "{3: tokens:p:P}), 3)", sq.toString());
49 }
50
Akron746b0482015-06-22 01:22:40 +020051
margaretha144983d2015-05-07 11:52:17 +020052 @Test
Akron746b0482015-06-22 01:22:40 +020053 public void testMultipleReferences () throws QueryException {
margaretha144983d2015-05-07 11:52:17 +020054 String filepath = getClass().getResource(
55 "/queries/reference/multiple-references.jsonld").getFile();
56 SpanQueryWrapper sqwi = getJSONQuery(filepath);
57 SpanQuery sq = sqwi.toQuery();
58
59 // 'cat="VP" & cat="NP" & cat="PP" & #1 . #2 & #2 . #3 & #1 .
60 // #3 & #2 ->dep #1'
61 assertEquals(
62 "spanReference(focus(#[1,2]spanSegment(focus(#2: spanSegment(spanRelation(tokens:>:mate/d:HEAD), "
63 + "focus(2: spanReference(spanNext(focus(1: spanNext(focus(2: spanNext({1: <tokens:c:VP />}, "
64 + "{2: <tokens:c:NP />})), {3: <tokens:c:PP />})), {3: <tokens:c:PP />}), 3)))), "
Akron746b0482015-06-22 01:22:40 +020065 + "{1: <tokens:c:VP />})), 1)", sq.toString());
margaretha144983d2015-05-07 11:52:17 +020066 }
67
Akron746b0482015-06-22 01:22:40 +020068
margaretha144983d2015-05-07 11:52:17 +020069 @Test
Akron746b0482015-06-22 01:22:40 +020070 public void testDistanceReferences () throws QueryException {
margaretha144983d2015-05-07 11:52:17 +020071 String filepath = getClass().getResource(
Akron746b0482015-06-22 01:22:40 +020072 "/queries/reference/bug-multiple-distance-simple.jsonld")
73 .getFile();
margaretha144983d2015-05-07 11:52:17 +020074 SpanQueryWrapper sqwi = getJSONQuery(filepath);
75 SpanQuery sq = sqwi.toQuery();
76
Akron746b0482015-06-22 01:22:40 +020077 assertEquals(
78 "spanDistance(<tokens:c:vb />, <tokens:c:prp />, [(w[1:1], notOrdered, notExcluded)])",
79 sq.toString());
Akron784d13d2015-06-20 15:13:16 +020080
81 // "/queries/reference/distance-reference.jsonld").getFile();
82 filepath = getClass().getResource(
Akron746b0482015-06-22 01:22:40 +020083 "/queries/reference/bug-multiple-distance.jsonld").getFile();
Akron784d13d2015-06-20 15:13:16 +020084 sqwi = getJSONQuery(filepath);
85 sq = sqwi.toQuery();
86
margaretha144983d2015-05-07 11:52:17 +020087 // 'cat="VP" & cat="NP" & cat="PP" & #1 . #2 & #2 . #3 & #1 .
88 // #3 & #2 ->dep #1'
Akron746b0482015-06-22 01:22:40 +020089 assertEquals("spanReference(" + "focus(" + "#[1,2]spanSegment("
90 + "focus(" + "#2: spanSegment("
91 + "spanRelation(tokens:>:stanford/d:tag), " + "focus("
92 + "2: spanDistance(" + "focus(" + "1: spanDistance("
93 + "<tokens:c:vb />, " + "{1: <tokens:c:prp />}, "
94 + "[(w[1:1], notOrdered, notExcluded)]" + ")" + "), "
95 + "{2: <tokens:c:nn />}, " + "[(w[0:2], ordered, notExcluded)]"
96 + ")" + ")" + ")" + "), " + "{1: <tokens:c:prp />}" + ")"
97 + "), 1" + ")", sq.toString());
margaretha144983d2015-05-07 11:52:17 +020098 }
99}