Search in sources :

Example 1 with XdslXmlParser

use of edu.cmu.tetrad.search.XdslXmlParser in project tetrad by cmu-phil.

the class LoadBayesImXsdlXmlAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (bayesImWrapper == null) {
        throw new RuntimeException("Not a Bayes IM.");
    }
    JFileChooser chooser = getJFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.showOpenDialog(null);
    File file = chooser.getSelectedFile();
    if (file != null) {
        Preferences.userRoot().put("fileSaveLocation", file.getParent());
    }
    try {
        Builder builder = new Builder();
        Document document = builder.build(file);
        printDocument(document);
        XdslXmlParser parser = new XdslXmlParser();
        BayesIm bayesIm = parser.getBayesIm(document.getRootElement());
        System.out.println(bayesIm);
        boolean allSpecified = true;
        for (edu.cmu.tetrad.graph.Node node : bayesIm.getBayesPm().getDag().getNodes()) {
            if (node.getCenterX() == -1 || node.getCenterY() == -1) {
                allSpecified = false;
            }
        }
        if (!allSpecified) {
            GraphUtils.circleLayout(bayesIm.getBayesPm().getDag(), 200, 200, 150);
        }
        bayesImWrapper.setBayesIm(bayesIm);
        bayesImEditor.getBayesIm(bayesIm);
    } catch (ParsingException e2) {
        e2.printStackTrace();
        throw new RuntimeException("Had trouble parsing that...");
    } catch (IOException e2) {
        e2.printStackTrace();
        throw new RuntimeException("Had trouble reading the file...");
    }
}
Also used : Builder(nu.xom.Builder) IOException(java.io.IOException) Document(nu.xom.Document) XdslXmlParser(edu.cmu.tetrad.search.XdslXmlParser) BayesIm(edu.cmu.tetrad.bayes.BayesIm) ParsingException(nu.xom.ParsingException) File(java.io.File)

Aggregations

BayesIm (edu.cmu.tetrad.bayes.BayesIm)1 XdslXmlParser (edu.cmu.tetrad.search.XdslXmlParser)1 File (java.io.File)1 IOException (java.io.IOException)1 Builder (nu.xom.Builder)1 Document (nu.xom.Document)1 ParsingException (nu.xom.ParsingException)1