function s = BR_KB2s(KB)
% BR_KB2s - convert KB to string
% On input:
%     KB (KB structure): knowledge base
%      (k).clauses (vector): disjunction of literals
%      (k).prob (float): probability of clause
% On output:
%     s (string): conjunction of disjunction
%       not is pushed into the atoms as -<int> (no negations left)
% Call:
%     s1 = BR_KB2s(KB);
% Author:
%     T. Henderson
%     UU
%     Fall 2018
%

num_clauses = length(KB);

s = [];

for c = 1:num_clauses
    clause = KB(c).clauses;
    len_clause = length(clause);
    cs = [];
    if len_clause==1
        if clause(1)>0
            cs = ['(',num2str(clause(1)),')'];
        else
            cs = ['(~(',num2str(abs(clause(1))),'))'];
        end
    else
        if clause(1)>0
            cs = ['(',num2str(clause(1))];
        else
            cs = ['(','~(',num2str(abs(clause(1))),')'];
        end
        for d = 2:len_clause-1
            if clause(d)>0
                cs = ['(',cs,')','v','(',num2str(clause(d)),')'];
            else
                cs = ['(',cs,')','v','(~(',num2str(abs(clause(d))),'))'];
            end
        end
        if clause(end)>0
            cs = ['(',cs,')','v','(',num2str(clause(end)),')',')'];
        else
            cs = ['(',cs,')','v(~(',num2str(abs(clause(end))),')))'];
        end
    end
    if c<2
        s = [s,cs];
    else
        s = ['(',s,'^',cs,')'];
    end
end
