Work in progress - rough draft.
This commit is contained in:
@@ -25,7 +25,7 @@ public class FoodNetBuilder {
|
||||
public static final String TASTE = "Taste";
|
||||
|
||||
public static final String SOMEONE_VEGETARIAN = "vegetarian";
|
||||
public static final String SOMEONE_ALLERGIC_NUTS = "allergic-nuts";
|
||||
//public static final String SOMEONE_ALLERGIC_NUTS = "allergic-nuts";
|
||||
|
||||
public static final String CONTAINS_MEAT = "Meat";
|
||||
public static final String CONTAINS_VEGETABLE = "Vegetable";
|
||||
@@ -33,8 +33,8 @@ public class FoodNetBuilder {
|
||||
public static final String CONTAINS_PORK = TYPE.PORK.toString();
|
||||
public static final String CONTAINS_TOMATOS = TYPE.TOMATO.toString();
|
||||
public static final String CONTAINS_POTATOS = TYPE.POTATO.toString();
|
||||
public static final String CONTAINS_NUTS = "Nuts";
|
||||
public static final String CONTAINS_GENERIC_NUTS = TYPE.GENERIC_NUTS.toString();
|
||||
//public static final String CONTAINS_NUTS = "Nuts";
|
||||
//public static final String CONTAINS_GENERIC_NUTS = TYPE.GENERIC_NUTS.toString();
|
||||
|
||||
public static final String TRUE_VALUE = "true";
|
||||
public static final String FALSE_VALUE = "false";
|
||||
@@ -44,18 +44,18 @@ public class FoodNetBuilder {
|
||||
public static final String RATING_DOMAIN[] = { "1", "2", "3", "4", "5",
|
||||
"6", "7", "8", "9", "10" };
|
||||
|
||||
private static final String[] VARIABLES = { SOMEONE_VEGETARIAN, SOMEONE_ALLERGIC_NUTS,
|
||||
private static final String[] VARIABLES = { SOMEONE_VEGETARIAN, /*SOMEONE_ALLERGIC_NUTS,*/
|
||||
CONTAINS_BEEF, CONTAINS_MEAT, CONTAINS_PORK, CONTAINS_POTATOS,
|
||||
CONTAINS_TOMATOS, CONTAINS_VEGETABLE, CONTAINS_NUTS, CONTAINS_GENERIC_NUTS, TASTE };
|
||||
CONTAINS_TOMATOS, CONTAINS_VEGETABLE, /*CONTAINS_NUTS, CONTAINS_GENERIC_NUTS,*/ TASTE };
|
||||
|
||||
private static final String[] OBSERVED = { CONTAINS_BEEF, CONTAINS_PORK,
|
||||
CONTAINS_POTATOS, CONTAINS_TOMATOS, CONTAINS_GENERIC_NUTS};
|
||||
CONTAINS_POTATOS, CONTAINS_TOMATOS/*, CONTAINS_GENERIC_NUTS*/};
|
||||
|
||||
public static Ontology createOntology() {
|
||||
HashSet<String> classes = new HashSet<String>();
|
||||
|
||||
classes.add(CONTAINS_MEAT);
|
||||
classes.add(CONTAINS_NUTS);
|
||||
//classes.add(CONTAINS_NUTS);
|
||||
classes.add(CONTAINS_VEGETABLE);
|
||||
|
||||
Ontology ontology = new Ontology(classes);
|
||||
@@ -63,7 +63,7 @@ public class FoodNetBuilder {
|
||||
ontology.define(CONTAINS_PORK, CONTAINS_MEAT);
|
||||
ontology.define(CONTAINS_BEEF, CONTAINS_MEAT);
|
||||
|
||||
ontology.define(CONTAINS_GENERIC_NUTS, CONTAINS_NUTS);
|
||||
//ontology.define(CONTAINS_GENERIC_NUTS, CONTAINS_NUTS);
|
||||
|
||||
ontology.define(CONTAINS_TOMATOS, CONTAINS_VEGETABLE);
|
||||
ontology.define(CONTAINS_POTATOS, CONTAINS_VEGETABLE);
|
||||
@@ -125,9 +125,10 @@ public class FoodNetBuilder {
|
||||
if (ingredients.contains(TYPE.TOMATO)) {
|
||||
point.add(build(CONTAINS_TOMATOS, TRUE_VALUE));
|
||||
}
|
||||
/*
|
||||
if (ingredients.contains(TYPE.GENERIC_NUTS)) {
|
||||
point.add(build(CONTAINS_GENERIC_NUTS, TRUE_VALUE));
|
||||
}
|
||||
}*/
|
||||
|
||||
point.add(build(TASTE, "" + weight));
|
||||
|
||||
@@ -137,16 +138,17 @@ public class FoodNetBuilder {
|
||||
public static ProbabilityDistribution vegi(Survey survey) {
|
||||
String names[] = { SOMEONE_VEGETARIAN };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
if (survey.isDiner("vegetarian")) {
|
||||
table.setProbabilityForAssignment("true;", new Probability(1));
|
||||
table.setProbabilityForAssignment("false;", new Probability(0));
|
||||
} else {
|
||||
//if (survey.isDiner("vegetarian")) {
|
||||
// table.setProbabilityForAssignment("true;", new Probability(1));
|
||||
// table.setProbabilityForAssignment("false;", new Probability(0));
|
||||
//} else {
|
||||
table.setProbabilityForAssignment("true;", new Probability(0));
|
||||
table.setProbabilityForAssignment("false;", new Probability(1));
|
||||
}
|
||||
//}
|
||||
return table;
|
||||
}
|
||||
|
||||
/*
|
||||
public static ProbabilityDistribution allergicNuts(Survey survey) {
|
||||
String names[] = { SOMEONE_ALLERGIC_NUTS };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
@@ -158,7 +160,7 @@ public class FoodNetBuilder {
|
||||
table.setProbabilityForAssignment("false;", new Probability(1));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}*/
|
||||
|
||||
public static ProbabilityDistribution beef() {
|
||||
String names[] = { CONTAINS_MEAT, CONTAINS_BEEF };
|
||||
@@ -178,6 +180,7 @@ public class FoodNetBuilder {
|
||||
return table;
|
||||
}
|
||||
|
||||
/*
|
||||
public static ProbabilityDistribution genericNuts() {
|
||||
String names[] = { CONTAINS_NUTS, CONTAINS_GENERIC_NUTS };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
@@ -188,7 +191,7 @@ public class FoodNetBuilder {
|
||||
String names[] = { SOMEONE_ALLERGIC_NUTS, CONTAINS_NUTS };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
return table;
|
||||
}
|
||||
}*/
|
||||
|
||||
public static ProbabilityDistribution tomatos() {
|
||||
String names[] = { CONTAINS_VEGETABLE, CONTAINS_TOMATOS };
|
||||
@@ -210,7 +213,7 @@ public class FoodNetBuilder {
|
||||
|
||||
public static ProbabilityDistribution taste() {
|
||||
String names[] = { TASTE, CONTAINS_BEEF, CONTAINS_PORK,
|
||||
CONTAINS_POTATOS, CONTAINS_TOMATOS, CONTAINS_GENERIC_NUTS };
|
||||
CONTAINS_POTATOS, CONTAINS_TOMATOS/*, CONTAINS_GENERIC_NUTS*/ };
|
||||
ContinousDistribution distribution = new ContinousDistribution(names, 0);
|
||||
return distribution;
|
||||
}
|
||||
@@ -219,10 +222,10 @@ public class FoodNetBuilder {
|
||||
BayesNet net = new BayesNet(VARIABLES);
|
||||
|
||||
net.setDistribution(new Variable(SOMEONE_VEGETARIAN, DOMAIN), vegi(survey));
|
||||
net.setDistribution(new Variable(SOMEONE_ALLERGIC_NUTS, DOMAIN), allergicNuts(survey));
|
||||
//net.setDistribution(new Variable(SOMEONE_ALLERGIC_NUTS, DOMAIN), allergicNuts(survey));
|
||||
|
||||
net.setDistribution(new Variable(CONTAINS_MEAT, DOMAIN), meat());
|
||||
net.setDistribution(new Variable(CONTAINS_NUTS, DOMAIN), nuts());
|
||||
//net.setDistribution(new Variable(CONTAINS_NUTS, DOMAIN), nuts());
|
||||
|
||||
net.setDistribution(new Variable(CONTAINS_VEGETABLE, DOMAIN),
|
||||
vegetables());
|
||||
@@ -230,14 +233,14 @@ public class FoodNetBuilder {
|
||||
net.setDistribution(new Variable(CONTAINS_PORK, DOMAIN), pork());
|
||||
net.setDistribution(new Variable(CONTAINS_POTATOS, DOMAIN), potatos());
|
||||
net.setDistribution(new Variable(CONTAINS_TOMATOS, DOMAIN), tomatos());
|
||||
net.setDistribution(new Variable(CONTAINS_GENERIC_NUTS, DOMAIN), genericNuts());
|
||||
//net.setDistribution(new Variable(CONTAINS_GENERIC_NUTS, DOMAIN), genericNuts());
|
||||
|
||||
net.setDistribution(new Variable(TASTE, RATING_DOMAIN), taste());
|
||||
|
||||
Ontology ontology = createOntology();
|
||||
for (String category : ontology.getClasses()) {
|
||||
net.connect(category, SOMEONE_VEGETARIAN);
|
||||
net.connect(category, SOMEONE_ALLERGIC_NUTS);
|
||||
/*net.connect(category, SOMEONE_ALLERGIC_NUTS);*/
|
||||
}
|
||||
|
||||
for (String thing : OBSERVED) {
|
||||
|
||||
Reference in New Issue
Block a user