Commit | Line | Data |
---|---|---|
be675984 MS |
1 | /* |
2 | * To change this template, choose Tools | Templates | |
3 | * and open the template in the editor. | |
4 | */ | |
5 | package org.ufcspa.simdecs.diagram.bn; | |
6 | ||
7 | import java.io.File; | |
8 | import java.util.ArrayList; | |
9 | import java.util.Vector; | |
10 | ||
11 | import unbbayes.io.xmlbif.version6.*; | |
12 | import unbbayes.prs.Node; | |
13 | import unbbayes.prs.bn.ProbabilisticNetwork; | |
14 | import unbbayes.simdecs.PerguntaNodo; | |
15 | /** | |
16 | * | |
17 | * @author mchelem | |
18 | */ | |
19 | public class BayesianNetwork { | |
20 | ||
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; | |
25 | } | |
26 | ||
27 | /* Testing */ | |
28 | public static void main(String[] args) throws Exception { | |
29 | ProbabilisticNetwork bn = BayesianNetwork.loadNetwork("samples/headache.xml"); | |
30 | ||
31 | // Get bayesian network name | |
32 | System.out.println("Network name: "+ bn.getName()); | |
33 | ||
34 | // Get all the nodes | |
35 | System.out.println("All nodes: "); | |
36 | ArrayList<Node> nodes = bn.getNodes(); | |
37 | for (Node node: nodes){ | |
38 | System.out.println("-> " + node.getName()); | |
39 | } | |
40 | ||
41 | // Get node by name and its children | |
42 | Node facialPainNode = bn.getNode("facial_pain"); | |
43 | System.out.println("\nNode: " + facialPainNode.getName()); | |
44 | ||
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()); | |
0016f784 | 50 | |
be675984 MS |
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()); | |
56 | } | |
57 | ||
58 | ArrayList<Node> childrenNodes = facialPainNode.getChildren(); | |
59 | System.out.println("Children:"); | |
60 | for (Node node: childrenNodes){ | |
61 | System.out.println("-> " + node.getName()); | |
62 | } | |
63 | } | |
64 | ||
65 | ||
66 | } | |
67 |