}
network.finalizeStructure();
//SamplingQuery query = new SamplingQuery(network);
EnumerationQuery query = new EnumerationQuery(network);
CalcProbability messageProbability = new CalcProbability(this.k);
messageProbability.addClass(SPAM_DATA.length);
messageProbability.addClass(HAM_DATA.length);
double probSpam = messageProbability.calculate(0);
spamEvent.getTable().addLine(probSpam, true);
query.defineEventType(spamEvent, EventType.Outcome);
query.setEventValue(spamEvent, true);
index = 0;
for( String word: words) {
String word2 = word+index;
BayesianEvent event = network.getEvent(word2);
event.getTable().addLine(this.spamBag.probability(word), true, true); // spam
event.getTable().addLine(this.hamBag.probability(word), true, false); // ham
query.defineEventType(event, EventType.Evidence);
query.setEventValue(event, true);
index++;
}
//query.setSampleSize(100000000);
query.execute();
return query.getProbability();
}