Search in sources :

Example 1 with FrequentItemSetTable

use of org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetTable in project knime-core by knime.

the class SubgroupMinerModel method createFrequentItemsetOutput.

/*
     * @return a DataTable cotaining the frequent itemsets and their support
     */
private BufferedDataTable createFrequentItemsetOutput(final ExecutionContext exec) throws CanceledExecutionException {
    List<FrequentItemSet> freqSets = m_apriori.getFrequentItemSets(FrequentItemSet.Type.valueOf(m_itemSetType.getStringValue()));
    List<FrequentItemSetRow> rows = new LinkedList<FrequentItemSetRow>();
    // iterate over set list
    int rowKeyCounter = 0;
    for (FrequentItemSet set : freqSets) {
        exec.setProgress((double) rowKeyCounter / (double) m_nrOfRows, "creating output table. Row number: " + rowKeyCounter);
        List<String> itemList = new ArrayList<String>();
        for (int i = 0; i < set.getItems().size(); i++) {
            if (i > m_maxItemSetLength.getIntValue()) {
                break;
            }
            Integer item = set.getItems().get(i);
            // for every item look at the referring column name
            String itemName;
            if (m_nameMapping != null && m_nameMapping.size() > item) {
                itemName = m_nameMapping.get(item);
            } else {
                itemName = "item" + item;
            }
            itemList.add(itemName);
        }
        // create for every set a row
        FrequentItemSetRow row = new FrequentItemSetRow(new RowKey("item set " + rowKeyCounter++), itemList, m_maxItemSetLength.getIntValue(), set.getSupport());
        rows.add(row);
    }
    DataTableSpec outSpec = createItemsetOutputSpec();
    FrequentItemSetTable result = new FrequentItemSetTable(rows, outSpec);
    result.sortBy(FrequentItemSetTable.Sorter.valueOf(m_sorter.getStringValue()));
    return exec.createBufferedDataTable(result, exec);
}
Also used : FrequentItemSetTable(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetTable) DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) ArrayList(java.util.ArrayList) FrequentItemSet(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) LinkedList(java.util.LinkedList) FrequentItemSetRow(org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetRow)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 FrequentItemSet (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSet)1 FrequentItemSetRow (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetRow)1 FrequentItemSetTable (org.knime.base.node.mine.subgroupminer.freqitemset.FrequentItemSetTable)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowKey (org.knime.core.data.RowKey)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1