function p = BR_Nilsson_query(query,cc_probs)
% BR_Nilsson_query - find probability of sentence using probabilities of
%     complete conjunction set
% On input:
%     query (KB structure): query
%     cc_probs (kx1 vector): complete conjunction probabilities
% On output:
%     p (float): probability of query
% Call:
%     p = BR_Nilsson_query(query,probs);
% Author:
%     T. Henderson
%     UU
%     Fall 2018
%

num_cc = length(cc_probs);
num_vars = log2(num_cc);
query_sat = ones(1,num_cc);

for cc = 0:num_cc-1
    bits = BR_int2bits(cc,num_vars);
    query_sat(cc+1) = query_sat(cc+1)&BR_sat(query.clauses,bits);
end

p = query_sat*cc_probs;

