Commit 0bee8c90ab65a7ba4cbf71334b8a78140de782d4
1 parent
9bc9e3a1
fix ignoreItem
Showing
11 changed files
with
514 additions
and
466 deletions
docker/Dockerfile
| 1 | 1 | # Automatically generated Dockerfile |
| 2 | -# - Build 2016-12-16 12:13 | |
| 2 | +# - Build 2016-12-30 07:00 | |
| 3 | 3 | # - Lucene/Solr version 6.3.0 |
| 4 | 4 | # - Mtas release 20161216 |
| 5 | 5 | # |
| ... | ... | @@ -49,13 +49,12 @@ RUN apt-get update && apt-get install -y lsof software-properties-common python- |
| 49 | 49 | && rm -rf /var/www/html/* \ |
| 50 | 50 | && mkdir /var/www/html/demo \ |
| 51 | 51 | && cp -rp data/folia-samples /var/www/html/demo/ \ |
| 52 | -&& cp -rp data/isotei-samples /var/www/html/demo/ \ | |
| 53 | 52 | && gunzip -r /var/www/html/demo \ |
| 54 | 53 | && cp -rp data/site/* /var/www/html/ \ |
| 55 | 54 | && chmod -R 755 /var/www/html \ |
| 56 | 55 | && printf "echo\n" >> /start.sh \ |
| 57 | 56 | && printf "echo \"================ Mtas -- Multi Tier Annotation Search =================\"\n" >> /start.sh \ |
| 58 | -&& printf "echo \" Timestamp 2016-12-16 12:13\"\n" >> /start.sh \ | |
| 57 | +&& printf "echo \" Timestamp 2016-12-30 07:00\"\n" >> /start.sh \ | |
| 59 | 58 | && printf "echo \" Lucene/Solr version 6.3.0\"\n" >> /start.sh \ |
| 60 | 59 | && printf "echo \" Mtas release 20161216\"\n" >> /start.sh \ |
| 61 | 60 | && printf "echo \" See https://meertensinstituut.github.io/mtas/ for more information\"\n" >> /start.sh \ |
| ... | ... |
junit/mtas/parser/MtasCQLParserTestSentence.java
| ... | ... | @@ -49,9 +49,8 @@ public class MtasCQLParserTestSentence { |
| 49 | 49 | MtasCQLParser p1 = new MtasCQLParser(new BufferedReader(new StringReader(cql1))); |
| 50 | 50 | MtasCQLParser p2 = new MtasCQLParser(new BufferedReader(new StringReader(cql2))); |
| 51 | 51 | try { |
| 52 | - //System.out.print("CQL equivalent:\t"+cql1+" and "+cql2); | |
| 53 | - assertEquals(p1.parse(field, defaultPrefix, null, null, null) ,p2.parse(field, defaultPrefix, null, null, null)); | |
| 54 | - //System.out.print("\n"); | |
| 52 | + //System.out.println("CQL equivalent:\t"+cql1+" and "+cql2); | |
| 53 | + assertEquals(p1.parse(field, defaultPrefix, null, null, null) ,p2.parse(field, defaultPrefix, null, null, null)); | |
| 55 | 54 | } catch (ParseException e) { |
| 56 | 55 | //System.out.println("Error CQL equivalent:\t"+cql1+" and "+cql2); |
| 57 | 56 | e.printStackTrace(); |
| ... | ... | @@ -78,6 +77,7 @@ public class MtasCQLParserTestSentence { |
| 78 | 77 | basicTest17(); |
| 79 | 78 | basicTest18(); |
| 80 | 79 | basicTest19(); |
| 80 | + basicTest20(); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | private void basicTest1() throws ParseException { |
| ... | ... | @@ -305,4 +305,23 @@ public class MtasCQLParserTestSentence { |
| 305 | 305 | testCQLParse(field, null, cql, q); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | + private void basicTest20() { | |
| 309 | + String field = "testveld"; | |
| 310 | + String cql1 = "[pos=\"N\"]?[pos=\"ADJ\"]"; | |
| 311 | + String cql2 = "([pos=\"N\"])?[pos=\"ADJ\"]"; | |
| 312 | + testCQLEquivalent(field, null, cql1, cql2); | |
| 313 | + String cql3 = "[pos=\"N\"][pos=\"ADJ\"]?"; | |
| 314 | + String cql4 = "[pos=\"N\"]([pos=\"ADJ\"])?"; | |
| 315 | + testCQLEquivalent(field, null, cql3, cql4); | |
| 316 | + String cql5 = "[pos=\"N\"][pos=\"ADJ\"]?[pos=\"N\"]"; | |
| 317 | + String cql6 = "[pos=\"N\"]([pos=\"ADJ\"])?[pos=\"N\"]"; | |
| 318 | + testCQLEquivalent(field, null, cql5, cql6); | |
| 319 | + String cql7 = "[pos=\"N\"]?[pos=\"ADJ\"]?[pos=\"N\"]"; | |
| 320 | + String cql8 = "([pos=\"N\"])?([pos=\"ADJ\"])?[pos=\"N\"]"; | |
| 321 | + testCQLEquivalent(field, null, cql7, cql8); | |
| 322 | + String cql9 = "[pos=\"N\"][pos=\"ADJ\"]?[pos=\"N\"]?"; | |
| 323 | + String cql10 = "[pos=\"N\"]([pos=\"ADJ\"])?([pos=\"N\"])?"; | |
| 324 | + testCQLEquivalent(field, null, cql9, cql10); | |
| 325 | + } | |
| 326 | + | |
| 308 | 327 | } |
| ... | ... |
src/mtas/parser/cql/MtasCQLParser.java
| ... | ... | @@ -62,10 +62,10 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | final private MtasSpanQuery cql(String field, String defaultPrefix, HashMap<String, String[] > variables, HashSet<String > usedVariables, MtasSpanQuery ignore, Integer maximumIgnoreLength) throws ParseException, ParseException { |
| 65 | - MtasSpanQuery q; | |
| 65 | + MtasSpanSequenceItem si; | |
| 66 | 66 | ArrayList < MtasSpanSequenceItem > itemList = new ArrayList < MtasSpanSequenceItem > (); |
| 67 | - q = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 68 | - itemList.add(new MtasSpanSequenceItem(q, false)); | |
| 67 | + si = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 68 | + itemList.add(si); | |
| 69 | 69 | label_1: |
| 70 | 70 | while (true) { |
| 71 | 71 | if (jj_2_1(1000)) { |
| ... | ... | @@ -73,8 +73,8 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 73 | 73 | } else { |
| 74 | 74 | break label_1; |
| 75 | 75 | } |
| 76 | - q = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 77 | - itemList.add(new MtasSpanSequenceItem(q, false)); | |
| 76 | + si = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 77 | + itemList.add(si); | |
| 78 | 78 | } |
| 79 | 79 | jj_consume_token(0); |
| 80 | 80 | if (itemList.size() > 1) |
| ... | ... | @@ -88,8 +88,9 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 88 | 88 | throw new Error("Missing return statement in function"); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - final private MtasSpanQuery cqlBlock(String field, String defaultPrefix, HashMap<String, String[] > variables, HashSet<String > usedVariables, MtasSpanQuery ignore,Integer maximumIgnoreLength) throws ParseException, ParseException { | |
| 92 | - MtasCQLParserSentenceCondition s1 = null, s2 = null; | |
| 91 | + final private MtasSpanSequenceItem cqlBlock(String field, String defaultPrefix, HashMap<String, String[] > variables, HashSet<String > usedVariables, MtasSpanQuery ignore,Integer maximumIgnoreLength) throws ParseException, ParseException { | |
| 92 | + MtasCQLParserSentenceCondition sc1 = null, sc2 = null; | |
| 93 | + MtasSpanSequenceItem si1 = null, si2=null; | |
| 93 | 94 | MtasSpanQuery q1 = null, q2 = null; |
| 94 | 95 | Token end = null; |
| 95 | 96 | String operator = null; |
| ... | ... | @@ -100,10 +101,10 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 100 | 101 | String OPERATOR_INTERSECTING = "intersecting"; |
| 101 | 102 | String OPERATOR_NOT_INTERSECTING = "not_intersecting"; |
| 102 | 103 | if (jj_2_2(1000)) { |
| 103 | - s1 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 104 | + sc1 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 104 | 105 | } else if (jj_2_3(1000)) { |
| 105 | 106 | jj_consume_token(BRACKET_START); |
| 106 | - q1 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 107 | + si1 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 107 | 108 | jj_consume_token(BRACKET_END); |
| 108 | 109 | } else { |
| 109 | 110 | jj_consume_token(-1); |
| ... | ... | @@ -133,10 +134,10 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 133 | 134 | throw new ParseException(); |
| 134 | 135 | } |
| 135 | 136 | if (jj_2_10(1000)) { |
| 136 | - s2 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 137 | + sc2 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 137 | 138 | } else if (jj_2_11(1000)) { |
| 138 | 139 | jj_consume_token(BRACKET_START); |
| 139 | - q2 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 140 | + si2 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength); | |
| 140 | 141 | jj_consume_token(BRACKET_END); |
| 141 | 142 | } else { |
| 142 | 143 | jj_consume_token(-1); |
| ... | ... | @@ -145,39 +146,45 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 145 | 146 | } else { |
| 146 | 147 | ; |
| 147 | 148 | } |
| 148 | - if (s1 != null) | |
| 149 | + if (sc1 != null) | |
| 149 | 150 | { |
| 150 | - q1 = s1.getQuery(); | |
| 151 | + si1 = new MtasSpanSequenceItem(sc1.getQuery(),sc1.isOptional()); | |
| 151 | 152 | } |
| 152 | 153 | if (operator != null) |
| 153 | 154 | { |
| 154 | - if (s2 != null) | |
| 155 | + if (sc2 != null) | |
| 155 | 156 | { |
| 156 | - q2 = s2.getQuery(); | |
| 157 | + si2 = new MtasSpanSequenceItem(sc2.getQuery(),sc2.isOptional()); | |
| 157 | 158 | } |
| 158 | 159 | if (operator.equals(OPERATOR_CONTAINING)) |
| 159 | 160 | { |
| 160 | - {if (true) return new MtasSpanContainingQuery(q1, q2);} | |
| 161 | + MtasSpanQuery q = new MtasSpanContainingQuery(si1.getQuery(), si2.getQuery()); | |
| 162 | + {if (true) return new MtasSpanSequenceItem(q, si1.isOptional());} | |
| 161 | 163 | } |
| 162 | 164 | else if (operator.equals(OPERATOR_NOT_CONTAINING)) |
| 163 | 165 | { |
| 164 | - {if (true) return new MtasSpanNotQuery(q1, new MtasSpanContainingQuery(q1, q2));} | |
| 166 | + MtasSpanQuery q = new MtasSpanNotQuery(si1.getQuery(), new MtasSpanContainingQuery(si1.getQuery(), si2.getQuery())); | |
| 167 | + {if (true) return new MtasSpanSequenceItem(q, si1.isOptional());} | |
| 165 | 168 | } |
| 166 | 169 | else if (operator.equals(OPERATOR_WITHIN)) |
| 167 | 170 | { |
| 168 | - {if (true) return new MtasSpanWithinQuery(q2, q1);} | |
| 171 | + MtasSpanQuery q = new MtasSpanWithinQuery(si2.getQuery(), si1.getQuery()); | |
| 172 | + {if (true) return new MtasSpanSequenceItem(q, si1.isOptional());} | |
| 169 | 173 | } |
| 170 | 174 | else if (operator.equals(OPERATOR_NOT_WITHIN)) |
| 171 | 175 | { |
| 172 | - {if (true) return new MtasSpanNotQuery(q1, new MtasSpanWithinQuery(q2, q1));} | |
| 176 | + MtasSpanQuery q = new MtasSpanNotQuery(si1.getQuery(), new MtasSpanWithinQuery(si2.getQuery(), si1.getQuery())); | |
| 177 | + {if (true) return new MtasSpanSequenceItem(q, si1.isOptional());} | |
| 173 | 178 | } |
| 174 | 179 | else if (operator.equals(OPERATOR_INTERSECTING)) |
| 175 | 180 | { |
| 176 | - {if (true) return new MtasSpanIntersectingQuery(q2, q1);} | |
| 181 | + MtasSpanQuery q = new MtasSpanIntersectingQuery(si1.getQuery(), si2.getQuery()); | |
| 182 | + {if (true) return new MtasSpanSequenceItem(q, si1.isOptional());} | |
| 177 | 183 | } |
| 178 | 184 | else if (operator.equals(OPERATOR_NOT_INTERSECTING)) |
| 179 | 185 | { |
| 180 | - {if (true) return new MtasSpanNotQuery(q1, new MtasSpanIntersectingQuery(q2, q1));} | |
| 186 | + MtasSpanQuery q = new MtasSpanNotQuery(si1.getQuery(), new MtasSpanIntersectingQuery(si1.getQuery(), si2.getQuery())); | |
| 187 | + {if (true) return new MtasSpanSequenceItem(q, si1.isOptional());} | |
| 181 | 188 | } |
| 182 | 189 | else |
| 183 | 190 | { |
| ... | ... | @@ -186,7 +193,7 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 186 | 193 | } |
| 187 | 194 | else |
| 188 | 195 | { |
| 189 | - {if (true) return q1;} | |
| 196 | + {if (true) return si1;} | |
| 190 | 197 | } |
| 191 | 198 | throw new Error("Missing return statement in function"); |
| 192 | 199 | } |
| ... | ... | @@ -1351,31 +1358,6 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1351 | 1358 | finally { jj_save(78, xla); } |
| 1352 | 1359 | } |
| 1353 | 1360 | |
| 1354 | - private boolean jj_3_66() { | |
| 1355 | - Token xsp; | |
| 1356 | - xsp = jj_scanpos; | |
| 1357 | - if (jj_3_56()) { | |
| 1358 | - jj_scanpos = xsp; | |
| 1359 | - if (jj_3_57()) return true; | |
| 1360 | - } | |
| 1361 | - if (jj_scan_token(OR)) return true; | |
| 1362 | - xsp = jj_scanpos; | |
| 1363 | - if (jj_3_58()) { | |
| 1364 | - jj_scanpos = xsp; | |
| 1365 | - if (jj_3_59()) return true; | |
| 1366 | - } | |
| 1367 | - while (true) { | |
| 1368 | - xsp = jj_scanpos; | |
| 1369 | - if (jj_3_60()) { jj_scanpos = xsp; break; } | |
| 1370 | - } | |
| 1371 | - return false; | |
| 1372 | - } | |
| 1373 | - | |
| 1374 | - private boolean jj_3_55() { | |
| 1375 | - if (jj_3R_14()) return true; | |
| 1376 | - return false; | |
| 1377 | - } | |
| 1378 | - | |
| 1379 | 1361 | private boolean jj_3_54() { |
| 1380 | 1362 | if (jj_3R_15()) return true; |
| 1381 | 1363 | return false; |
| ... | ... | @@ -1517,18 +1499,6 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1517 | 1499 | return false; |
| 1518 | 1500 | } |
| 1519 | 1501 | |
| 1520 | - private boolean jj_3_11() { | |
| 1521 | - if (jj_scan_token(BRACKET_START)) return true; | |
| 1522 | - if (jj_3R_7()) return true; | |
| 1523 | - if (jj_scan_token(BRACKET_END)) return true; | |
| 1524 | - return false; | |
| 1525 | - } | |
| 1526 | - | |
| 1527 | - private boolean jj_3_10() { | |
| 1528 | - if (jj_3R_8()) return true; | |
| 1529 | - return false; | |
| 1530 | - } | |
| 1531 | - | |
| 1532 | 1502 | private boolean jj_3R_12() { |
| 1533 | 1503 | if (jj_scan_token(GROUP_START)) return true; |
| 1534 | 1504 | Token xsp; |
| ... | ... | @@ -1548,18 +1518,25 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1548 | 1518 | return false; |
| 1549 | 1519 | } |
| 1550 | 1520 | |
| 1521 | + private boolean jj_3_11() { | |
| 1522 | + if (jj_scan_token(BRACKET_START)) return true; | |
| 1523 | + if (jj_3R_7()) return true; | |
| 1524 | + if (jj_scan_token(BRACKET_END)) return true; | |
| 1525 | + return false; | |
| 1526 | + } | |
| 1527 | + | |
| 1551 | 1528 | private boolean jj_3_75() { |
| 1552 | 1529 | if (jj_scan_token(TOKEN_NOTEQUALS)) return true; |
| 1553 | 1530 | return false; |
| 1554 | 1531 | } |
| 1555 | 1532 | |
| 1556 | - private boolean jj_3_9() { | |
| 1557 | - if (jj_scan_token(NOT_INTERSECTING)) return true; | |
| 1533 | + private boolean jj_3_10() { | |
| 1534 | + if (jj_3R_8()) return true; | |
| 1558 | 1535 | return false; |
| 1559 | 1536 | } |
| 1560 | 1537 | |
| 1561 | - private boolean jj_3_8() { | |
| 1562 | - if (jj_scan_token(INTERSECTING)) return true; | |
| 1538 | + private boolean jj_3_9() { | |
| 1539 | + if (jj_scan_token(NOT_INTERSECTING)) return true; | |
| 1563 | 1540 | return false; |
| 1564 | 1541 | } |
| 1565 | 1542 | |
| ... | ... | @@ -1575,13 +1552,13 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1575 | 1552 | return false; |
| 1576 | 1553 | } |
| 1577 | 1554 | |
| 1578 | - private boolean jj_3_7() { | |
| 1579 | - if (jj_scan_token(NOT_WITHIN)) return true; | |
| 1555 | + private boolean jj_3_8() { | |
| 1556 | + if (jj_scan_token(INTERSECTING)) return true; | |
| 1580 | 1557 | return false; |
| 1581 | 1558 | } |
| 1582 | 1559 | |
| 1583 | - private boolean jj_3_6() { | |
| 1584 | - if (jj_scan_token(WITHIN)) return true; | |
| 1560 | + private boolean jj_3_7() { | |
| 1561 | + if (jj_scan_token(NOT_WITHIN)) return true; | |
| 1585 | 1562 | return false; |
| 1586 | 1563 | } |
| 1587 | 1564 | |
| ... | ... | @@ -1590,8 +1567,8 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1590 | 1567 | return false; |
| 1591 | 1568 | } |
| 1592 | 1569 | |
| 1593 | - private boolean jj_3_5() { | |
| 1594 | - if (jj_scan_token(NOT_CONTAINING)) return true; | |
| 1570 | + private boolean jj_3_6() { | |
| 1571 | + if (jj_scan_token(WITHIN)) return true; | |
| 1595 | 1572 | return false; |
| 1596 | 1573 | } |
| 1597 | 1574 | |
| ... | ... | @@ -1612,11 +1589,6 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1612 | 1589 | return false; |
| 1613 | 1590 | } |
| 1614 | 1591 | |
| 1615 | - private boolean jj_3_4() { | |
| 1616 | - if (jj_scan_token(CONTAINING)) return true; | |
| 1617 | - return false; | |
| 1618 | - } | |
| 1619 | - | |
| 1620 | 1592 | private boolean jj_3_44() { |
| 1621 | 1593 | if (jj_scan_token(CURLY_BRACKET_START)) return true; |
| 1622 | 1594 | if (jj_scan_token(NUMBER)) return true; |
| ... | ... | @@ -1626,47 +1598,23 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1626 | 1598 | return false; |
| 1627 | 1599 | } |
| 1628 | 1600 | |
| 1629 | - private boolean jj_3_23() { | |
| 1630 | - Token xsp; | |
| 1631 | - xsp = jj_scanpos; | |
| 1632 | - if (jj_3_24()) { | |
| 1633 | - jj_scanpos = xsp; | |
| 1634 | - if (jj_3_25()) return true; | |
| 1635 | - } | |
| 1601 | + private boolean jj_3_5() { | |
| 1602 | + if (jj_scan_token(NOT_CONTAINING)) return true; | |
| 1636 | 1603 | return false; |
| 1637 | 1604 | } |
| 1638 | 1605 | |
| 1639 | - private boolean jj_3_12() { | |
| 1606 | + private boolean jj_3_23() { | |
| 1640 | 1607 | Token xsp; |
| 1641 | 1608 | xsp = jj_scanpos; |
| 1642 | - if (jj_3_4()) { | |
| 1643 | - jj_scanpos = xsp; | |
| 1644 | - if (jj_3_5()) { | |
| 1645 | - jj_scanpos = xsp; | |
| 1646 | - if (jj_3_6()) { | |
| 1647 | - jj_scanpos = xsp; | |
| 1648 | - if (jj_3_7()) { | |
| 1649 | - jj_scanpos = xsp; | |
| 1650 | - if (jj_3_8()) { | |
| 1651 | - jj_scanpos = xsp; | |
| 1652 | - if (jj_3_9()) return true; | |
| 1653 | - } | |
| 1654 | - } | |
| 1655 | - } | |
| 1656 | - } | |
| 1657 | - } | |
| 1658 | - xsp = jj_scanpos; | |
| 1659 | - if (jj_3_10()) { | |
| 1609 | + if (jj_3_24()) { | |
| 1660 | 1610 | jj_scanpos = xsp; |
| 1661 | - if (jj_3_11()) return true; | |
| 1611 | + if (jj_3_25()) return true; | |
| 1662 | 1612 | } |
| 1663 | 1613 | return false; |
| 1664 | 1614 | } |
| 1665 | 1615 | |
| 1666 | - private boolean jj_3_3() { | |
| 1667 | - if (jj_scan_token(BRACKET_START)) return true; | |
| 1668 | - if (jj_3R_7()) return true; | |
| 1669 | - if (jj_scan_token(BRACKET_END)) return true; | |
| 1616 | + private boolean jj_3_4() { | |
| 1617 | + if (jj_scan_token(CONTAINING)) return true; | |
| 1670 | 1618 | return false; |
| 1671 | 1619 | } |
| 1672 | 1620 | |
| ... | ... | @@ -1688,11 +1636,6 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1688 | 1636 | return false; |
| 1689 | 1637 | } |
| 1690 | 1638 | |
| 1691 | - private boolean jj_3_2() { | |
| 1692 | - if (jj_3R_8()) return true; | |
| 1693 | - return false; | |
| 1694 | - } | |
| 1695 | - | |
| 1696 | 1639 | private boolean jj_3_22() { |
| 1697 | 1640 | if (jj_3R_12()) return true; |
| 1698 | 1641 | return false; |
| ... | ... | @@ -1703,15 +1646,37 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1703 | 1646 | return false; |
| 1704 | 1647 | } |
| 1705 | 1648 | |
| 1706 | - private boolean jj_3R_7() { | |
| 1649 | + private boolean jj_3_12() { | |
| 1707 | 1650 | Token xsp; |
| 1708 | 1651 | xsp = jj_scanpos; |
| 1709 | - if (jj_3_2()) { | |
| 1652 | + if (jj_3_4()) { | |
| 1710 | 1653 | jj_scanpos = xsp; |
| 1711 | - if (jj_3_3()) return true; | |
| 1654 | + if (jj_3_5()) { | |
| 1655 | + jj_scanpos = xsp; | |
| 1656 | + if (jj_3_6()) { | |
| 1657 | + jj_scanpos = xsp; | |
| 1658 | + if (jj_3_7()) { | |
| 1659 | + jj_scanpos = xsp; | |
| 1660 | + if (jj_3_8()) { | |
| 1661 | + jj_scanpos = xsp; | |
| 1662 | + if (jj_3_9()) return true; | |
| 1663 | + } | |
| 1664 | + } | |
| 1665 | + } | |
| 1666 | + } | |
| 1712 | 1667 | } |
| 1713 | 1668 | xsp = jj_scanpos; |
| 1714 | - if (jj_3_12()) jj_scanpos = xsp; | |
| 1669 | + if (jj_3_10()) { | |
| 1670 | + jj_scanpos = xsp; | |
| 1671 | + if (jj_3_11()) return true; | |
| 1672 | + } | |
| 1673 | + return false; | |
| 1674 | + } | |
| 1675 | + | |
| 1676 | + private boolean jj_3_3() { | |
| 1677 | + if (jj_scan_token(BRACKET_START)) return true; | |
| 1678 | + if (jj_3R_7()) return true; | |
| 1679 | + if (jj_scan_token(BRACKET_END)) return true; | |
| 1715 | 1680 | return false; |
| 1716 | 1681 | } |
| 1717 | 1682 | |
| ... | ... | @@ -1726,6 +1691,11 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1726 | 1691 | return false; |
| 1727 | 1692 | } |
| 1728 | 1693 | |
| 1694 | + private boolean jj_3_2() { | |
| 1695 | + if (jj_3R_8()) return true; | |
| 1696 | + return false; | |
| 1697 | + } | |
| 1698 | + | |
| 1729 | 1699 | private boolean jj_3_40() { |
| 1730 | 1700 | if (jj_3R_14()) return true; |
| 1731 | 1701 | return false; |
| ... | ... | @@ -1763,6 +1733,18 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1763 | 1733 | return false; |
| 1764 | 1734 | } |
| 1765 | 1735 | |
| 1736 | + private boolean jj_3R_7() { | |
| 1737 | + Token xsp; | |
| 1738 | + xsp = jj_scanpos; | |
| 1739 | + if (jj_3_2()) { | |
| 1740 | + jj_scanpos = xsp; | |
| 1741 | + if (jj_3_3()) return true; | |
| 1742 | + } | |
| 1743 | + xsp = jj_scanpos; | |
| 1744 | + if (jj_3_12()) jj_scanpos = xsp; | |
| 1745 | + return false; | |
| 1746 | + } | |
| 1747 | + | |
| 1766 | 1748 | private boolean jj_3_38() { |
| 1767 | 1749 | if (jj_scan_token(OR)) return true; |
| 1768 | 1750 | if (jj_3R_14()) return true; |
| ... | ... | @@ -1785,11 +1767,6 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1785 | 1767 | return false; |
| 1786 | 1768 | } |
| 1787 | 1769 | |
| 1788 | - private boolean jj_3_1() { | |
| 1789 | - if (jj_3R_7()) return true; | |
| 1790 | - return false; | |
| 1791 | - } | |
| 1792 | - | |
| 1793 | 1770 | private boolean jj_3_37() { |
| 1794 | 1771 | if (jj_scan_token(AND)) return true; |
| 1795 | 1772 | if (jj_3R_14()) return true; |
| ... | ... | @@ -1825,6 +1802,11 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 1825 | 1802 | return false; |
| 1826 | 1803 | } |
| 1827 | 1804 | |
| 1805 | + private boolean jj_3_1() { | |
| 1806 | + if (jj_3R_7()) return true; | |
| 1807 | + return false; | |
| 1808 | + } | |
| 1809 | + | |
| 1828 | 1810 | private boolean jj_3_71() { |
| 1829 | 1811 | if (jj_scan_token(NUMBER)) return true; |
| 1830 | 1812 | return false; |
| ... | ... | @@ -2047,6 +2029,31 @@ public class MtasCQLParser implements MtasCQLParserConstants { |
| 2047 | 2029 | return false; |
| 2048 | 2030 | } |
| 2049 | 2031 | |
| 2032 | + private boolean jj_3_66() { | |
| 2033 | + Token xsp; | |
| 2034 | + xsp = jj_scanpos; | |
| 2035 | + if (jj_3_56()) { | |
| 2036 | + jj_scanpos = xsp; | |
| 2037 | + if (jj_3_57()) return true; | |
| 2038 | + } | |
| 2039 | + if (jj_scan_token(OR)) return true; | |
| 2040 | + xsp = jj_scanpos; | |
| 2041 | + if (jj_3_58()) { | |
| 2042 | + jj_scanpos = xsp; | |
| 2043 | + if (jj_3_59()) return true; | |
| 2044 | + } | |
| 2045 | + while (true) { | |
| 2046 | + xsp = jj_scanpos; | |
| 2047 | + if (jj_3_60()) { jj_scanpos = xsp; break; } | |
| 2048 | + } | |
| 2049 | + return false; | |
| 2050 | + } | |
| 2051 | + | |
| 2052 | + private boolean jj_3_55() { | |
| 2053 | + if (jj_3R_14()) return true; | |
| 2054 | + return false; | |
| 2055 | + } | |
| 2056 | + | |
| 2050 | 2057 | /** Generated Token Manager. */ |
| 2051 | 2058 | public MtasCQLParserTokenManager token_source; |
| 2052 | 2059 | SimpleCharStream jj_input_stream; |
| ... | ... |
src/mtas/parser/cql/MtasCQLParser.jj
| ... | ... | @@ -247,18 +247,18 @@ TOKEN : |
| 247 | 247 | |
| 248 | 248 | private MtasSpanQuery cql(String field, String defaultPrefix, HashMap<String, String[] > variables, HashSet<String > usedVariables, MtasSpanQuery ignore, Integer maximumIgnoreLength) throws ParseException : |
| 249 | 249 | { |
| 250 | - MtasSpanQuery q; | |
| 250 | + MtasSpanSequenceItem si; | |
| 251 | 251 | ArrayList < MtasSpanSequenceItem > itemList = new ArrayList < MtasSpanSequenceItem > (); |
| 252 | 252 | } |
| 253 | 253 | { |
| 254 | - q = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 254 | + si = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 255 | 255 | { |
| 256 | - itemList.add(new MtasSpanSequenceItem(q, false)); | |
| 256 | + itemList.add(si); | |
| 257 | 257 | } |
| 258 | 258 | ( |
| 259 | - q = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 259 | + si = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 260 | 260 | { |
| 261 | - itemList.add(new MtasSpanSequenceItem(q, false)); | |
| 261 | + itemList.add(si); | |
| 262 | 262 | } |
| 263 | 263 | )* |
| 264 | 264 | < EOF > |
| ... | ... | @@ -274,9 +274,10 @@ private MtasSpanQuery cql(String field, String defaultPrefix, HashMap<String, St |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | -private MtasSpanQuery cqlBlock(String field, String defaultPrefix, HashMap<String, String[] > variables, HashSet<String > usedVariables, MtasSpanQuery ignore,Integer maximumIgnoreLength) throws ParseException : | |
| 277 | +private MtasSpanSequenceItem cqlBlock(String field, String defaultPrefix, HashMap<String, String[] > variables, HashSet<String > usedVariables, MtasSpanQuery ignore,Integer maximumIgnoreLength) throws ParseException : | |
| 278 | 278 | { |
| 279 | - MtasCQLParserSentenceCondition s1 = null, s2 = null; | |
| 279 | + MtasCQLParserSentenceCondition sc1 = null, sc2 = null; | |
| 280 | + MtasSpanSequenceItem si1 = null, si2=null; | |
| 280 | 281 | MtasSpanQuery q1 = null, q2 = null; |
| 281 | 282 | Token end = null; |
| 282 | 283 | String operator = null; |
| ... | ... | @@ -289,9 +290,9 @@ private MtasSpanQuery cqlBlock(String field, String defaultPrefix, HashMap<Strin |
| 289 | 290 | } |
| 290 | 291 | { |
| 291 | 292 | ( |
| 292 | - s1 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 293 | + sc1 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 293 | 294 | | |
| 294 | - < BRACKET_START > q1 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) < BRACKET_END > | |
| 295 | + < BRACKET_START > si1 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) < BRACKET_END > | |
| 295 | 296 | ) |
| 296 | 297 | [ |
| 297 | 298 | ( |
| ... | ... | @@ -321,44 +322,50 @@ private MtasSpanQuery cqlBlock(String field, String defaultPrefix, HashMap<Strin |
| 321 | 322 | } |
| 322 | 323 | ) |
| 323 | 324 | ( |
| 324 | - s2 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 325 | - | < BRACKET_START > q2 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) < BRACKET_END > | |
| 325 | + sc2 = sentence(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) | |
| 326 | + | < BRACKET_START > si2 = cqlBlock(field, defaultPrefix, variables, usedVariables, ignore, maximumIgnoreLength) < BRACKET_END > | |
| 326 | 327 | ) |
| 327 | 328 | ] |
| 328 | 329 | { |
| 329 | - if (s1 != null) | |
| 330 | + if (sc1 != null) | |
| 330 | 331 | { |
| 331 | - q1 = s1.getQuery(); | |
| 332 | + si1 = new MtasSpanSequenceItem(sc1.getQuery(),sc1.isOptional()); | |
| 332 | 333 | } |
| 333 | 334 | if (operator != null) |
| 334 | 335 | { |
| 335 | - if (s2 != null) | |
| 336 | + if (sc2 != null) | |
| 336 | 337 | { |
| 337 | - q2 = s2.getQuery(); | |
| 338 | + si2 = new MtasSpanSequenceItem(sc2.getQuery(),sc2.isOptional()); | |
| 338 | 339 | } |
| 339 | 340 | if (operator.equals(OPERATOR_CONTAINING)) |
| 340 | 341 | { |
| 341 | - return new MtasSpanContainingQuery(q1, q2); | |
| 342 | + MtasSpanQuery q = new MtasSpanContainingQuery(si1.getQuery(), si2.getQuery()); | |
| 343 | + return new MtasSpanSequenceItem(q, si1.isOptional()); | |
| 342 | 344 | } |
| 343 | 345 | else if (operator.equals(OPERATOR_NOT_CONTAINING)) |
| 344 | 346 | { |
| 345 | - return new MtasSpanNotQuery(q1, new MtasSpanContainingQuery(q1, q2)); | |
| 347 | + MtasSpanQuery q = new MtasSpanNotQuery(si1.getQuery(), new MtasSpanContainingQuery(si1.getQuery(), si2.getQuery())); | |
| 348 | + return new MtasSpanSequenceItem(q, si1.isOptional()); | |
| 346 | 349 | } |
| 347 | 350 | else if (operator.equals(OPERATOR_WITHIN)) |
| 348 | 351 | { |
| 349 | - return new MtasSpanWithinQuery(q2, q1); | |
| 352 | + MtasSpanQuery q = new MtasSpanWithinQuery(si2.getQuery(), si1.getQuery()); | |
| 353 | + return new MtasSpanSequenceItem(q, si1.isOptional()); | |
| 350 | 354 | } |
| 351 | 355 | else if (operator.equals(OPERATOR_NOT_WITHIN)) |
| 352 | 356 | { |
| 353 | - return new MtasSpanNotQuery(q1, new MtasSpanWithinQuery(q2, q1)); | |
| 357 | + MtasSpanQuery q = new MtasSpanNotQuery(si1.getQuery(), new MtasSpanWithinQuery(si2.getQuery(), si1.getQuery())); | |
| 358 | + return new MtasSpanSequenceItem(q, si1.isOptional()); | |
| 354 | 359 | } |
| 355 | 360 | else if (operator.equals(OPERATOR_INTERSECTING)) |
| 356 | 361 | { |
| 357 | - return new MtasSpanIntersectingQuery(q2, q1); | |
| 362 | + MtasSpanQuery q = new MtasSpanIntersectingQuery(si1.getQuery(), si2.getQuery()); | |
| 363 | + return new MtasSpanSequenceItem(q, si1.isOptional()); | |
| 358 | 364 | } |
| 359 | 365 | else if (operator.equals(OPERATOR_NOT_INTERSECTING)) |
| 360 | 366 | { |
| 361 | - return new MtasSpanNotQuery(q1, new MtasSpanIntersectingQuery(q2, q1)); | |
| 367 | + MtasSpanQuery q = new MtasSpanNotQuery(si1.getQuery(), new MtasSpanIntersectingQuery(si1.getQuery(), si2.getQuery())); | |
| 368 | + return new MtasSpanSequenceItem(q, si1.isOptional()); | |
| 362 | 369 | } |
| 363 | 370 | else |
| 364 | 371 | { |
| ... | ... | @@ -367,7 +374,7 @@ private MtasSpanQuery cqlBlock(String field, String defaultPrefix, HashMap<Strin |
| 367 | 374 | } |
| 368 | 375 | else |
| 369 | 376 | { |
| 370 | - return q1; | |
| 377 | + return si1; | |
| 371 | 378 | } |
| 372 | 379 | } |
| 373 | 380 | } |
| ... | ... |
src/mtas/parser/cql/util/MtasCQLParserBasicSentenceCondition.java
| ... | ... | @@ -21,7 +21,7 @@ public class MtasCQLParserBasicSentenceCondition { |
| 21 | 21 | private int minimumOccurence, maximumOccurence; |
| 22 | 22 | |
| 23 | 23 | /** The optional parts. */ |
| 24 | - private boolean simplified, optional, optionalParts; | |
| 24 | + private boolean simplified, optional; | |
| 25 | 25 | |
| 26 | 26 | private MtasSpanQuery ignoreClause; |
| 27 | 27 | |
| ... | ... | @@ -66,10 +66,10 @@ public class MtasCQLParserBasicSentenceCondition { |
| 66 | 66 | * @throws ParseException |
| 67 | 67 | * the parse exception |
| 68 | 68 | */ |
| 69 | - public void addGroup(MtasCQLParserGroupFullCondition w) | |
| 69 | + public void addGroup(MtasCQLParserGroupFullCondition g) | |
| 70 | 70 | throws ParseException { |
| 71 | 71 | if (!simplified) { |
| 72 | - partList.add(w); | |
| 72 | + partList.add(g); | |
| 73 | 73 | } else { |
| 74 | 74 | throw new ParseException("already simplified"); |
| 75 | 75 | } |
| ... | ... | @@ -146,20 +146,6 @@ public class MtasCQLParserBasicSentenceCondition { |
| 146 | 146 | return optional; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** | |
| 150 | - * Checks for optional parts. | |
| 151 | - * | |
| 152 | - * @return true, if successful | |
| 153 | - * @throws ParseException | |
| 154 | - * the parse exception | |
| 155 | - */ | |
| 156 | - public boolean hasOptionalParts() throws ParseException { | |
| 157 | - if (simplified) { | |
| 158 | - return optionalParts; | |
| 159 | - } else { | |
| 160 | - throw new ParseException("can't be called when not simplified"); | |
| 161 | - } | |
| 162 | - } | |
| 163 | 149 | |
| 164 | 150 | /** |
| 165 | 151 | * Sets the optional. |
| ... | ... | @@ -182,11 +168,11 @@ public class MtasCQLParserBasicSentenceCondition { |
| 182 | 168 | public void simplify() throws ParseException { |
| 183 | 169 | if (!simplified) { |
| 184 | 170 | simplified = true; |
| 185 | - optionalParts = true; | |
| 171 | + boolean optionalParts = true; | |
| 186 | 172 | List<MtasCQLParserBasicSentencePartCondition> newPartList; |
| 187 | 173 | MtasCQLParserBasicSentencePartCondition lastPart = null; |
| 188 | 174 | newPartList = new ArrayList<MtasCQLParserBasicSentencePartCondition>(); |
| 189 | - // try and merge equal word conditions | |
| 175 | + // try and merge equal basicSentencePart (word/group) conditions | |
| 190 | 176 | for (MtasCQLParserBasicSentencePartCondition part : partList) { |
| 191 | 177 | if ((lastPart == null) || !lastPart.equals(part)) { |
| 192 | 178 | lastPart = part; |
| ... | ... | @@ -209,8 +195,6 @@ public class MtasCQLParserBasicSentenceCondition { |
| 209 | 195 | newMaximumOccurence = lastPart.getMaximumOccurence() |
| 210 | 196 | + part.getMaximumOccurence(); |
| 211 | 197 | lastPart.setOccurence(newMinimumOccurence, newMaximumOccurence); |
| 212 | - lastPart.setOptional(false); | |
| 213 | - optionalParts = false; | |
| 214 | 198 | } else { |
| 215 | 199 | lastPart = part; |
| 216 | 200 | newPartList.add(part); |
| ... | ... | @@ -230,15 +214,12 @@ public class MtasCQLParserBasicSentenceCondition { |
| 230 | 214 | } else { |
| 231 | 215 | lastPart = part; |
| 232 | 216 | newPartList.add(part); |
| 233 | - if (!part.isOptional()) { | |
| 234 | - optionalParts = false; | |
| 235 | - } | |
| 217 | + optionalParts = false; | |
| 236 | 218 | } |
| 237 | 219 | } else { |
| 238 | 220 | if ((lastPart.getMinimumOccurence() == 1) |
| 239 | 221 | && (part.getMinimumOccurence() == 1)) { |
| 240 | - newMinimumOccurence = lastPart.getMinimumOccurence() | |
| 241 | - + part.getMinimumOccurence() - 1; | |
| 222 | + newMinimumOccurence = 1; | |
| 242 | 223 | newMaximumOccurence = lastPart.getMaximumOccurence() |
| 243 | 224 | + part.getMaximumOccurence(); |
| 244 | 225 | lastPart.setOccurence(newMinimumOccurence, newMaximumOccurence); |
| ... | ... | @@ -246,9 +227,6 @@ public class MtasCQLParserBasicSentenceCondition { |
| 246 | 227 | } else { |
| 247 | 228 | lastPart = part; |
| 248 | 229 | newPartList.add(part); |
| 249 | - if (!part.isOptional()) { | |
| 250 | - optionalParts = false; | |
| 251 | - } | |
| 252 | 230 | } |
| 253 | 231 | } |
| 254 | 232 | } |
| ... | ... | @@ -265,7 +243,7 @@ public class MtasCQLParserBasicSentenceCondition { |
| 265 | 243 | * |
| 266 | 244 | * @return the part list |
| 267 | 245 | */ |
| 268 | - public List<MtasCQLParserBasicSentencePartCondition> getPartList() { | |
| 246 | + private List<MtasCQLParserBasicSentencePartCondition> getPartList() { | |
| 269 | 247 | return partList; |
| 270 | 248 | } |
| 271 | 249 | |
| ... | ... |
src/mtas/parser/cql/util/MtasCQLParserSentenceCondition.java
| ... | ... | @@ -10,23 +10,16 @@ import mtas.search.spans.MtasSpanSequenceItem; |
| 10 | 10 | import mtas.search.spans.MtasSpanSequenceQuery; |
| 11 | 11 | import mtas.search.spans.util.MtasSpanQuery; |
| 12 | 12 | |
| 13 | - | |
| 14 | 13 | /** |
| 15 | 14 | * The Class MtasCQLParserSentenceCondition. |
| 16 | 15 | */ |
| 17 | 16 | public class MtasCQLParserSentenceCondition { |
| 18 | 17 | |
| 19 | - // parent list: multiple items for OR | |
| 20 | 18 | /** The sequence list. */ |
| 19 | + // parent list: multiple items for OR | |
| 21 | 20 | // child list: sequence |
| 22 | 21 | private List<List<MtasCQLParserSentenceCondition>> sequenceList; |
| 23 | 22 | |
| 24 | - /** The sentence sequence. */ | |
| 25 | - private List<MtasCQLParserSentenceCondition> sentenceSequence = null; | |
| 26 | - | |
| 27 | - /** The sentence current. */ | |
| 28 | - private MtasCQLParserSentenceCondition sentenceCurrent = null; | |
| 29 | - | |
| 30 | 23 | /** The basic sentence. */ |
| 31 | 24 | private MtasCQLParserBasicSentenceCondition basicSentence = null; |
| 32 | 25 | |
| ... | ... | @@ -34,10 +27,10 @@ public class MtasCQLParserSentenceCondition { |
| 34 | 27 | private int minimumOccurence, maximumOccurence; |
| 35 | 28 | |
| 36 | 29 | /** The optional parts. */ |
| 37 | - private boolean basic, simplified, optional, optionalParts; | |
| 38 | - | |
| 30 | + private boolean basic, simplified, optional; | |
| 31 | + | |
| 39 | 32 | private MtasSpanQuery ignore; |
| 40 | - | |
| 33 | + | |
| 41 | 34 | private Integer maximumIgnoreLength; |
| 42 | 35 | |
| 43 | 36 | /** |
| ... | ... | @@ -48,10 +41,10 @@ public class MtasCQLParserSentenceCondition { |
| 48 | 41 | * @throws ParseException |
| 49 | 42 | * the parse exception |
| 50 | 43 | */ |
| 51 | - public MtasCQLParserSentenceCondition(MtasCQLParserBasicSentenceCondition s, MtasSpanQuery ignore, Integer maximumIgnoreLength) | |
| 52 | - throws ParseException { | |
| 44 | + public MtasCQLParserSentenceCondition(MtasCQLParserBasicSentenceCondition s, | |
| 45 | + MtasSpanQuery ignore, Integer maximumIgnoreLength) throws ParseException { | |
| 53 | 46 | sequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>(); |
| 54 | - basicSentence = s; | |
| 47 | + basicSentence = s; | |
| 55 | 48 | minimumOccurence = 1; |
| 56 | 49 | maximumOccurence = 1; |
| 57 | 50 | simplified = false; |
| ... | ... | @@ -69,8 +62,8 @@ public class MtasCQLParserSentenceCondition { |
| 69 | 62 | * @throws ParseException |
| 70 | 63 | * the parse exception |
| 71 | 64 | */ |
| 72 | - public MtasCQLParserSentenceCondition(MtasCQLParserSentenceCondition sp, MtasSpanQuery ignore, Integer maximumIgnoreLength) | |
| 73 | - throws ParseException { | |
| 65 | + public MtasCQLParserSentenceCondition(MtasCQLParserSentenceCondition sp, | |
| 66 | + MtasSpanQuery ignore, Integer maximumIgnoreLength) throws ParseException { | |
| 74 | 67 | sequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>(); |
| 75 | 68 | addSentenceToEndLatestSequence(sp); |
| 76 | 69 | minimumOccurence = 1; |
| ... | ... | @@ -100,8 +93,12 @@ public class MtasCQLParserSentenceCondition { |
| 100 | 93 | basicSentence.addBasicSentence(s); |
| 101 | 94 | } |
| 102 | 95 | } else { |
| 103 | - sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore, maximumIgnoreLength); | |
| 104 | - sentenceSequence.add(sentenceCurrent); | |
| 96 | + MtasCQLParserSentenceCondition sentenceCurrent = new MtasCQLParserSentenceCondition( | |
| 97 | + s, ignore, maximumIgnoreLength); | |
| 98 | + if (sequenceList.size() == 0) { | |
| 99 | + sequenceList.add(new ArrayList<MtasCQLParserSentenceCondition>()); | |
| 100 | + } | |
| 101 | + sequenceList.get(sequenceList.size() - 1).add(sentenceCurrent); | |
| 105 | 102 | } |
| 106 | 103 | } else { |
| 107 | 104 | throw new ParseException("already simplified"); |
| ... | ... | @@ -116,37 +113,42 @@ public class MtasCQLParserSentenceCondition { |
| 116 | 113 | * @throws ParseException |
| 117 | 114 | * the parse exception |
| 118 | 115 | */ |
| 119 | - public void addBasicSentenceAsOption(MtasCQLParserBasicSentenceCondition s) | |
| 120 | - throws ParseException { | |
| 121 | - if (!simplified) { | |
| 122 | - if (isBasic()) { | |
| 123 | - if (basicSentence == null) { | |
| 124 | - basicSentence = s; | |
| 125 | - } else { | |
| 126 | - // add previous basic sentence as first option | |
| 127 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 128 | - sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, ignore, maximumIgnoreLength); | |
| 129 | - sentenceSequence.add(sentenceCurrent); | |
| 130 | - sequenceList.add(sentenceSequence); | |
| 131 | - basicSentence = null; | |
| 132 | - // create new option for current basic sentence | |
| 133 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 134 | - sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore, maximumIgnoreLength); | |
| 135 | - sentenceSequence.add(sentenceCurrent); | |
| 136 | - sequenceList.add(sentenceSequence); | |
| 137 | - // not basic anymore | |
| 138 | - basic = false; | |
| 139 | - } | |
| 140 | - } else { | |
| 141 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 142 | - sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore, maximumIgnoreLength); | |
| 143 | - sentenceSequence.add(sentenceCurrent); | |
| 144 | - sequenceList.add(sentenceSequence); | |
| 145 | - } | |
| 146 | - } else { | |
| 147 | - throw new ParseException("already simplified"); | |
| 148 | - } | |
| 149 | - } | |
| 116 | + // public void addBasicSentenceAsOption(MtasCQLParserBasicSentenceCondition s) | |
| 117 | + // throws ParseException { | |
| 118 | + // if (!simplified) { | |
| 119 | + // MtasCQLParserSentenceCondition sentenceCurrent; | |
| 120 | + // List<MtasCQLParserSentenceCondition> sentenceSequence; | |
| 121 | + // if (isBasic()) { | |
| 122 | + // if (basicSentence == null) { | |
| 123 | + // basicSentence = s; | |
| 124 | + // } else { | |
| 125 | + // // add previous basic sentence as first option | |
| 126 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 127 | + // sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, | |
| 128 | + // ignore, maximumIgnoreLength); | |
| 129 | + // sentenceSequence.add(sentenceCurrent); | |
| 130 | + // sequenceList.add(sentenceSequence); | |
| 131 | + // basicSentence = null; | |
| 132 | + // // create new option for current basic sentence | |
| 133 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 134 | + // sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore, | |
| 135 | + // maximumIgnoreLength); | |
| 136 | + // sentenceSequence.add(sentenceCurrent); | |
| 137 | + // sequenceList.add(sentenceSequence); | |
| 138 | + // // not basic anymore | |
| 139 | + // basic = false; | |
| 140 | + // } | |
| 141 | + // } else { | |
| 142 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 143 | + // sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore, | |
| 144 | + // maximumIgnoreLength); | |
| 145 | + // sentenceSequence.add(sentenceCurrent); | |
| 146 | + // sequenceList.add(sentenceSequence); | |
| 147 | + // } | |
| 148 | + // } else { | |
| 149 | + // throw new ParseException("already simplified"); | |
| 150 | + // } | |
| 151 | + // } | |
| 150 | 152 | |
| 151 | 153 | /** |
| 152 | 154 | * Adds the sentence to start first sequence. |
| ... | ... | @@ -156,43 +158,47 @@ public class MtasCQLParserSentenceCondition { |
| 156 | 158 | * @throws ParseException |
| 157 | 159 | * the parse exception |
| 158 | 160 | */ |
| 159 | - public void addSentenceToStartFirstSequence(MtasCQLParserSentenceCondition s) | |
| 160 | - throws ParseException { | |
| 161 | - if (!simplified) { | |
| 162 | - if (isBasic()) { | |
| 163 | - if (basicSentence == null) { | |
| 164 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 165 | - sentenceCurrent = s; | |
| 166 | - sentenceSequence.add(sentenceCurrent); | |
| 167 | - sequenceList.add(sentenceSequence); | |
| 168 | - // not basic anymore | |
| 169 | - basic = false; | |
| 170 | - } else { | |
| 171 | - // add sentence as first item in new sequence | |
| 172 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 173 | - // add sentence to first option | |
| 174 | - sentenceCurrent = s; | |
| 175 | - sentenceSequence.add(sentenceCurrent); | |
| 176 | - // add basic sentence as second item | |
| 177 | - sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, ignore, maximumIgnoreLength); | |
| 178 | - sentenceSequence.add(sentenceCurrent); | |
| 179 | - sequenceList.add(sentenceSequence); | |
| 180 | - basicSentence = null; | |
| 181 | - // not simple anymore | |
| 182 | - basic = false; | |
| 183 | - } | |
| 184 | - } else { | |
| 185 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 186 | - sentenceSequence.add(s); | |
| 187 | - sentenceSequence.addAll(sequenceList.get(0)); | |
| 188 | - sequenceList.set(0, sentenceSequence); | |
| 189 | - sentenceSequence = sequenceList.get((sequenceList.size() - 1)); | |
| 190 | - sentenceCurrent = sentenceSequence.get((sentenceSequence.size() - 1)); | |
| 191 | - } | |
| 192 | - } else { | |
| 193 | - throw new ParseException("already simplified"); | |
| 194 | - } | |
| 195 | - } | |
| 161 | + // public void addSentenceToStartFirstSequence(MtasCQLParserSentenceCondition | |
| 162 | + // s) | |
| 163 | + // throws ParseException { | |
| 164 | + // if (!simplified) { | |
| 165 | + // MtasCQLParserSentenceCondition sentenceCurrent; | |
| 166 | + // List<MtasCQLParserSentenceCondition> sentenceSequence; | |
| 167 | + // if (isBasic()) { | |
| 168 | + // if (basicSentence == null) { | |
| 169 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 170 | + // sentenceCurrent = s; | |
| 171 | + // sentenceSequence.add(sentenceCurrent); | |
| 172 | + // sequenceList.add(sentenceSequence); | |
| 173 | + // // not basic anymore | |
| 174 | + // basic = false; | |
| 175 | + // } else { | |
| 176 | + // // add sentence as first item in new sequence | |
| 177 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 178 | + // // add sentence to first option | |
| 179 | + // sentenceCurrent = s; | |
| 180 | + // sentenceSequence.add(sentenceCurrent); | |
| 181 | + // // add basic sentence as second item | |
| 182 | + // sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, | |
| 183 | + // ignore, maximumIgnoreLength); | |
| 184 | + // sentenceSequence.add(sentenceCurrent); | |
| 185 | + // sequenceList.add(sentenceSequence); | |
| 186 | + // basicSentence = null; | |
| 187 | + // // not simple anymore | |
| 188 | + // basic = false; | |
| 189 | + // } | |
| 190 | + // } else { | |
| 191 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 192 | + // sentenceSequence.add(s); | |
| 193 | + // sentenceSequence.addAll(sequenceList.get(0)); | |
| 194 | + // sequenceList.set(0, sentenceSequence); | |
| 195 | + // sentenceSequence = sequenceList.get((sequenceList.size() - 1)); | |
| 196 | + // sentenceCurrent = sentenceSequence.get((sentenceSequence.size() - 1)); | |
| 197 | + // } | |
| 198 | + // } else { | |
| 199 | + // throw new ParseException("already simplified"); | |
| 200 | + // } | |
| 201 | + // } | |
| 196 | 202 | |
| 197 | 203 | /** |
| 198 | 204 | * Adds the sentence to end latest sequence. |
| ... | ... | @@ -205,6 +211,8 @@ public class MtasCQLParserSentenceCondition { |
| 205 | 211 | public void addSentenceToEndLatestSequence(MtasCQLParserSentenceCondition s) |
| 206 | 212 | throws ParseException { |
| 207 | 213 | if (!simplified) { |
| 214 | + MtasCQLParserSentenceCondition sentenceCurrent; | |
| 215 | + List<MtasCQLParserSentenceCondition> sentenceSequence; | |
| 208 | 216 | if (isBasic()) { |
| 209 | 217 | if (basicSentence == null) { |
| 210 | 218 | sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); |
| ... | ... | @@ -216,7 +224,8 @@ public class MtasCQLParserSentenceCondition { |
| 216 | 224 | } else { |
| 217 | 225 | // add previous basic sentence as first option |
| 218 | 226 | sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); |
| 219 | - sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, ignore, maximumIgnoreLength); | |
| 227 | + sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, | |
| 228 | + ignore, maximumIgnoreLength); | |
| 220 | 229 | sentenceSequence.add(sentenceCurrent); |
| 221 | 230 | sequenceList.add(sentenceSequence); |
| 222 | 231 | basicSentence = null; |
| ... | ... | @@ -228,11 +237,10 @@ public class MtasCQLParserSentenceCondition { |
| 228 | 237 | } |
| 229 | 238 | } else { |
| 230 | 239 | sentenceCurrent = s; |
| 231 | - if (sentenceSequence == null) { | |
| 232 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 233 | - sequenceList.add(sentenceSequence); | |
| 240 | + if (sequenceList.size() == 0) { | |
| 241 | + sequenceList.add(new ArrayList<MtasCQLParserSentenceCondition>()); | |
| 234 | 242 | } |
| 235 | - sentenceSequence.add(sentenceCurrent); | |
| 243 | + sequenceList.get(sequenceList.size() - 1).add(sentenceCurrent); | |
| 236 | 244 | } |
| 237 | 245 | } else { |
| 238 | 246 | throw new ParseException("already simplified"); |
| ... | ... | @@ -250,6 +258,8 @@ public class MtasCQLParserSentenceCondition { |
| 250 | 258 | public void addSentenceAsFirstOption(MtasCQLParserSentenceCondition s) |
| 251 | 259 | throws ParseException { |
| 252 | 260 | if (!simplified) { |
| 261 | + MtasCQLParserSentenceCondition sentenceCurrent; | |
| 262 | + List<MtasCQLParserSentenceCondition> sentenceSequence; | |
| 253 | 263 | if (isBasic()) { |
| 254 | 264 | if (basicSentence == null) { |
| 255 | 265 | sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); |
| ... | ... | @@ -266,7 +276,8 @@ public class MtasCQLParserSentenceCondition { |
| 266 | 276 | sequenceList.add(sentenceSequence); |
| 267 | 277 | // add previous basic sentence as new option |
| 268 | 278 | sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); |
| 269 | - sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, ignore, maximumIgnoreLength); | |
| 279 | + sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, | |
| 280 | + ignore, maximumIgnoreLength); | |
| 270 | 281 | sentenceSequence.add(sentenceCurrent); |
| 271 | 282 | sequenceList.add(sentenceSequence); |
| 272 | 283 | basicSentence = null; |
| ... | ... | @@ -295,49 +306,52 @@ public class MtasCQLParserSentenceCondition { |
| 295 | 306 | * @throws ParseException |
| 296 | 307 | * the parse exception |
| 297 | 308 | */ |
| 298 | - public void addSentenceAsOption(MtasCQLParserSentenceCondition s) | |
| 299 | - throws ParseException { | |
| 300 | - if (!simplified) { | |
| 301 | - if (isBasic()) { | |
| 302 | - if (basicSentence == null) { | |
| 303 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 304 | - sentenceCurrent = s; | |
| 305 | - sentenceSequence.add(sentenceCurrent); | |
| 306 | - sequenceList.add(sentenceSequence); | |
| 307 | - // not simple anymore | |
| 308 | - basic = false; | |
| 309 | - } else { | |
| 310 | - // add previous basic sentence as first option | |
| 311 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 312 | - sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, ignore, maximumIgnoreLength); | |
| 313 | - sentenceSequence.add(sentenceCurrent); | |
| 314 | - sequenceList.add(sentenceSequence); | |
| 315 | - basicSentence = null; | |
| 316 | - // add sentence as new option | |
| 317 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 318 | - sentenceCurrent = s; | |
| 319 | - sentenceSequence.add(sentenceCurrent); | |
| 320 | - sequenceList.add(sentenceSequence); | |
| 321 | - // not simple anymore | |
| 322 | - basic = false; | |
| 323 | - } | |
| 324 | - } else { | |
| 325 | - sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 326 | - sentenceCurrent = s; | |
| 327 | - sentenceSequence.add(sentenceCurrent); | |
| 328 | - sequenceList.add(sentenceSequence); | |
| 329 | - } | |
| 330 | - } else { | |
| 331 | - throw new ParseException("already simplified"); | |
| 332 | - } | |
| 333 | - } | |
| 309 | + // public void addSentenceAsOption(MtasCQLParserSentenceCondition s) | |
| 310 | + // throws ParseException { | |
| 311 | + // if (!simplified) { | |
| 312 | + // MtasCQLParserSentenceCondition sentenceCurrent; | |
| 313 | + // List<MtasCQLParserSentenceCondition> sentenceSequence; | |
| 314 | + // if (isBasic()) { | |
| 315 | + // if (basicSentence == null) { | |
| 316 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 317 | + // sentenceCurrent = s; | |
| 318 | + // sentenceSequence.add(sentenceCurrent); | |
| 319 | + // sequenceList.add(sentenceSequence); | |
| 320 | + // // not simple anymore | |
| 321 | + // basic = false; | |
| 322 | + // } else { | |
| 323 | + // // add previous basic sentence as first option | |
| 324 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 325 | + // sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence, | |
| 326 | + // ignore, maximumIgnoreLength); | |
| 327 | + // sentenceSequence.add(sentenceCurrent); | |
| 328 | + // sequenceList.add(sentenceSequence); | |
| 329 | + // basicSentence = null; | |
| 330 | + // // add sentence as new option | |
| 331 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 332 | + // sentenceCurrent = s; | |
| 333 | + // sentenceSequence.add(sentenceCurrent); | |
| 334 | + // sequenceList.add(sentenceSequence); | |
| 335 | + // // not simple anymore | |
| 336 | + // basic = false; | |
| 337 | + // } | |
| 338 | + // } else { | |
| 339 | + // sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>(); | |
| 340 | + // sentenceCurrent = s; | |
| 341 | + // sentenceSequence.add(sentenceCurrent); | |
| 342 | + // sequenceList.add(sentenceSequence); | |
| 343 | + // } | |
| 344 | + // } else { | |
| 345 | + // throw new ParseException("already simplified"); | |
| 346 | + // } | |
| 347 | + // } | |
| 334 | 348 | |
| 335 | 349 | /** |
| 336 | 350 | * Checks if is basic. |
| 337 | 351 | * |
| 338 | 352 | * @return true, if is basic |
| 339 | 353 | */ |
| 340 | - public boolean isBasic() { | |
| 354 | + private boolean isBasic() { | |
| 341 | 355 | return basic; |
| 342 | 356 | } |
| 343 | 357 | |
| ... | ... | @@ -346,7 +360,7 @@ public class MtasCQLParserSentenceCondition { |
| 346 | 360 | * |
| 347 | 361 | * @return true, if is single |
| 348 | 362 | */ |
| 349 | - public boolean isSingle() { | |
| 363 | + private boolean isSingle() { | |
| 350 | 364 | return basic ? true : ((sequenceList.size() > 1) ? false : true); |
| 351 | 365 | } |
| 352 | 366 | |
| ... | ... | @@ -362,22 +376,22 @@ public class MtasCQLParserSentenceCondition { |
| 362 | 376 | for (List<MtasCQLParserSentenceCondition> sequence : sequenceList) { |
| 363 | 377 | simplifySequence(sequence); |
| 364 | 378 | } |
| 365 | - } | |
| 366 | - // flatten | |
| 367 | - if (sequenceList.size() > 1) { | |
| 368 | - List<List<MtasCQLParserSentenceCondition>> newSequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>(); | |
| 369 | - for (List<MtasCQLParserSentenceCondition> sequence : sequenceList) { | |
| 370 | - if (sequence.size() == 1) { | |
| 371 | - MtasCQLParserSentenceCondition subSentence = sequence.get(0); | |
| 372 | - if (subSentence.isBasic()) { | |
| 373 | - newSequenceList.add(sequence); | |
| 374 | - } else { | |
| 375 | - newSequenceList.addAll(subSentence.getsequenceList()); | |
| 379 | + // flatten | |
| 380 | + if (sequenceList.size() > 1) { | |
| 381 | + List<List<MtasCQLParserSentenceCondition>> newSequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>(); | |
| 382 | + for (List<MtasCQLParserSentenceCondition> sequence : sequenceList) { | |
| 383 | + if (sequence.size() == 1) { | |
| 384 | + MtasCQLParserSentenceCondition subSentence = sequence.get(0); | |
| 385 | + if (subSentence.isBasic()) { | |
| 386 | + newSequenceList.add(sequence); | |
| 387 | + } else { | |
| 388 | + newSequenceList.addAll(subSentence.sequenceList); | |
| 389 | + } | |
| 376 | 390 | } |
| 377 | 391 | } |
| 392 | + sequenceList = newSequenceList; | |
| 378 | 393 | } |
| 379 | - sequenceList = newSequenceList; | |
| 380 | - } | |
| 394 | + } | |
| 381 | 395 | simplified = true; |
| 382 | 396 | } |
| 383 | 397 | } |
| ... | ... | @@ -399,93 +413,69 @@ public class MtasCQLParserSentenceCondition { |
| 399 | 413 | if (lastSentence == null) { |
| 400 | 414 | lastSentence = sentence; |
| 401 | 415 | } else if (lastSentence.isBasic() && sentence.isBasic()) { |
| 402 | - // if no recurrence or equal queries | |
| 403 | - // opt1 optPart1 opt2 optPart2 merge opt optPart | |
| 404 | - // ..-.....-.....-........-.....+.....-.....- | |
| 405 | - // ..+.....-.....-........-.....-............ | |
| 406 | - // ..+.....+.....-........-.....+.....-.....- | |
| 407 | - // ..-.....-.....+........-.....-............ | |
| 408 | - // ..+.....-.....+........-.....-............ | |
| 409 | - // ..+.....+.....+........-.....+.....+.....- | |
| 410 | - // ..-.....-.....+........+.....+.....-.....- | |
| 411 | - // ..+.....-.....+........+.....+.....+.....- | |
| 412 | - // ..+.....+.....+........+.....+.....+.....+ | |
| 413 | - if ((((lastSentence.getMaximumOccurence() == 1) | |
| 414 | - && (sentence.getMaximumOccurence() == 1)) | |
| 415 | - || lastSentence.getQuery().equals(sentence.getQuery()) | |
| 416 | - && ((!lastSentence.isOptional() && !sentence.isOptional())) | |
| 417 | - || lastSentence.hasOptionalParts() | |
| 418 | - || sentence.hasOptionalParts())) { | |
| 419 | - // create new basic sentence | |
| 420 | - MtasCQLParserBasicSentenceCondition newBasicSentence = new MtasCQLParserBasicSentenceCondition(ignore, maximumIgnoreLength); | |
| 421 | - newBasicSentence.addBasicSentence(lastSentence.basicSentence); | |
| 422 | - newBasicSentence.addBasicSentence(sentence.basicSentence); | |
| 423 | - // make optional | |
| 424 | - if (lastSentence.isOptional() && sentence.isOptional()) { | |
| 425 | - newBasicSentence.setOptional(true); | |
| 426 | - } | |
| 427 | - lastSentence = new MtasCQLParserSentenceCondition(newBasicSentence, ignore, maximumIgnoreLength); | |
| 428 | - lastSentence.simplify(); | |
| 416 | + if (!lastSentence.isOptional() && !sentence.isOptional() | |
| 417 | + && sentence.getMaximumOccurence() == 1 | |
| 418 | + && lastSentence.getMaximumOccurence() == 1) { | |
| 419 | + lastSentence.basicSentence.addBasicSentence(sentence.basicSentence); | |
| 429 | 420 | } else { |
| 430 | 421 | newSequence.add(lastSentence); |
| 431 | 422 | lastSentence = sentence; |
| 432 | 423 | } |
| 433 | - } else if (lastSentence.isBasic()) { | |
| 434 | - if (sentence.isSingle() | |
| 435 | - && (!sentence.isOptional() || sentence.hasOptionalParts()) | |
| 436 | - && ((sentence.getMaximumOccurence() == 1) | |
| 437 | - && (lastSentence.getMaximumOccurence() == 1))) { | |
| 438 | - for (MtasCQLParserSentenceCondition subSentence : sentence | |
| 439 | - .getsequenceList().get(0)) { | |
| 424 | + } else if (lastSentence.isBasic() && !sentence.isBasic()) { | |
| 425 | + if (sentence.isSingle() && !sentence.isOptional() | |
| 426 | + && sentence.getMaximumOccurence() == 1 | |
| 427 | + && lastSentence.getMaximumOccurence() == 1) { | |
| 428 | + // add all items from (first) sequenceList potentially to the new | |
| 429 | + // sequence | |
| 430 | + for (MtasCQLParserSentenceCondition subSentence : sentence.sequenceList | |
| 431 | + .get(0)) { | |
| 440 | 432 | newSequence.add(lastSentence); |
| 441 | 433 | lastSentence = subSentence; |
| 442 | 434 | } |
| 443 | 435 | } else { |
| 436 | + // add sentence potentially to the new sequence | |
| 444 | 437 | newSequence.add(lastSentence); |
| 445 | 438 | lastSentence = sentence; |
| 446 | 439 | } |
| 447 | - } else if (sentence.isBasic()) { | |
| 448 | - if (lastSentence.isSingle() | |
| 449 | - && (!lastSentence.isOptional() || lastSentence.hasOptionalParts()) | |
| 450 | - && ((sentence.getMaximumOccurence() == 1) | |
| 451 | - && (lastSentence.getMaximumOccurence() == 1))) { | |
| 440 | + } else if (!lastSentence.isBasic() && sentence.isBasic()) { | |
| 441 | + if (lastSentence.isSingle() && !lastSentence.isOptional() | |
| 442 | + && sentence.getMaximumOccurence() == 1 | |
| 443 | + && lastSentence.getMaximumOccurence() == 1) { | |
| 444 | + // add basic sentence to end latest sequence | |
| 452 | 445 | lastSentence |
| 453 | - .addBasicSentenceToEndLatestSequence(sentence.getBasicSentence()); | |
| 446 | + .addBasicSentenceToEndLatestSequence(sentence.basicSentence); | |
| 454 | 447 | } else { |
| 448 | + // add sentence potentially to the new sequence | |
| 455 | 449 | newSequence.add(lastSentence); |
| 456 | 450 | lastSentence = sentence; |
| 457 | 451 | } |
| 458 | 452 | } else { |
| 459 | - newSequence.add(lastSentence); | |
| 460 | - lastSentence = sentence; | |
| 453 | + if (sentence.isSingle() && !sentence.isOptional() | |
| 454 | + && lastSentence.isSingle() && !lastSentence.isOptional() | |
| 455 | + && sentence.getMaximumOccurence() == 1 | |
| 456 | + && lastSentence.getMaximumOccurence() == 1) { | |
| 457 | + // combine sentences | |
| 458 | + for (MtasCQLParserSentenceCondition subSentence : sentence.sequenceList | |
| 459 | + .get(0)) { | |
| 460 | + lastSentence.sequenceList.get(0).add(subSentence); | |
| 461 | + } | |
| 462 | + } else { | |
| 463 | + // add sentence potentially to the new sequence (both not basic) | |
| 464 | + newSequence.add(lastSentence); | |
| 465 | + lastSentence = sentence; | |
| 466 | + } | |
| 461 | 467 | } |
| 462 | 468 | } |
| 469 | + // add last to newSequence | |
| 463 | 470 | if (lastSentence != null) { |
| 464 | 471 | newSequence.add(lastSentence); |
| 465 | 472 | } |
| 473 | + // replace content sequence with newSequence | |
| 466 | 474 | sequence.clear(); |
| 467 | 475 | sequence.addAll(newSequence); |
| 468 | 476 | } |
| 469 | 477 | |
| 470 | 478 | /** |
| 471 | - * Gets the sequence list. | |
| 472 | - * | |
| 473 | - * @return the sequence list | |
| 474 | - */ | |
| 475 | - public List<List<MtasCQLParserSentenceCondition>> getsequenceList() { | |
| 476 | - return sequenceList; | |
| 477 | - } | |
| 478 | - | |
| 479 | - /** | |
| 480 | - * Gets the basic sentence. | |
| 481 | - * | |
| 482 | - * @return the basic sentence | |
| 483 | - */ | |
| 484 | - public MtasCQLParserBasicSentenceCondition getBasicSentence() { | |
| 485 | - return basicSentence; | |
| 486 | - } | |
| 487 | - | |
| 488 | - /** | |
| 489 | 479 | * Gets the minimum occurence. |
| 490 | 480 | * |
| 491 | 481 | * @return the minimum occurence |
| ... | ... | @@ -540,13 +530,13 @@ public class MtasCQLParserSentenceCondition { |
| 540 | 530 | * @throws ParseException |
| 541 | 531 | * the parse exception |
| 542 | 532 | */ |
| 543 | - public boolean hasOptionalParts() throws ParseException { | |
| 544 | - if (simplified) { | |
| 545 | - return optionalParts; | |
| 546 | - } else { | |
| 547 | - throw new ParseException("can't be called when not simplified"); | |
| 548 | - } | |
| 549 | - } | |
| 533 | + // public boolean hasOptionalParts() throws ParseException { | |
| 534 | + // if (simplified) { | |
| 535 | + // return optionalParts; | |
| 536 | + // } else { | |
| 537 | + // throw new ParseException("can't be called when not simplified"); | |
| 538 | + // } | |
| 539 | + // } | |
| 550 | 540 | |
| 551 | 541 | /** |
| 552 | 542 | * Sets the optional. |
| ... | ... | @@ -584,7 +574,8 @@ public class MtasCQLParserSentenceCondition { |
| 584 | 574 | new MtasSpanSequenceItem(sentence.getQuery(), sentence.optional)); |
| 585 | 575 | } |
| 586 | 576 | if (maximumOccurence > 1) { |
| 587 | - return new MtasSpanRecurrenceQuery(new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength), | |
| 577 | + return new MtasSpanRecurrenceQuery( | |
| 578 | + new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength), | |
| 588 | 579 | minimumOccurence, maximumOccurence, ignore, maximumIgnoreLength); |
| 589 | 580 | } else { |
| 590 | 581 | return new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength); |
| ... | ... |
src/mtas/parser/cql/util/MtasCQLParserSentencePartCondition.java
| ... | ... | @@ -64,23 +64,7 @@ public class MtasCQLParserSentencePartCondition { |
| 64 | 64 | this.maximumIgnoreLength = maximumIgnoreLength; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - /** | |
| 68 | - * Gets the first minimum occurence. | |
| 69 | - * | |
| 70 | - * @return the first minimum occurence | |
| 71 | - */ | |
| 72 | - public int getFirstMinimumOccurence() { | |
| 73 | - return firstMinimumOccurence; | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Gets the first maximum occurence. | |
| 78 | - * | |
| 79 | - * @return the first maximum occurence | |
| 80 | - */ | |
| 81 | - public int getFirstMaximumOccurence() { | |
| 82 | - return firstMaximumOccurence; | |
| 83 | - } | |
| 67 | + | |
| 84 | 68 | |
| 85 | 69 | /** |
| 86 | 70 | * Sets the first occurence. |
| ... | ... | @@ -108,15 +92,6 @@ public class MtasCQLParserSentencePartCondition { |
| 108 | 92 | } |
| 109 | 93 | |
| 110 | 94 | /** |
| 111 | - * Checks if is first optional. | |
| 112 | - * | |
| 113 | - * @return true, if is first optional | |
| 114 | - */ | |
| 115 | - public boolean isFirstOptional() { | |
| 116 | - return firstOptional; | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | 95 | * Sets the first optional. |
| 121 | 96 | * |
| 122 | 97 | * @param status |
| ... | ... | @@ -126,7 +101,7 @@ public class MtasCQLParserSentencePartCondition { |
| 126 | 101 | */ |
| 127 | 102 | public void setFirstOptional(boolean status) throws ParseException { |
| 128 | 103 | if (fullCondition == null) { |
| 129 | - firstOptional = status; | |
| 104 | + firstOptional = status; | |
| 130 | 105 | } else { |
| 131 | 106 | throw new ParseException("fullCondition already generated"); |
| 132 | 107 | } |
| ... | ... | @@ -179,29 +154,32 @@ public class MtasCQLParserSentencePartCondition { |
| 179 | 154 | if (firstBasicSentence != null) { |
| 180 | 155 | fullCondition = new MtasCQLParserSentenceCondition( |
| 181 | 156 | firstBasicSentence, ignoreClause, maximumIgnoreLength); |
| 182 | - fullCondition.setOccurence(firstMinimumOccurence, | |
| 183 | - firstMaximumOccurence); | |
| 184 | - return fullCondition; | |
| 157 | + | |
| 185 | 158 | } else { |
| 186 | - fullCondition = firstSentence; | |
| 187 | - fullCondition.setOccurence(firstMinimumOccurence, | |
| 188 | - firstMaximumOccurence); | |
| 189 | - return fullCondition; | |
| 159 | + fullCondition = firstSentence; | |
| 160 | + } | |
| 161 | + fullCondition.setOccurence(firstMinimumOccurence, | |
| 162 | + firstMaximumOccurence); | |
| 163 | + if(firstOptional) { | |
| 164 | + fullCondition.setOptional(firstOptional); | |
| 190 | 165 | } |
| 166 | + return fullCondition; | |
| 191 | 167 | } else { |
| 192 | 168 | if (!orOperator) { |
| 193 | 169 | if (firstBasicSentence != null) { |
| 194 | 170 | firstBasicSentence.setOccurence(firstMinimumOccurence, |
| 195 | 171 | firstMaximumOccurence); |
| 172 | + firstBasicSentence.setOptional(firstOptional); | |
| 196 | 173 | fullCondition = new MtasCQLParserSentenceCondition( |
| 197 | 174 | firstBasicSentence, ignoreClause, maximumIgnoreLength); |
| 198 | 175 | } else { |
| 199 | 176 | firstSentence.setOccurence(firstMinimumOccurence, |
| 200 | 177 | firstMaximumOccurence); |
| 178 | + firstSentence.setOptional(firstOptional); | |
| 201 | 179 | fullCondition = new MtasCQLParserSentenceCondition(firstSentence, ignoreClause, maximumIgnoreLength); |
| 202 | 180 | } |
| 203 | 181 | fullCondition.addSentenceToEndLatestSequence( |
| 204 | - secondSentencePart.createFullSentence()); | |
| 182 | + secondSentencePart.createFullSentence()); | |
| 205 | 183 | } else { |
| 206 | 184 | MtasCQLParserSentenceCondition sentence = secondSentencePart |
| 207 | 185 | .createFullSentence(); |
| ... | ... | @@ -212,7 +190,7 @@ public class MtasCQLParserSentencePartCondition { |
| 212 | 190 | sentence.addSentenceAsFirstOption(firstSentence); |
| 213 | 191 | } |
| 214 | 192 | fullCondition = sentence; |
| 215 | - } | |
| 193 | + } | |
| 216 | 194 | return fullCondition; |
| 217 | 195 | } |
| 218 | 196 | } else { |
| ... | ... |
src/mtas/search/spans/MtasSpanRecurrenceSpans.java
| ... | ... | @@ -287,7 +287,7 @@ public class MtasSpanRecurrenceSpans extends Spans implements MtasSpans { |
| 287 | 287 | private void findMatches(Match match, int n) throws IOException { |
| 288 | 288 | if (n > 0) { |
| 289 | 289 | int largestMatchingEndPosition = match.endPosition(); |
| 290 | - HashSet<Integer> list = ignoreItem.getFullList(spans.docID(), match.endPosition()); | |
| 290 | + HashSet<Integer> list = ignoreItem.getFullEndPositionList(spans.docID(), match.endPosition()); | |
| 291 | 291 | // try to find matches with existing queue |
| 292 | 292 | if (!queueSpans.isEmpty()) { |
| 293 | 293 | Match span; |
| ... | ... | @@ -329,7 +329,7 @@ public class MtasSpanRecurrenceSpans extends Spans implements MtasSpans { |
| 329 | 329 | private List<Match> expandWithIgnoreItem(int docId, Match match) { |
| 330 | 330 | List<Match> list = new ArrayList<Match>(); |
| 331 | 331 | try { |
| 332 | - HashSet<Integer> ignoreList = ignoreItem.getFullList(docId, | |
| 332 | + HashSet<Integer> ignoreList = ignoreItem.getFullEndPositionList(docId, | |
| 333 | 333 | match.endPosition); |
| 334 | 334 | if (ignoreList != null) { |
| 335 | 335 | for (Integer endPosition : ignoreList) { |
| ... | ... |
src/mtas/search/spans/MtasSpanSequenceItem.java
src/mtas/search/spans/MtasSpanSequenceSpans.java
| ... | ... | @@ -345,7 +345,7 @@ public class MtasSpanSequenceSpans extends Spans implements MtasSpans { |
| 345 | 345 | return false; |
| 346 | 346 | // try to find matches |
| 347 | 347 | } else { |
| 348 | - // submatches: try to build matches while collecting | |
| 348 | + // subMatches: try to build matches while collecting | |
| 349 | 349 | Integer subMatchesStartPosition = null; |
| 350 | 350 | Boolean subMatchesOptional = true; |
| 351 | 351 | List<Match> subMatchesQueue = new ArrayList<Match>(); |
| ... | ... | @@ -379,7 +379,7 @@ public class MtasSpanSequenceSpans extends Spans implements MtasSpans { |
| 379 | 379 | minStartPositionNext = (minStartPositionNext == null) |
| 380 | 380 | ? queueSpans.get(j).lowestPosition |
| 381 | 381 | : Math.min(minStartPositionNext, |
| 382 | - queueSpans.get(j).lowestPosition); | |
| 382 | + queueSpans.get(j).lowestPosition); | |
| 383 | 383 | // computing restrictions not possible |
| 384 | 384 | } else { |
| 385 | 385 | minStartPositionNext = null; |
| ... | ... | @@ -628,7 +628,7 @@ public class MtasSpanSequenceSpans extends Spans implements MtasSpans { |
| 628 | 628 | } else if (!subMatchesOptional && !item.sequenceSpans.optional) { |
| 629 | 629 | if (item.filledPosition) { |
| 630 | 630 | for (Match m : subMatchesQueue) { |
| 631 | - HashSet<Integer> ignoreList = ignoreItem.getFullList(docId, | |
| 631 | + HashSet<Integer> ignoreList = ignoreItem.getFullEndPositionList(docId, | |
| 632 | 632 | m.endPosition); |
| 633 | 633 | Integer[] checkList; |
| 634 | 634 | if (ignoreList == null) { |
| ... | ... | @@ -706,7 +706,7 @@ public class MtasSpanSequenceSpans extends Spans implements MtasSpans { |
| 706 | 706 | } else { |
| 707 | 707 | newEndPosition = item.sequenceSpans.spans.endPosition(); |
| 708 | 708 | if ((minEndPosition == null) || (newEndPosition >= minEndPosition |
| 709 | - - ignoreItem.getMaxSize(docId, newEndPosition))) { | |
| 709 | + - ignoreItem.getMinStartPosition(docId, newEndPosition))) { | |
| 710 | 710 | item.add(newStartPosition, newEndPosition); |
| 711 | 711 | if (firstRetrievedPosition == null) { |
| 712 | 712 | firstRetrievedPosition = newStartPosition; |
| ... | ... |
src/mtas/search/spans/util/MtasIgnoreItem.java
| ... | ... | @@ -30,17 +30,20 @@ public class MtasIgnoreItem { |
| 30 | 30 | int maximumIgnoreLength; |
| 31 | 31 | |
| 32 | 32 | /** The base list. */ |
| 33 | - HashMap<Integer, HashSet<Integer>> baseList; | |
| 33 | + HashMap<Integer, HashSet<Integer>> baseStartPositionList; | |
| 34 | + HashMap<Integer, HashSet<Integer>> baseEndPositionList; | |
| 34 | 35 | |
| 35 | 36 | /** The full list. */ |
| 36 | - HashMap<Integer, HashSet<Integer>> fullList; | |
| 37 | + HashMap<Integer, HashSet<Integer>> fullEndPositionList; | |
| 37 | 38 | |
| 38 | 39 | /** The max base end position. */ |
| 40 | + HashMap<Integer, Integer> minBaseStartPosition; | |
| 39 | 41 | HashMap<Integer, Integer> maxBaseEndPosition; |
| 40 | 42 | |
| 41 | 43 | /** The max full end position. */ |
| 42 | - HashMap<Integer, Integer> maxFullEndPosition; | |
| 43 | - | |
| 44 | + HashMap<Integer, Integer> minFullStartPosition; | |
| 45 | +HashMap<Integer, Integer> maxFullEndPosition; | |
| 46 | + | |
| 44 | 47 | /** |
| 45 | 48 | * Instantiates a new mtas ignore item. |
| 46 | 49 | * |
| ... | ... | @@ -52,9 +55,12 @@ public class MtasIgnoreItem { |
| 52 | 55 | currentDocId = -1; |
| 53 | 56 | currentPosition = -1; |
| 54 | 57 | minimumPosition = -1; |
| 55 | - baseList = new HashMap<Integer, HashSet<Integer>>(); | |
| 56 | - fullList = new HashMap<Integer, HashSet<Integer>>(); | |
| 58 | + baseStartPositionList = new HashMap<Integer, HashSet<Integer>>(); | |
| 59 | + baseEndPositionList = new HashMap<Integer, HashSet<Integer>>(); | |
| 60 | + fullEndPositionList = new HashMap<Integer, HashSet<Integer>>(); | |
| 61 | + minBaseStartPosition = new HashMap<Integer, Integer>(); | |
| 57 | 62 | maxBaseEndPosition = new HashMap<Integer, Integer>(); |
| 63 | + minFullStartPosition = new HashMap<Integer, Integer>(); | |
| 58 | 64 | maxFullEndPosition = new HashMap<Integer, Integer>(); |
| 59 | 65 | if (maximumIgnoreLength == null) { |
| 60 | 66 | this.maximumIgnoreLength = DEFAULT_MAXIMUM_IGNORE_LENGTH; |
| ... | ... | @@ -76,10 +82,10 @@ public class MtasIgnoreItem { |
| 76 | 82 | } else if (currentDocId == docId) { |
| 77 | 83 | return true; |
| 78 | 84 | } else { |
| 79 | - baseList.clear(); | |
| 80 | - fullList.clear(); | |
| 85 | + baseEndPositionList.clear(); | |
| 86 | + fullEndPositionList.clear(); | |
| 81 | 87 | maxBaseEndPosition.clear(); |
| 82 | - maxFullEndPosition.clear(); | |
| 88 | + minFullStartPosition.clear(); | |
| 83 | 89 | if (currentDocId < docId) { |
| 84 | 90 | currentDocId = ignoreSpans.advance(docId); |
| 85 | 91 | currentPosition = -1; |
| ... | ... | @@ -97,15 +103,33 @@ public class MtasIgnoreItem { |
| 97 | 103 | * @return the max size |
| 98 | 104 | * @throws IOException Signals that an I/O exception has occurred. |
| 99 | 105 | */ |
| 100 | - public int getMaxSize(int docId, int position) throws IOException { | |
| 106 | + public int getMinStartPosition(int docId, int position) throws IOException { | |
| 107 | + if (ignoreSpans != null && docId == currentDocId) { | |
| 108 | + if (position < minimumPosition) { | |
| 109 | + throw new IOException( | |
| 110 | + "Unexpected position, should be >= " + minimumPosition + "!"); | |
| 111 | + } else { | |
| 112 | + computeFullStartPositionMinimum(position); | |
| 113 | + if(minFullStartPosition.containsKey(position)) { | |
| 114 | + return minFullStartPosition.get(position); | |
| 115 | + } else { | |
| 116 | + return 0; | |
| 117 | + } | |
| 118 | + } | |
| 119 | + } else { | |
| 120 | + return 0; | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 124 | + public int getMaxEndPosition(int docId, int position) throws IOException { | |
| 101 | 125 | if (ignoreSpans != null && docId == currentDocId) { |
| 102 | 126 | if (position < minimumPosition) { |
| 103 | 127 | throw new IOException( |
| 104 | 128 | "Unexpected position, should be >= " + minimumPosition + "!"); |
| 105 | 129 | } |
| 106 | - moveTo(position); | |
| 107 | - if (maxBaseEndPosition.containsKey(position)) { | |
| 108 | - return maxBaseEndPosition.get(position).intValue() - position; | |
| 130 | + computeFullEndPositionList(position); | |
| 131 | + if(maxFullEndPosition.containsKey(position)) { | |
| 132 | + return maxFullEndPosition.get(position); | |
| 109 | 133 | } else { |
| 110 | 134 | return 0; |
| 111 | 135 | } |
| ... | ... | @@ -122,20 +146,45 @@ public class MtasIgnoreItem { |
| 122 | 146 | * @return the full list |
| 123 | 147 | * @throws IOException Signals that an I/O exception has occurred. |
| 124 | 148 | */ |
| 125 | - public HashSet<Integer> getFullList(int docId, int position) | |
| 149 | + public HashSet<Integer> getFullEndPositionList(int docId, int position) | |
| 126 | 150 | throws IOException { |
| 127 | 151 | if (ignoreSpans != null && docId == currentDocId) { |
| 128 | 152 | if (position < minimumPosition) { |
| 129 | 153 | throw new IOException( |
| 130 | 154 | "Unexpected startPosition, should be >= " + minimumPosition + "!"); |
| 131 | 155 | } else { |
| 132 | - computeFullList(position); | |
| 133 | - return fullList.get(position); | |
| 156 | + computeFullEndPositionList(position); | |
| 157 | + return fullEndPositionList.get(position); | |
| 134 | 158 | } |
| 135 | 159 | } else { |
| 136 | 160 | return null; |
| 137 | 161 | } |
| 138 | 162 | } |
| 163 | + | |
| 164 | + private void computeFullStartPositionMinimum(int position) throws IOException { | |
| 165 | + if (ignoreSpans != null && !minFullStartPosition.containsKey(position)) { | |
| 166 | + HashSet<Integer> list = baseStartPositionList.get(position); | |
| 167 | + HashSet<Integer> newList = new HashSet<Integer>(); | |
| 168 | + int minimumStartPosition = position; | |
| 169 | + while(list!=null && !list.isEmpty()) { | |
| 170 | + newList.clear(); | |
| 171 | + for(int startPosition : list) { | |
| 172 | + if(minFullStartPosition.containsKey(startPosition)) { | |
| 173 | + minimumStartPosition = Math.min(minimumStartPosition, minFullStartPosition.get(startPosition)); | |
| 174 | + } else if(baseStartPositionList.containsKey(startPosition)) { | |
| 175 | + newList.addAll(baseStartPositionList.get(startPosition)); | |
| 176 | + } else { | |
| 177 | + if(startPosition<minimumStartPosition) { | |
| 178 | + minimumStartPosition = startPosition; | |
| 179 | + } | |
| 180 | + } | |
| 181 | + } | |
| 182 | + list.clear(); | |
| 183 | + list.addAll(newList); | |
| 184 | + } | |
| 185 | + minFullStartPosition.put(position, minimumStartPosition); | |
| 186 | + } | |
| 187 | + } | |
| 139 | 188 | |
| 140 | 189 | /** |
| 141 | 190 | * Compute full list. |
| ... | ... | @@ -143,11 +192,11 @@ public class MtasIgnoreItem { |
| 143 | 192 | * @param position the position |
| 144 | 193 | * @throws IOException Signals that an I/O exception has occurred. |
| 145 | 194 | */ |
| 146 | - private void computeFullList(int position) throws IOException { | |
| 147 | - if (ignoreSpans != null && !fullList.containsKey(position)) { | |
| 195 | + private void computeFullEndPositionList(int position) throws IOException { | |
| 196 | + if (ignoreSpans != null && !fullEndPositionList.containsKey(position)) { | |
| 148 | 197 | // initial fill |
| 149 | 198 | moveTo(position); |
| 150 | - HashSet<Integer> list = baseList.get(position); | |
| 199 | + HashSet<Integer> list = baseEndPositionList.get(position); | |
| 151 | 200 | if (list != null && !list.isEmpty()) { |
| 152 | 201 | int maxEndPosition = maxBaseEndPosition.get(position); |
| 153 | 202 | HashSet<Integer> checkList = new HashSet<Integer>(); |
| ... | ... | @@ -162,17 +211,17 @@ public class MtasIgnoreItem { |
| 162 | 211 | + maximumIgnoreLength); |
| 163 | 212 | } else { |
| 164 | 213 | for (Integer checkItem : checkList) { |
| 165 | - if (fullList.get(checkItem) != null) { | |
| 166 | - list.addAll(fullList.get(checkItem)); | |
| 214 | + if (fullEndPositionList.get(checkItem) != null) { | |
| 215 | + list.addAll(fullEndPositionList.get(checkItem)); | |
| 167 | 216 | maxEndPosition = Math.max(maxEndPosition, |
| 168 | 217 | maxFullEndPosition.get(checkItem)); |
| 169 | 218 | } else { |
| 170 | 219 | moveTo(checkItem); |
| 171 | - if (baseList.containsKey(checkItem)) { | |
| 172 | - list.addAll(baseList.get(checkItem)); | |
| 220 | + if (baseEndPositionList.containsKey(checkItem)) { | |
| 221 | + list.addAll(baseEndPositionList.get(checkItem)); | |
| 173 | 222 | maxEndPosition = Math.max(maxEndPosition, |
| 174 | 223 | maxBaseEndPosition.get(checkItem)); |
| 175 | - subCheckList.addAll(baseList.get(checkItem)); | |
| 224 | + subCheckList.addAll(baseEndPositionList.get(checkItem)); | |
| 176 | 225 | } else { |
| 177 | 226 | // ready for checkItem |
| 178 | 227 | } |
| ... | ... | @@ -184,10 +233,10 @@ public class MtasIgnoreItem { |
| 184 | 233 | depth++; |
| 185 | 234 | } |
| 186 | 235 | } |
| 187 | - fullList.put(position, list); | |
| 236 | + fullEndPositionList.put(position, list); | |
| 188 | 237 | maxFullEndPosition.put(position, (maxEndPosition - position)); |
| 189 | 238 | } else { |
| 190 | - fullList.put(position, null); | |
| 239 | + fullEndPositionList.put(position, null); | |
| 191 | 240 | maxFullEndPosition.put(position, 0); |
| 192 | 241 | } |
| 193 | 242 | } |
| ... | ... | @@ -204,14 +253,24 @@ public class MtasIgnoreItem { |
| 204 | 253 | currentPosition = ignoreSpans.nextStartPosition(); |
| 205 | 254 | if (currentPosition != Spans.NO_MORE_POSITIONS |
| 206 | 255 | && currentPosition >= minimumPosition) { |
| 207 | - if (!baseList.containsKey(currentPosition)) { | |
| 208 | - baseList.put(currentPosition, new HashSet<Integer>()); | |
| 256 | + if (!baseEndPositionList.containsKey(currentPosition)) { | |
| 257 | + baseEndPositionList.put(currentPosition, new HashSet<Integer>()); | |
| 209 | 258 | maxBaseEndPosition.put(currentPosition, currentPosition); |
| 259 | + } else { | |
| 260 | + maxBaseEndPosition.put(currentPosition, | |
| 261 | + Math.max(maxBaseEndPosition.get(currentPosition), | |
| 262 | + ignoreSpans.endPosition())); | |
| 263 | + } | |
| 264 | + if (!baseStartPositionList.containsKey(ignoreSpans.endPosition())) { | |
| 265 | + baseStartPositionList.put(ignoreSpans.endPosition(), new HashSet<Integer>()); | |
| 266 | + minBaseStartPosition.put(ignoreSpans.endPosition(), ignoreSpans.endPosition()); | |
| 267 | + } else { | |
| 268 | + minBaseStartPosition.put(ignoreSpans.endPosition(), | |
| 269 | + Math.min(minBaseStartPosition.get(ignoreSpans.endPosition()), | |
| 270 | + currentPosition)); | |
| 210 | 271 | } |
| 211 | - baseList.get(currentPosition).add(ignoreSpans.endPosition()); | |
| 212 | - maxBaseEndPosition.put(currentPosition, | |
| 213 | - Math.max(maxBaseEndPosition.get(currentPosition), | |
| 214 | - ignoreSpans.endPosition())); | |
| 272 | + baseStartPositionList.get(ignoreSpans.endPosition()).add(currentPosition); | |
| 273 | + baseEndPositionList.get(currentPosition).add(ignoreSpans.endPosition()); | |
| 215 | 274 | } |
| 216 | 275 | } catch (IOException e) { |
| 217 | 276 | currentPosition = Spans.NO_MORE_POSITIONS; |
| ... | ... | @@ -228,12 +287,17 @@ public class MtasIgnoreItem { |
| 228 | 287 | */ |
| 229 | 288 | public void removeBefore(int docId, int position) { |
| 230 | 289 | if (ignoreSpans != null && docId == currentDocId) { |
| 231 | - baseList.entrySet().removeIf(entry -> entry.getKey() < position); | |
| 232 | - fullList.entrySet().removeIf(entry -> entry.getKey() < position); | |
| 233 | - maxBaseEndPosition.entrySet() | |
| 290 | + baseStartPositionList.entrySet().removeIf(entry -> entry.getKey() < position); | |
| 291 | + baseEndPositionList.entrySet().removeIf(entry -> entry.getKey() < position); | |
| 292 | + fullEndPositionList.entrySet().removeIf(entry -> entry.getKey() < position); | |
| 293 | + minBaseStartPosition.entrySet() | |
| 234 | 294 | .removeIf(entry -> entry.getKey() < position); |
| 295 | + maxBaseEndPosition.entrySet() | |
| 296 | + .removeIf(entry -> entry.getKey() < position); | |
| 297 | + minFullStartPosition.entrySet() | |
| 298 | + .removeIf(entry -> entry.getKey() < position); | |
| 235 | 299 | maxFullEndPosition.entrySet() |
| 236 | - .removeIf(entry -> entry.getKey() < position); | |
| 300 | + .removeIf(entry -> entry.getKey() < position); | |
| 237 | 301 | if (minimumPosition < position) { |
| 238 | 302 | minimumPosition = position; |
| 239 | 303 | } |
| ... | ... |