Skip to content
Snippets Groups Projects
Commit 34c494b0 authored by Lukas Kettenbach's avatar Lukas Kettenbach
Browse files

XMLBIF import (done) export (beta)

parent 83259b31
Branches
Tags
No related merge requests found
<?xml version="1.0" encoding="US-ASCII"?>
<!--
Bayesian network in XMLBIF v0.3 (BayesNet Interchange Format)
Produced by SamIam http://reasoning.cs.ucla.edu/samiam
Output created Mar 21, 2013 5:30:08 PM
-->
<BIF VERSION="0.3">
<NETWORK>
<NAME>bayesiannetwork</NAME>
<VARIABLE TYPE="nature">
<NAME>variable2</NAME>
<OUTCOME>state0</OUTCOME>
<OUTCOME>state1</OUTCOME>
<PROPERTY>position = (346, -116)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>variable5</NAME>
<OUTCOME>state0</OUTCOME>
<OUTCOME>state1</OUTCOME>
<PROPERTY>position = (328, -31)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>variable4</NAME>
<OUTCOME>state0</OUTCOME>
<OUTCOME>state1</OUTCOME>
<PROPERTY>position = (7, -159)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>variable3</NAME>
<OUTCOME>state0</OUTCOME>
<OUTCOME>state1</OUTCOME>
<PROPERTY>position = (146, -228)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>variable1</NAME>
<OUTCOME>state0</OUTCOME>
<OUTCOME>state1</OUTCOME>
<PROPERTY>position = (357, -231)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>variable0</NAME>
<OUTCOME>state0</OUTCOME>
<OUTCOME>state1</OUTCOME>
<PROPERTY>position = (131, -95)</PROPERTY>
</VARIABLE>
<DEFINITION>
<FOR>variable2</FOR>
<TABLE>0.2 0.8 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>variable5</FOR>
<TABLE>0.1 0.9 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>variable4</FOR>
<TABLE>0.5 0.5 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>variable3</FOR>
<TABLE>0.5 0.5 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>variable1</FOR>
<TABLE>0.5 0.5 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>variable0</FOR>
<GIVEN>variable5</GIVEN>
<GIVEN>variable2</GIVEN>
<GIVEN>variable1</GIVEN>
<GIVEN>variable3</GIVEN>
<GIVEN>variable4</GIVEN>
<TABLE>0.1 0.9 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 </TABLE>
</DEFINITION>
</NETWORK>
</BIF>
<?xml version="1.0" encoding="US-ASCII"?>
<!--
Bayesian network in XMLBIF v0.3 (BayesNet Interchange Format)
Produced by SamIam http://reasoning.cs.ucla.edu/samiam
Output created Mar 21, 2013 5:30:08 PM
-->
<BIF VERSION="0.3">
<NETWORK>
<NAME>BN_Weather_IceCream</NAME>
<VARIABLE TYPE="nature">
<NAME>Weather0</NAME>
<OUTCOME>Sun</OUTCOME>
<OUTCOME>Rain</OUTCOME>
<PROPERTY>position = (150, 100)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>Ice_Cream_Eaten</NAME>
<OUTCOME>True</OUTCOME>
<OUTCOME>False</OUTCOME>
<PROPERTY>position = (150, 300)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>Weather</NAME>
<OUTCOME>Sun</OUTCOME>
<OUTCOME>Rain</OUTCOME>
<PROPERTY>position = (150, 200)</PROPERTY>
</VARIABLE>
<DEFINITION>
<FOR>Weather0</FOR>
<TABLE>0.6 0.4 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>Ice_Cream_Eaten</FOR>
<GIVEN>Weather</GIVEN>
<TABLE>0.9 0.1 0.2 0.8 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>Weather</FOR>
<GIVEN>Weather0</GIVEN>
<TABLE>0.7 0.3 0.5 0.5 </TABLE>
</DEFINITION>
</NETWORK>
</BIF>
<?xml version="1.0" ?>
<BIF VERSION="0.3">
<NETWORK>
<NAME>tesasdasdt</NAME>
<VARIABLE TYPE="nature">
<NAME>IceCreameaten</NAME>
<PROPERTY>position = (150, 300)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>Weather</NAME>
<PROPERTY>position = (150, 200)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>Weather0</NAME>
<PROPERTY>position = (150, 100)</PROPERTY>
</VARIABLE>
</NETWORK>
</BIF>
net
{
propagationenginegenerator1791944048146838126L = "edu.ucla.belief.approx.BeliefPropagationSettings@4b942a3c";
jenginegenerator6060830225489488864L = "edu.ucla.belief.inference.JoinTreeSettings@8f3eac";
node_size = (130 55);
}
node I1
......@@ -13,23 +15,23 @@ node I1
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
node W1
node W0
{
states = ("Rain" "Sun" );
position = (374 -128);
position = (231 -125);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "W1";
label = "W0";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
node W0
node W1
{
states = ("Rain" "Sun" );
position = (231 -125);
position = (374 -128);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "W0";
label = "W1";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
......@@ -38,12 +40,12 @@ potential ( I1 | W1 )
data = (( 0.2 0.8 )
( 0.9 0.1 ));
}
potential ( W0 | )
{
data = ( 0.4 0.6 );
}
potential ( W1 | W0 )
{
data = (( 0.5 0.5 )
( 0.3 0.7 ));
}
potential ( W0 | )
{
data = ( 0.4 0.6 );
}
<?xml version="1.0"?>
<BIF VERSION="0.3">
<NETWORK>
<NAME>Unnamed network</NAME>
<VARIABLE TYPE="nature">
<NAME>W1</NAME>
<OUTCOME>Rain</OUTCOME>
<OUTCOME>Sun</OUTCOME>
<PROPERTY>position = (597, 105)</PROPERTY>
</VARIABLE>
<DEFINITION>
<FOR>W1</FOR>
<GIVEN>W0</GIVEN>
<TABLE>0.5 0.5 0.3 0.7 </TABLE>
</DEFINITION>
<VARIABLE TYPE="nature">
<NAME>W0</NAME>
<OUTCOME>Rain</OUTCOME>
<OUTCOME>Sun</OUTCOME>
<PROPERTY>position = (388, 106)</PROPERTY>
</VARIABLE>
<VARIABLE TYPE="nature">
<NAME>I1</NAME>
<OUTCOME>true</OUTCOME>
<OUTCOME>false</OUTCOME>
<PROPERTY>position = (602, 220)</PROPERTY>
</VARIABLE>
<DEFINITION>
<FOR>W0</FOR>
<TABLE>0.4 0.6 </TABLE>
</DEFINITION>
<DEFINITION>
<FOR>I1</FOR>
<GIVEN>W1</GIVEN>
<TABLE>0.2 0.8 0.9 0.1 </TABLE>
</DEFINITION>
</NETWORK>
</BIF>
net
{
propagationenginegenerator1791944048146838126L = "edu.ucla.belief.approx.BeliefPropagationSettings@41b22cc7";
jenginegenerator6060830225489488864L = "edu.ucla.belief.inference.JoinTreeSettings@75a340";
node_size = (130 55);
}
node W0
{
states = ("Rain" "Sun" );
position = (231 -125);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "W0";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
node W2
{
states = ("Rain" "Sun" );
......@@ -33,23 +25,23 @@ node I2
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
node I3
node W1
{
states = ("true" "false" );
position = (683 -215);
states = ("Rain" "Sun" );
position = (374 -128);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "I3";
label = "W1";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
node I1
node I3
{
states = ("true" "false" );
position = (429 -227);
position = (683 -215);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "I1";
label = "I3";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
......@@ -63,19 +55,25 @@ node W3
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
node W1
node I1
{
states = ("Rain" "Sun" );
position = (374 -128);
states = ("true" "false" );
position = (429 -227);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "W1";
label = "I1";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
potential ( W0 | )
node W0
{
data = ( 0.4 0.6 );
states = ("Rain" "Sun" );
position = (231 -125);
excludepolicy = "include whole CPT";
ismapvariable = "false";
label = "W0";
DSLxEXTRA_DEFINITIONxDIAGNOSIS_TYPE = "AUXILIARY";
diagnosistype = "AUXILIARY";
}
potential ( W2 | W1 )
{
......@@ -87,12 +85,12 @@ potential ( I2 | W2 )
data = (( 0.2 0.8 )
( 0.9 0.1 ));
}
potential ( I3 | W3 )
potential ( W1 | W0 )
{
data = (( 0.2 0.8 )
( 0.9 0.1 ));
data = (( 0.5 0.5 )
( 0.3 0.7 ));
}
potential ( I1 | W1 )
potential ( I3 | W3 )
{
data = (( 0.2 0.8 )
( 0.9 0.1 ));
......@@ -102,8 +100,12 @@ potential ( W3 | W2 )
data = (( 0.5 0.5 )
( 0.3 0.7 ));
}
potential ( W1 | W0 )
potential ( I1 | W1 )
{
data = (( 0.5 0.5 )
( 0.3 0.7 ));
data = (( 0.2 0.8 )
( 0.9 0.1 ));
}
potential ( W0 | )
{
data = ( 0.4 0.6 );
}
......@@ -16,7 +16,7 @@ twoTBN = TwoTBN()
weather0_init = DiscreteNode("Weather0", ["Sun", "Rain"])
weather0 = DiscreteNode("Weather0", ["Sun", "Rain"])
weather = DiscreteNode("Weather", ["Sun", "Rain"])
ice_cream_eaten = DiscreteNode("Ice Cream eaten", [True, False])
ice_cream_eaten = DiscreteNode("Ice Cream Eaten", [True, False])
B0.add_node(weather0_init)
twoTBN.add_node(weather0, True)
......@@ -29,8 +29,11 @@ twoTBN.add_edge(weather0, weather);
cpt_weather0_init = numpy.array([.6, .4])
weather0_init.set_probability_table(cpt_weather0_init, [weather0_init])
cpt_weather = numpy.array([[.7, .3],
[.5, .5]])
cpt_weather0 = numpy.array([.6, .4])
weather0.set_probability_table(cpt_weather0, [weather0])
cpt_weather = numpy.array([[.7, .5],
[.3, .5]])
weather.set_probability_table(cpt_weather, [weather0, weather])
ice_cream_eaten.set_probability(.9, [(ice_cream_eaten, True), (weather, "Sun")])
ice_cream_eaten.set_probability(.1, [(ice_cream_eaten, False), (weather, "Sun")])
......@@ -40,20 +43,27 @@ ice_cream_eaten.set_probability(.8, [(ice_cream_eaten, False), (weather, "Rain")
dbn.set_B0(B0)
dbn.set_TwoTBN(twoTBN)
from primo.utils.XMLBIF import XMLBIF
network = XMLBIF.read("BN_Weather_IceCream.xmlbif")
exit
#xmlbif = XMLBIF(dbn.get_TwoTBN(), "BN_Weather_IceCream")
#xmlbif.write("BN_Weather_IceCream.xmlbif")
N = 5000
T = 4
count = 0
def get_evidence_function():
global count
print count
global count
evidence = {}
if count == 1:
count = count + 1
return {weather:"Sun"}
evidence = {weather:"Sun"}
else:
count = count + 1
return {}
print "Time slice " + str(count) + " with evidence " + str(evidence)
return evidence
samples = pf.particle_filtering_DBN(dbn, N, T, get_evidence_function)
w_hit = 0.0
for n in samples:
......@@ -61,5 +71,5 @@ for n in samples:
#print state
if state[weather] == "Sun":
w_hit += 1
print("P(..) = " + str(w_hit / N))
\ No newline at end of file
......@@ -2,6 +2,7 @@ import networkx as nx
from primo.core import Node
class BayesNet(object):
graph = nx.DiGraph()
node_lookup = {}
......@@ -90,7 +91,7 @@ class BayesNet(object):
import matplotlib.pyplot as plt
nx.draw_circular(self.graph)
plt.show()
def draw_graphviz(self):
import matplotlib.pyplot as plt
nx.draw_graphviz(self.graph)
......@@ -138,4 +139,4 @@ class BayesNet(object):
def __len__(self):
'''Return the number of nodes in the graph.'''
return len(self.graph)
return len(self.graph)
\ No newline at end of file
import abc
import re
class Node(object):
__metaclass__ = abc.ABCMeta
name = "UninitializedName"
position = (0, 0)
def __init__(self, node_name):
self.name = node_name
# Remove all special characters and replace " " with "_"
name = re.sub(r"[^a-zA-Z_0-9 ]*", "", node_name)
self.name = name.replace(" ", "_")
@abc.abstractmethod
def announce_parent(self, node):
......
# -*- coding: utf-8 -*-
import xml.dom.minidom as minidom
from primo.core import BayesNet
from primo.core import Node
from primo.reasoning import DiscreteNode
import re
import numpy
class XMLBIF(object):
'''
This class represents the Interchange Format for Bayesian Networks (XMLBIF).
It helps you to convert a BayesNet to a XMLBIF and a XMLBIF to a BayesNet.
See: http://www.cs.cmu.edu/~fgcozman/Research/InterchangeFormat/
'''
def __init__(self, network, network_name = "Unnamed network",
encoding = "UTF-8", ndent = " ", newl = "\n",
addindent = " "):
'''
Create a new XMLBIF instance.
Keyword arguments:
network -- is a valid BayesNet that must only contain DicreteNodes.
network_name -- is some name that will be mentioned in the XMLBIF.
encoding -- encoding of the XMLBIF. Encoding other than UTF-8 is
likely incorrect, since UTF-8 is the default encoding of XML.
ndent -- specifies the indentation string and defaults to a tabulator.
newl -- specifies the string emitted at the end of each line.
addindent -- is the incremental indentation to use for subnodes of the current one
'''
self.network = network
self.network_name = network_name
self.encoding = encoding
self.ndent = ndent
self.newl = newl
self.addindent = addindent
self.root = minidom.Document()
if isinstance(network, BayesNet):
self.network = network
else:
raise Exception("Given network is not a BayesNet.")
# Create inital XMLBIF
self.generate_XMLBIF()
def __str__(self):
'''
Returns a pretty string representation of the XMLBIF.
'''
return self.root.toprettyxml(self.ndent, self.newl, self.encoding);
def write(self, filename):
'''
Write this XMLBIF instance to disk.
Keyword arguments:
filename -- is a string containing the filename.
'''
f = open(filename, "w")
self.root.writexml(f, self.ndent, self.addindent, self.newl, self.encoding)
def generate_XMLBIF(self):
'''
Generate the XMLBIF document.
This method is used internally. Do not call it outside this class.
'''
self.calculate_positions()
root_node = minidom.Document()
tag_bif = root_node.createElement("BIF")
tag_net = root_node.createElement("NETWORK")
tag_bif.setAttribute("VERSION","0.3")
root_node.appendChild(tag_bif)
tag_bif.appendChild(tag_net)
tag_name = minidom.Element("NAME")
text = minidom.Text()
text.data = str(self.network_name)
tag_name.appendChild(text)
tag_net.appendChild(tag_name)
for node_name in self.network.node_lookup:
current_node = self.network.node_lookup[node_name]
if not isinstance(current_node, DiscreteNode):
raise Exception("Node " + str(current_node) + " is not a DiscreteNode.")
node_tag = self.create_node_tag(current_node)
tag_net.appendChild(node_tag)
#Generate CPTs
for node_name in self.network.node_lookup:
current_node = self.network.node_lookup[node_name]
tag_def = minidom.Element("DEFINITION")
tag_for = minidom.Element("FOR")
txt_for = minidom.Text()
txt_for.data = node_name
tag_for.appendChild(txt_for)
tag_def.appendChild(tag_for)
for parent in reversed(self.network.graph.predecessors(current_node)):
tag_par = minidom.Element("GIVEN")
txt_par = minidom.Text()
txt_par.data = str(parent.name)
tag_par.appendChild(txt_par)
tag_def.appendChild(tag_par)
tag_cpt = minidom.Element("TABLE")
txt_cpt = minidom.Text()
txt = ""
for elem in current_node.get_cpd().get_table().T.flat:
txt += str(elem) + " "
txt_cpt.data = txt
tag_cpt.appendChild(txt_cpt)
tag_def.appendChild(tag_cpt)
tag_net.appendChild(tag_def)
self.root = root_node
return self
def create_node_tag(self, node):
'''
Create a node tag that will look like:
<VARIABLE TYPE="nature">
<NAME>node_name</NAME>
<OUTCOME>...</OUTCOME>
<OUTCOME>...</OUTCOME>
<PROPERTY>position = (x, y)</PROPERTY>
</VARIABLE>
Keyword arguments:
node -- a Node with valid name and position
Returns a XMLBIF conform "variable" tag
'''
if not isinstance(node, Node):
raise Exception("Node " + str(node) + " is not a Node.")
tag_var = minidom.Element("VARIABLE")
tag_own = minidom.Element("NAME")
tag_pos = minidom.Element("PROPERTY")
tag_var.setAttribute("TYPE", "nature")
# set node name
txt_name = minidom.Text()
txt_name.data = node.name
tag_var.appendChild(tag_own)
tag_own.appendChild(txt_name)
# set outcomes
for value in node.value_range:
tag_outcome = minidom.Element("OUTCOME")
txt_outcome = minidom.Text()
txt_outcome.data = value
tag_outcome.appendChild(txt_outcome)
tag_var.appendChild(tag_outcome)
# set position
txt_pos = minidom.Text()
x, y = node.position
txt_pos.data = "position = (" + str(x) + ", " + str(y) + ")"
tag_pos.appendChild(txt_pos)
tag_var.appendChild(tag_pos)
return tag_var
def calculate_positions(self):
'''
Calculate the visual position for each node.
This method is used internally. Do not call it outside this class.
'''
q = []
p = []
already_seen = []
x_step = 150
y_step = 100
x_pos = 0
y_pos = 0
for node_name in self.network.node_lookup:
node = self.network.node_lookup[node_name]
if len(self.network.graph.predecessors(node)) == 0:
q.append(node)
already_seen.append(node)
while q:
p = q
q = []
y_pos += y_step
x_pos = x_step
while p:
node = p.pop()
node.position = (x_pos, y_pos)
x_pos += x_step
for child in self.network.graph.successors(node):
if not child in already_seen:
q.append(child)
already_seen.append(child)
@staticmethod
def read(filename_or_file, is_string = False):
'''
Reads a XMLBIF and returns a BayesNet.
Keyword arguments:
filename_or_file -- may be either a file name, or a file-like object.
is_string -- is True if filename_or_file is a XML in a string
Returns a BayesNet.
'''
if is_string:
root = minidom.parseString(filename_or_file)
else:
root = minidom.parse(filename_or_file)
return XMLBIF.generate_BayesNet(root)
@staticmethod
def generate_BayesNet(root):
'''
Generate a BayesNet from a XMLBIF.
This method is used internally. Do not call it outside this class.
'''
network = BayesNet()
bif_nodes = root.getElementsByTagName("BIF")
if len(bif_nodes) != 1:
raise Exception("More than one or none <BIF>-tag in document.")
network_nodes = bif_nodes[0].getElementsByTagName("NETWORK")
if len(network_nodes) != 1:
raise Exception("More than one or none <NETWORK>-tag in document.")
variable_nodes = network_nodes[0].getElementsByTagName("VARIABLE")
for variable_node in variable_nodes:
name = "Unnamed node"
value_range = []
position = (0, 0)
for name_node in variable_node.getElementsByTagName("NAME"):
name = XMLBIF.get_node_text(name_node.childNodes)
break
for output_node in variable_node.getElementsByTagName("OUTCOME"):
value_range.append(XMLBIF.get_node_text(output_node.childNodes))
for position_node in variable_node.getElementsByTagName("PROPERTY"):
position = XMLBIF.get_node_position_from_text(position_node.childNodes)
break
new_node = DiscreteNode(name, value_range)
new_node.position = position
network.add_node(new_node)
definition_nodes = network_nodes[0].getElementsByTagName("DEFINITION")
for definition_node in definition_nodes:
node = None
parent_count = 0
for for_node in definition_node.getElementsByTagName("FOR"):
name = XMLBIF.get_node_text(for_node.childNodes)
node = network.get_node(name)
break
if node == None:
continue
for given_node in definition_node.getElementsByTagName("GIVEN"):
parent_name = XMLBIF.get_node_text(given_node.childNodes)
parent_node = network.get_node(parent_name)
node.announce_parent(parent_node)
parent_count += 1
for table_node in definition_node.getElementsByTagName("TABLE"):
table = XMLBIF.get_node_table_from_text(table_node.childNodes, parent_count)
return network
@staticmethod
def get_node_text(nodelist):
'''
Keyword arguments:
nodelist -- is a list of nodes (xml.dom.minidom.Node).
Returns the text of the given nodelist or a empty string.
'''
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
@staticmethod
def get_node_position_from_text(nodelist):
'''
Keyword arguments:
nodelist -- is a list of nodes (xml.dom.minidom.Node).
Returns the position of the given nodelist as pair (x, y).
'''
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
text = ''.join(rc)
number_list = re.findall(r"\d+", text)
if len(number_list) != 2:
raise Exception("Ambiguous node position in XMLBIF.")
return (number_list[0], number_list[1])
@staticmethod
def get_node_table_from_text(nodelist, parent_count):
'''
Keyword arguments:
nodelist -- is a list of nodes (xml.dom.minidom.Node).
parent_count -- is the number of parents.
Returns the probability table of the given nodelist as pair numpy.array.
'''
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
text = ''.join(rc)
number_list = re.findall(r"[0-9]*\.*[0-9]+", text)
if len(number_list)
for number in number_list:
return (number_list[0], number_list[1])
\ No newline at end of file
# -*- coding: utf-8 -*-
from XMLBIF import XMLBIF
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment