/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.ufcspa.simdecs.diagram.bn; import java.io.File; import java.util.ArrayList; import java.util.Vector; import unbbayes.io.xmlbif.version6.*; import unbbayes.prs.Node; import unbbayes.prs.bn.ProbabilisticNetwork; import unbbayes.simdecs.PerguntaNodo; /** * * @author mchelem */ public class BayesianNetwork { public static ProbabilisticNetwork loadNetwork(String filename) throws Exception { ProbabilisticNetwork bayesianNetwork = new ProbabilisticNetwork(null); XMLBIFIO.loadXML(new File(filename),bayesianNetwork); return bayesianNetwork; } /* Testing */ public static void main(String[] args) throws Exception { ProbabilisticNetwork bn = BayesianNetwork.loadNetwork("samples/headache.xml"); // Get bayesian network name System.out.println("Network name: "+ bn.getName()); // Get all the nodes System.out.println("All nodes: "); ArrayList nodes = bn.getNodes(); for (Node node: nodes){ System.out.println("-> " + node.getName()); } // Get node by name and its children Node facialPainNode = bn.getNode("facial_pain"); System.out.println("\nNode: " + facialPainNode.getName()); // Atenção: campos adicionados aos nodos usando unbbayes. // No projeto será utilizado o armazenado pelo banco de dados. // Foi incluído aqui apenas para uso temporário. System.out.println("Custo: " + facialPainNode.getCustoEtapa()); System.out.println("Tempo: " + facialPainNode.getTempoEtapa()); Vector perguntas = facialPainNode.getPerguntas(); for (PerguntaNodo pergunta: perguntas) { // Setting questions because it is not set in the saved net pergunta.setPergunta("Minha pergunta?"); System.out.println("Pergunta: " + pergunta.getPergunta()); } ArrayList childrenNodes = facialPainNode.getChildren(); System.out.println("Children:"); for (Node node: childrenNodes){ System.out.println("-> " + node.getName()); } } }