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());
}
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());
}
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;
}
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);
}
}
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));
}
Aggregations