Search in sources :

Example 31 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class TestDefaultWhereClauseGenerator method setup.

@Before
public void setup() {
    initMocks(this);
    node23 = new QueryNode(23);
    node42 = new QueryNode(42);
    generator = new TestWhereClauseGenerator();
    generator.setAnnoCondition(new AnnotationConditionProvider());
}
Also used : QueryNode(annis.model.QueryNode) Before(org.junit.Before)

Example 32 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class TransitivePrecedenceOptimizerTest method testDontUseRangedPrecendenceOnSpans.

@Test
public void testDontUseRangedPrecendenceOnSpans() {
    assumeTrue(postProcessorExists);
    System.out.println("dontUseRangedPrecendenceOnSpans");
    // query to extend
    String aql = "node & node & node & #1 . #2 & #2 . #3";
    // optimizer is applied on the fly by the query anaylsis (as injected by Spring)
    QueryData data = parser.parse(aql, new LinkedList<Long>());
    assertEquals(1, data.getAlternatives().size());
    List<QueryNode> nodes = data.getAlternatives().get(0);
    assertEquals(2, nodes.get(0).getOutgoingJoins().size());
    Join j0 = nodes.get(0).getOutgoingJoins().get(0);
    Join j1 = nodes.get(0).getOutgoingJoins().get(1);
    assertTrue(j0 instanceof Precedence);
    assertTrue(j1 instanceof Precedence);
    Precedence p0 = (Precedence) j0;
    Precedence p1 = (Precedence) j1;
    assertEquals(1, p0.getMinDistance());
    assertEquals(1, p0.getMaxDistance());
    assertEquals(0, p1.getMinDistance());
    assertEquals(0, p1.getMaxDistance());
}
Also used : QueryNode(annis.model.QueryNode) Join(annis.model.Join) Precedence(annis.sqlgen.model.Precedence) Test(org.junit.Test)

Example 33 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class AqlCodeEditor method mapQueryNodes.

private TreeMap<String, Integer> mapQueryNodes(List<QueryNode> nodes) {
    TreeMap<String, Integer> result = new TreeMap<>();
    Map<Integer, TreeSet<Long>> alternative2Nodes = new HashMap<>();
    for (QueryNode n : nodes) {
        TreeSet<Long> orderedNodeSet = alternative2Nodes.get(n.getAlternativeNumber());
        if (orderedNodeSet == null) {
            orderedNodeSet = new TreeSet<>();
            alternative2Nodes.put(n.getAlternativeNumber(), orderedNodeSet);
        }
        orderedNodeSet.add(n.getId());
    }
    for (TreeSet<Long> orderedNodeSet : alternative2Nodes.values()) {
        int newID = 1;
        for (long var : orderedNodeSet) {
            result.put("" + var, newID);
            newID++;
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) TreeSet(java.util.TreeSet) QueryNode(annis.model.QueryNode)

Example 34 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class AdministrationDao method countExampleQueryNodes.

/**
 * Maps example queries to integer, which represents the amount of nodes of
 * the aql query.
 */
private void countExampleQueryNodes(List<ExampleQuery> exampleQueries) {
    for (ExampleQuery eQ : exampleQueries) {
        QueryData query = getQueryDao().parseAQL(eQ.getExampleQuery(), null);
        int count = 0;
        for (List<QueryNode> qNodes : query.getAlternatives()) {
            count += qNodes.size();
        }
        eQ.setNodes(count);
    }
}
Also used : QueryData(annis.ql.parser.QueryData) QueryNode(annis.model.QueryNode) ExampleQuery(annis.examplequeries.ExampleQuery)

Example 35 with QueryNode

use of annis.model.QueryNode in project ANNIS by korpling.

the class TestAbstractFromClauseGenerator method shouldNotUsePartitions.

@Test
public void shouldNotUsePartitions() {
    // given
    long id = uniqueLong();
    QueryNode node = new QueryNode(id);
    String table = uniqueString();
    String tableAlias = uniqueString();
    int count = 1;
    long corpusID = uniqueInt(0, Integer.MAX_VALUE);
    List<Long> corporaNonEmpty = Lists.newArrayList(corpusID);
    List<Long> multipleCorpora = Lists.newArrayList(uniqueLong(), corpusID, uniqueLong());
    List<Long> corpusEmpty = new LinkedList<>();
    Map<String, String> tableAliases = setupTableAliases(node, table, tableAlias, count);
    Map<String, Boolean> tablePartioned = new HashMap<>();
    tablePartioned.put(table, Boolean.TRUE);
    TableAccessStrategy tas = new TableAccessStrategy(node);
    tas.setTableAliases(tableAliases);
    String expected = tableAlias + " AS " + tableAlias + id;
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corpusEmpty), is(expected));
    // update the partion map to actually dis-allow partitions
    tablePartioned.put(table, Boolean.FALSE);
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corporaNonEmpty), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corpusEmpty), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, multipleCorpora), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, null), is(expected));
    // remove the entry
    tablePartioned.remove(table);
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corporaNonEmpty), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corpusEmpty), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, multipleCorpora), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, null), is(expected));
    // remove the whole object
    tas.setTablePartitioned(null);
    tablePartioned.remove(table);
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corporaNonEmpty), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, corpusEmpty), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, multipleCorpora), is(expected));
    assertThat(AbstractFromClauseGenerator.tableAliasDefinition(tas, node, table, count, null), is(expected));
}
Also used : HashMap(java.util.HashMap) QueryNode(annis.model.QueryNode) TestUtils.uniqueLong(annis.test.TestUtils.uniqueLong) TestUtils.uniqueString(annis.test.TestUtils.uniqueString) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

QueryNode (annis.model.QueryNode)67 Join (annis.model.Join)12 LinkedList (java.util.LinkedList)11 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)10 ArrayList (java.util.ArrayList)8 QueryAnnotation (annis.model.QueryAnnotation)7 Precedence (annis.sqlgen.model.Precedence)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Dominance (annis.sqlgen.model.Dominance)5 PointingRelation (annis.sqlgen.model.PointingRelation)5 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)5 TreeSet (java.util.TreeSet)5 Test (org.junit.Test)5 Identical (annis.sqlgen.model.Identical)4 LeftDominance (annis.sqlgen.model.LeftDominance)4 Near (annis.sqlgen.model.Near)4 RightDominance (annis.sqlgen.model.RightDominance)4 TestUtils.uniqueLong (annis.test.TestUtils.uniqueLong)4 QueryData (annis.ql.parser.QueryData)3