public double probabilitySpam(String m) {
List<String> words = separateSpaces(m);
BayesianNetwork network = new BayesianNetwork();
BayesianEvent spamEvent = network.createEvent("spam");
int index = 0;
for( String word: words) {
BayesianEvent event = network.createEvent(word+index);
network.createDependency(spamEvent, event);
index++;
}
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++;
}