function bn = read_bn_file(bn_filename)
% bn_filename: name of the file containing the bayesian network
% the file should contain one node per line of the form:
%  node_string [parents] [CPT]
% returns an n by 3 cell array, one 3 cell entry for each node
%  the first cell is the label of that node as a string
%  the second cell is an array containing the indexes of the parents
%  the third cell is an array containing the cpt entries

% read in all of the data from the file
[labels, parents, cpts] = textread(bn_filename, '%s %q %q');

for(i = 1:length(labels))
    % set in the label
    bn{i,1} = labels{i};
    
    % figure out the parents
    if( strmatch(parents{i}, 'null', 'exact') )
        % this node doesn't have any parents
        bn{i,2} = {};
    else
        current = 1;
        
        temp_cell = {};
        
        % get the labels for the parents
        for( j = 1:i-1 )
            if( findstr(bn{j,1}, parents{i}) )
                temp_cell{current} = bn{j,1};
                current = current + 1;
            end
        end
    
        bn{i,2} = temp_cell;
    end
    
    % set the cpt
    bn(i,3) = {sscanf(cpts{i}, '%f')};
end