Example usage for weka.gui.graphvisualizer GraphVisualizer readDOT

List of usage examples for weka.gui.graphvisualizer GraphVisualizer readDOT

Introduction

In this page you can find the example usage for weka.gui.graphvisualizer GraphVisualizer readDOT.

Prototype

public void readDOT(Reader input) 

Source Link

Document

Dot reader
Reads a graph description in DOT format from a string

Usage

From source file:adams.flow.sink.WekaGraphVisualizer.java

License:Open Source License

/**
 * Creates a tree visualizer from the token.
 * //from   www .  j a va  2s . c  o  m
 * @param token   the input
 * @return      the tree visualizer or null in case of an error
 */
protected GraphVisualizer createGraphVisualizer(Token token) {
    GraphVisualizer result;
    String filename;
    String graph;
    Reader reader;
    InputStream stream;
    Object input;

    result = null;

    reader = null;
    stream = null;
    try {
        input = token.getPayload();
        if (input instanceof WekaModelContainer)
            input = ((WekaModelContainer) input).getValue(WekaModelContainer.VALUE_MODEL);

        filename = null;
        graph = null;
        if (input instanceof String) {
            filename = (String) input;
        } else if (input instanceof File) {
            filename = ((File) input).getAbsolutePath();
        } else {
            if (((Drawable) input).graphType() != Drawable.BayesNet)
                throw new IllegalArgumentException(
                        token.getPayload().getClass().getName() + " does not generate a BayesNet graph!");
            graph = ((Drawable) input).graph();
        }

        result = new GraphVisualizer();

        if (filename != null) {
            if (filename.toLowerCase().endsWith(".xml") || filename.toLowerCase().endsWith(".bif")) {
                stream = new FileInputStream(filename);
                result.readBIF(stream);
            } else {
                reader = new FileReader(filename);
                result.readDOT(reader);
            }
        } else if (graph != null) {
            result.readBIF(graph);
        }
    } catch (Exception e) {
        handleException("Failed to read input!", e);
        return result;
    } finally {
        FileUtils.closeQuietly(reader);
        FileUtils.closeQuietly(stream);
    }

    return result;
}

From source file:meka.gui.explorer.classify.ShowGraphs.java

License:Open Source License

/**
 * Returns the action lister to use in the menu.
 *
 * @param history   the current history/*from  www . j  a v a  2 s . c o  m*/
 * @param index     the selected history item
 * @return          the listener
 */
@Override
public ActionListener getActionListener(final ResultHistoryList history, final int index) {
    final MultiLabelDrawable d = (MultiLabelDrawable) getClassifier(history, index);

    return new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Map<Integer, String> graphs;
            Map<Integer, Integer> types;
            java.util.List<Integer> keys;
            try {
                types = d.graphType();
                graphs = d.graph();
                keys = new ArrayList<Integer>(types.keySet());
            } catch (Exception ex) {
                System.err.println("Failed to obtain graph(s):");
                ex.printStackTrace();
                return;
            }
            JDialog dialog = new JDialog((Frame) null, history.getSuffixAt(index), false);
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            JTabbedPane tabbed = new JTabbedPane();
            dialog.getContentPane().setLayout(new BorderLayout());
            dialog.getContentPane().add(tabbed, BorderLayout.CENTER);
            for (Integer label : keys) {
                int type = types.get(label);
                JComponent comp = null;
                switch (type) {
                case MultiLabelDrawable.TREE:
                    TreeBuild b = new TreeBuild();
                    PlaceNode2 arrange = new PlaceNode2();
                    Node top = b.create(new StringReader(graphs.get(label)));
                    comp = new TreeVisualizer(null, top, arrange);
                    break;
                case MultiLabelDrawable.BayesNet:
                    GraphVisualizer g = new GraphVisualizer();
                    g.readDOT(new StringReader(graphs.get(label)));
                    comp = g;
                    break;
                default:
                    System.err.println("Unsupported graph type for label " + label + ": " + type);
                }
                if (comp != null)
                    tabbed.addTab("" + label, comp);
            }
            dialog.setSize(800, 600);
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
        }
    };
}