Search in sources :

Example 1 with Bag

use of org.apache.commons.collections.Bag in project pancm_project by xuwujing.

the class collectionsTest method bagTest.

/**
 * Bag 测试
 * 主要测试重复元素的统计
 */
@SuppressWarnings("deprecation")
private static void bagTest() {
    // 定义4种球
    Bag box = new HashBag(Arrays.asList("red", "blue", "black", "green"));
    // box.getCount():1
    System.out.println("box.getCount():" + box.getCount("red"));
    // 红色的球增加五个
    box.add("red", 5);
    // box.size():9
    System.out.println("box.size():" + box.size());
    // box.getCount():6
    System.out.println("box.getCount():" + box.getCount("red"));
}
Also used : HashBag(org.apache.commons.collections.HashBag) HashBag(org.apache.commons.collections.HashBag) Bag(org.apache.commons.collections.Bag)

Example 2 with Bag

use of org.apache.commons.collections.Bag in project pancm_project by xuwujing.

the class commonsTest method bagTest.

/**
 * Bag 测试
 * 主要测试重复元素的统计
 */
@SuppressWarnings("deprecation")
private static void bagTest() {
    // 定义4种球
    Bag box = new HashBag(Arrays.asList("red", "blue", "black", "green"));
    // box.getCount():1
    System.out.println("box.getCount():" + box.getCount("red"));
    // 红色的球增加五个
    box.add("red", 5);
    // box.size():9
    System.out.println("box.size():" + box.size());
    // box.getCount():6
    System.out.println("box.getCount():" + box.getCount("red"));
}
Also used : HashBag(org.apache.commons.collections.HashBag) HashBag(org.apache.commons.collections.HashBag) Bag(org.apache.commons.collections.Bag)

Example 3 with Bag

use of org.apache.commons.collections.Bag in project ANNIS by korpling.

the class TableAccessStrategy method computeSourceTables.

protected static Bag computeSourceTables(QueryNode node, Map<String, String> tableAliases) {
    Bag tables = new HashBag();
    // hack to support table selections for ANNOTATE query
    if (node == null) {
        String[] tableNames = { NODE_TABLE, RANK_TABLE, COMPONENT_TABLE, NODE_ANNOTATION_TABLE, EDGE_ANNOTATION_TABLE };
        for (String table : tableNames) tables.add(table);
        return tables;
    }
    tables.add(tableName(tableAliases, NODE_ANNOTATION_TABLE), node.getNodeAnnotations().size());
    if (node.getNodeAnnotations().isEmpty() && node.getNodeAnnotations().size() > 0)
        tables.add(tableName(tableAliases, NODE_ANNOTATION_TABLE));
    tables.add(tableName(tableAliases, EDGE_ANNOTATION_TABLE), node.getEdgeAnnotations().size());
    if (tables.getCount(tableName(tableAliases, RANK_TABLE)) == 0 && usesRankTable(node))
        tables.add(tableName(tableAliases, RANK_TABLE));
    if (tables.getCount(tableName(tableAliases, COMPONENT_TABLE)) == 0 && usesRankTable(node))
        tables.add(tableName(tableAliases, COMPONENT_TABLE));
    if (tables.getCount(tableName(tableAliases, NODE_TABLE)) == 0)
        tables.add(tableName(tableAliases, NODE_TABLE));
    return tables;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag)

Example 4 with Bag

use of org.apache.commons.collections.Bag in project ANNIS by korpling.

the class TestAbstractFromClauseGenerator method setupTableAliases.

// set up table access strategy to return the requested table alias
// simulate that count copies of the table (alias) are required
private Map<String, String> setupTableAliases(QueryNode node, String table, String tableAlias, int count) {
    HashMap<String, String> tableAliases = new HashMap<>();
    tableAliases.put(table, tableAlias);
    if (count > 0) {
        tableAliases.put(TableAccessStrategy.NODE_ANNOTATION_TABLE, tableAlias);
    }
    for (int i = 0; i < count; i++) {
        // this will add new entries for the source tables
        node.addNodeAnnotation(new QueryAnnotation("dummy", "dummy" + i));
    }
    tableAccessStrategy.setTableAliases(tableAliases);
    tableAccessStrategy.setNode(node);
    Bag tables = new HashBag();
    tables.add(tableAlias, count);
    given(tableAccessStrategy.computeSourceTables()).willReturn(tables);
    return tableAliases;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) HashMap(java.util.HashMap) QueryAnnotation(annis.model.QueryAnnotation) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag) TestUtils.uniqueString(annis.test.TestUtils.uniqueString)

Example 5 with Bag

use of org.apache.commons.collections.Bag in project ANNIS by korpling.

the class TableAccessStrategy method aliasedTable.

public String aliasedTable(String table, int count) {
    if (node != null) {
        // throw new IllegalArgumentException("access to node annotation table out of range: " + count);
        if (table.equals(EDGE_ANNOTATION_TABLE) && count > node.getEdgeAnnotations().size())
            throw new IllegalArgumentException("access to edge annotation table out of range: " + count);
        if (table.equals(NODE_TABLE) && count > 1)
            throw new IllegalArgumentException("access to struct table out of range: " + count);
        if (table.equals(RANK_TABLE) && count > 1)
            throw new IllegalArgumentException("access to rank table out of range: " + count);
        // offset table count for edge annotations if node and edge annotations are the same table
        if (table.equals(EDGE_ANNOTATION_TABLE) && isMaterialized(EDGE_ANNOTATION_TABLE, NODE_ANNOTATION_TABLE))
            count = count + node.getNodeAnnotations().size() - 1;
    }
    if (count == 0) {
        count = 1;
    }
    // compute table counts
    Bag tables = computeSourceTables(node, tableAliases);
    String aliasedName = tableName(table);
    String aliasCount = node != null ? String.valueOf(node.getId()) : "";
    String countSuffix = tables.getCount(aliasedName) > 1 ? "_" + count : "";
    return aliasedName + aliasCount + countSuffix;
}
Also used : Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag)

Aggregations

Bag (org.apache.commons.collections.Bag)8 HashBag (org.apache.commons.collections.bag.HashBag)6 HashMap (java.util.HashMap)2 HashBag (org.apache.commons.collections.HashBag)2 QueryAnnotation (annis.model.QueryAnnotation)1 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)1 Map (java.util.Map)1