2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package org.ufcspa.simdecs.diagram.bn;
8 import java.util.ArrayList;
9 import java.util.Vector;
11 import unbbayes.io.xmlbif.version6.*;
12 import unbbayes.prs.Node;
13 import unbbayes.prs.bn.ProbabilisticNetwork;
14 import unbbayes.simdecs.PerguntaNodo;
19 public class BayesianNetwork {
21 public static ProbabilisticNetwork loadNetwork(String filename) throws Exception {
22 ProbabilisticNetwork bayesianNetwork = new ProbabilisticNetwork(null);
23 XMLBIFIO.loadXML(new File(filename),bayesianNetwork);
24 return bayesianNetwork;
28 public static void main(String[] args) throws Exception {
29 ProbabilisticNetwork bn = BayesianNetwork.loadNetwork("samples/headache.xml");
31 // Get bayesian network name
32 System.out.println("Network name: "+ bn.getName());
35 System.out.println("All nodes: ");
36 ArrayList<Node> nodes = bn.getNodes();
37 for (Node node: nodes){
38 System.out.println("-> " + node.getName());
41 // Get node by name and its children
42 Node facialPainNode = bn.getNode("facial_pain");
43 System.out.println("\nNode: " + facialPainNode.getName());
45 // Atenção: campos adicionados aos nodos usando unbbayes.
46 // No projeto será utilizado o armazenado pelo banco de dados.
47 // Foi incluído aqui apenas para uso temporário.
48 System.out.println("Custo: " + facialPainNode.getCustoEtapa());
49 System.out.println("Tempo: " + facialPainNode.getTempoEtapa());
51 Vector<PerguntaNodo> perguntas = facialPainNode.getPerguntas();
52 for (PerguntaNodo pergunta: perguntas) {
53 // Setting questions because it is not set in the saved net
54 pergunta.setPergunta("Minha pergunta?");
55 System.out.println("Pergunta: " + pergunta.getPergunta());
58 ArrayList<Node> childrenNodes = facialPainNode.getChildren();
59 System.out.println("Children:");
60 for (Node node: childrenNodes){
61 System.out.println("-> " + node.getName());