Example usage for weka.experiment InstanceQuery setSparseData

List of usage examples for weka.experiment InstanceQuery setSparseData

Introduction

In this page you can find the example usage for weka.experiment InstanceQuery setSparseData.

Prototype

public void setSparseData(boolean s) 

Source Link

Document

Sets whether data should be encoded as sparse instances

Usage

From source file:adams.gui.visualization.instance.InstanceExplorer.java

License:Open Source License

/**
 * pops up SQL Viewer for SQL statement.
 *//*  www .  j  a  va 2s  .  c o  m*/
public void loadDataFromDatabase() {
    InstanceQuery query;
    List<InstanceContainer> data;
    Instances dataset;
    Instance inst;
    int i;

    if (m_LoadFromDatabaseDialog == null) {
        if ((getParentFrame() != null) && (getParentFrame() instanceof JFrame))
            m_LoadFromDatabaseDialog = new SqlViewerDialog((JFrame) getParentFrame());
        else
            m_LoadFromDatabaseDialog = new SqlViewerDialog(null);
    }

    m_LoadFromDatabaseDialog.setVisible(true);
    if (m_LoadFromDatabaseDialog.getReturnValue() != JOptionPane.OK_OPTION)
        return;

    try {
        showStatus("Executing query: " + m_LoadFromDatabaseDialog.getQuery());
        query = new InstanceQuery();
        query.setDatabaseURL(m_LoadFromDatabaseDialog.getURL());
        query.setUsername(m_LoadFromDatabaseDialog.getUser());
        query.setPassword(m_LoadFromDatabaseDialog.getPassword());
        query.setQuery(m_LoadFromDatabaseDialog.getQuery());
        query.setSparseData(m_LoadFromDatabaseDialog.getGenerateSparseData());
        if (query.isConnected())
            query.disconnectFromDatabase();
        query.connectToDatabase();

        showStatus("Loading data...");
        data = new ArrayList<>();
        dataset = query.retrieveInstances();
        for (i = 0; i < dataset.numInstances(); i++) {
            inst = new Instance();
            inst.set(dataset.instance(i));
            inst.setID(dataset.relationName() + "." + i);
            data.add(getContainerManager().newContainer(inst));
            showStatus("Loading data " + (i + 1) + "/" + dataset.numInstances());
        }
        loadData(dataset, data);
    } catch (Exception e) {
        GUIHelper.showErrorMessage(this, "Failed to load data from database:\n" + Utils.throwableToString(e),
                "Database error");
    }

    showStatus("");
}

From source file:wtute.engine.AnalysisEngine.java

public AnalysisEngine() throws Exception {
    attributeList = new FastVector();
    Class.forName("com.mysql.jdbc.Driver").newInstance();

    InstanceQuery query = new InstanceQuery();
    query.setUsername("root");
    query.setPassword("");
    query.setQuery("select sentence,sentence_quality from sentences");
    //data set is sparse
    query.setSparseData(true);
    data = query.retrieveInstances();//from  ww  w.ja v a2s.c  o  m
    StringToWordVector nts = new StringToWordVector();
    nts.setInputFormat(data);
    data = Filter.useFilter(data, nts);
}