Example usage for weka.gui.graphvisualizer GraphVisualizer readBIF

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

Introduction

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

Prototype

public void readBIF(InputStream instream) throws BIFFormatException 

Source Link

Document

BIF reader
Reads a graph description in XMLBIF03 from an InputStrem

Usage

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

License:Open Source License

/**
 * Creates a tree visualizer from the token.
 * //from w  w  w .j ava2s.  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:de.fub.maps.project.detector.model.inference.impl.ShowGraphAction.java

License:Open Source License

private JComponent createBayesGraph(String graphDescriptor) throws BIFFormatException {
    GraphVisualizer graphVisualizer = new GraphVisualizer();
    graphVisualizer.readBIF(graphDescriptor);
    graphVisualizer.layoutGraph();//w  w w  .j  a  v a2  s .  c om
    return graphVisualizer;
}