| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.query; |
| 2 | |
| 3 | import static de.ids_mannheim.korap.TestSimple.getJSONQuery; |
| 4 | import static org.junit.Assert.assertEquals; |
| 5 | |
| 6 | import java.io.IOException; |
| 7 | |
| 8 | import org.apache.lucene.search.spans.SpanQuery; |
| 9 | import org.junit.Test; |
| 10 | |
| 11 | import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper; |
| 12 | import de.ids_mannheim.korap.util.QueryException; |
| 13 | |
| 14 | public class TestSpanReferenceQueryJSON { |
| 15 | |
| 16 | @Test |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 17 | public void testFirstOperandRef () throws IOException, QueryException { |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 18 | |
| 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 | |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 33 | |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 34 | @Test |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 35 | public void testSecondOperandRef () throws QueryException { |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 36 | |
| 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 | |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 51 | |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 52 | @Test |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 53 | public void testMultipleReferences () throws QueryException { |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 54 | 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)))), " |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 65 | + "{1: <tokens:c:VP />})), 1)", sq.toString()); |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 68 | |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 69 | @Test |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 70 | public void testDistanceReferences () throws QueryException { |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 71 | String filepath = getClass().getResource( |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 72 | "/queries/reference/bug-multiple-distance-simple.jsonld") |
| 73 | .getFile(); |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 74 | SpanQueryWrapper sqwi = getJSONQuery(filepath); |
| 75 | SpanQuery sq = sqwi.toQuery(); |
| 76 | |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 77 | assertEquals( |
| 78 | "spanDistance(<tokens:c:vb />, <tokens:c:prp />, [(w[1:1], notOrdered, notExcluded)])", |
| 79 | sq.toString()); |
| Akron | 784d13d | 2015-06-20 15:13:16 +0200 | [diff] [blame] | 80 | |
| 81 | // "/queries/reference/distance-reference.jsonld").getFile(); |
| 82 | filepath = getClass().getResource( |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 83 | "/queries/reference/bug-multiple-distance.jsonld").getFile(); |
| Akron | 784d13d | 2015-06-20 15:13:16 +0200 | [diff] [blame] | 84 | sqwi = getJSONQuery(filepath); |
| 85 | sq = sqwi.toQuery(); |
| 86 | |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 87 | // 'cat="VP" & cat="NP" & cat="PP" & #1 . #2 & #2 . #3 & #1 . |
| 88 | // #3 & #2 ->dep #1' |
| Akron | 746b048 | 2015-06-22 01:22:40 +0200 | [diff] [blame^] | 89 | 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()); |
| margaretha | 144983d | 2015-05-07 11:52:17 +0200 | [diff] [blame] | 98 | } |
| 99 | } |