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>"; |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame^] | 104 | String opin1 = |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 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(); |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame^] | 111 | assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Test |
| 115 | public void testOPNOT() { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame^] | 116 | query="Sonne nicht Mond"; |
| 117 | String opnot1 = |
| 118 | "{@type=korap:group, relation=not, operands=[" + |
| 119 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 120 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 121 | "]}"; |
| 122 | ppt = new CosmasTree(query); |
| 123 | map = ppt.getRequestMap().get("query").toString(); |
| 124 | assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 125 | } |
| 126 | |
| 127 | @Test |
| 128 | public void testBEG_END() { |
| 129 | // BEG and END operators |
| 130 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html |
| 131 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html |
| 132 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |