Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame^] | 1 | import static org.junit.Assert.*; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import de.ids_mannheim.korap.query.serialize.CosmasTree; |
| 6 | import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree; |
| 7 | import de.ids_mannheim.korap.util.QueryException; |
| 8 | |
| 9 | public class CosmasTreeTest { |
| 10 | |
| 11 | CosmasTree ppt; |
| 12 | String map; |
| 13 | String query; |
| 14 | |
| 15 | private boolean equalsContent(String str, Object map) { |
| 16 | str = str.replaceAll(" ", ""); |
| 17 | String mapStr = map.toString().replaceAll(" ", ""); |
| 18 | return str.equals(mapStr); |
| 19 | } |
| 20 | |
| 21 | private boolean equalsQueryContent(String res, String query) throws QueryException { |
| 22 | res = res.replaceAll(" ", ""); |
| 23 | ppt = new CosmasTree(query); |
| 24 | String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", ""); |
| 25 | return res.equals(queryMap); |
| 26 | } |
| 27 | |
| 28 | @Test |
| 29 | public void testContext() throws QueryException { |
| 30 | String contextString = "{korap=http://korap.ids-mannheim.de/ns/query, @language=de, operands={@id=korap:operands, @container=@list}, relation={@id=korap:relation, @type=korap:relation#types}, class={@id=korap:class, @type=xsd:integer}, query=korap:query, filter=korap:filter, meta=korap:meta}"; |
| 31 | ppt = new CosmasTree("Test"); |
| 32 | assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context"))); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | @Test |
| 37 | public void testSingleToken() { |
| 38 | query="der"; |
| 39 | String single1 = |
| 40 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}"; |
| 41 | ppt = new CosmasTree(query); |
| 42 | map = ppt.getRequestMap().get("query").toString(); |
| 43 | assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 44 | |
| 45 | query="Mann"; |
| 46 | String single2 = |
| 47 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}"; |
| 48 | ppt = new CosmasTree(query); |
| 49 | map = ppt.getRequestMap().get("query").toString(); |
| 50 | assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 51 | |
| 52 | query="&Mann"; |
| 53 | String single3 = |
| 54 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}"; |
| 55 | ppt = new CosmasTree(query); |
| 56 | map = ppt.getRequestMap().get("query").toString(); |
| 57 | assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testSequence() { |
| 62 | query="der Mann"; |
| 63 | String seq1 = |
| 64 | "{@type=korap:sequence, operands=[" + |
| 65 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 66 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 67 | "]}"; |
| 68 | ppt = new CosmasTree(query); |
| 69 | map = ppt.getRequestMap().get("query").toString(); |
| 70 | assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 71 | |
| 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testOPOR() throws QueryException { |
| 76 | query="Sonne oder Mond"; |
| 77 | String disj1 = |
| 78 | "{@type=korap:group, relation=or, operands=[" + |
| 79 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 80 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 81 | "]}"; |
| 82 | ppt = new CosmasTree(query); |
| 83 | map = ppt.getRequestMap().get("query").toString(); |
| 84 | assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | @Test |
| 89 | public void testOPPROX() { |
| 90 | query="Sonne /+w1:4 Mond"; |
| 91 | String prox1 = |
| 92 | "{@type=korap:group, relation=distance, @subtype=w, min=1, max=4, operands=[" + |
| 93 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 94 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 95 | "]}"; |
| 96 | ppt = new CosmasTree(query); |
| 97 | map = ppt.getRequestMap().get("query").toString(); |
| 98 | assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 99 | } |
| 100 | |
| 101 | @Test |
| 102 | public void testOPIN() { |
| 103 | query="wegen #IN(L) <s>"; |
| 104 | String disj1 = |
| 105 | "{@type=korap:group, relation=in, position=L, operands=[" + |
| 106 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}," + |
| 107 | "{@type=korap:element, @value=s}" + |
| 108 | "]}"; |
| 109 | ppt = new CosmasTree(query); |
| 110 | map = ppt.getRequestMap().get("query").toString(); |
| 111 | assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 112 | } |
| 113 | |
| 114 | @Test |
| 115 | public void testOPNOT() { |
| 116 | |
| 117 | } |
| 118 | } |
| 119 | |