Work in progress.
This commit is contained in:
@@ -34,9 +34,9 @@ public class FoodExampleTest {
|
||||
+ table.getAssignments().get(assignment).getProbability());
|
||||
}
|
||||
|
||||
System.out.println("MEET: ");
|
||||
System.out.println("MEAT: ");
|
||||
table = (ProbabilityTable) net.getNodes().get(
|
||||
FoodExampleBuilder.CONTAINS_MEET);
|
||||
FoodExampleBuilder.CONTAINS_MEAT);
|
||||
for (String name : table.getNames()) {
|
||||
System.out.print(name + " ");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class FoodExampleBuilder {
|
||||
|
||||
public static final String TASTE = "Taste";
|
||||
public static final String SOMEONE_VEGETARIAN = "Vegetarian";
|
||||
public static final String CONTAINS_MEET = "Meet";
|
||||
public static final String CONTAINS_MEAT = "Meat";
|
||||
public static final String CONTAINS_VEGETABLE = "Vegetable";
|
||||
public static final String CONTAINS_BEEF = "Beef";
|
||||
public static final String CONTAINS_PORK = "Pork";
|
||||
@@ -35,7 +35,7 @@ public class FoodExampleBuilder {
|
||||
"6", "7", "8", "9", "10" };
|
||||
|
||||
private static final String[] VARIABLES = { SOMEONE_VEGETARIAN,
|
||||
CONTAINS_BEEF, CONTAINS_MEET, CONTAINS_PORK, CONTAINS_POTATOS,
|
||||
CONTAINS_BEEF, CONTAINS_MEAT, CONTAINS_PORK, CONTAINS_POTATOS,
|
||||
CONTAINS_TOMATOS, CONTAINS_VEGETABLE, TASTE };
|
||||
|
||||
private static final String[] OBSERVED = { CONTAINS_BEEF, CONTAINS_PORK,
|
||||
@@ -59,13 +59,13 @@ public class FoodExampleBuilder {
|
||||
return new LinkedList<Assignment>(assignment);
|
||||
}
|
||||
|
||||
public static Ontology onto() {
|
||||
public static Ontology createOntology() {
|
||||
HashSet<String> classes = new HashSet<String>();
|
||||
classes.add(CONTAINS_MEET);
|
||||
classes.add(CONTAINS_MEAT);
|
||||
classes.add(CONTAINS_VEGETABLE);
|
||||
Ontology onthology = new Ontology(classes);
|
||||
onthology.define(CONTAINS_PORK, CONTAINS_MEET);
|
||||
onthology.define(CONTAINS_BEEF, CONTAINS_MEET);
|
||||
onthology.define(CONTAINS_PORK, CONTAINS_MEAT);
|
||||
onthology.define(CONTAINS_BEEF, CONTAINS_MEAT);
|
||||
|
||||
onthology.define(CONTAINS_TOMATOS, CONTAINS_VEGETABLE);
|
||||
onthology.define(CONTAINS_POTATOS, CONTAINS_VEGETABLE);
|
||||
@@ -146,7 +146,7 @@ public class FoodExampleBuilder {
|
||||
|
||||
public static DataSet examples() {
|
||||
DataSet data = new DataSet();
|
||||
Ontology onto = onto();
|
||||
Ontology onto = createOntology();
|
||||
// user one ratings
|
||||
data.add(normalize(porkTomatoDish(10), onto));
|
||||
data.add(normalize(porkPotatoDish(9), onto));
|
||||
@@ -184,19 +184,19 @@ public class FoodExampleBuilder {
|
||||
}
|
||||
|
||||
public static ProbabilityDistribution beef() {
|
||||
String names[] = { CONTAINS_MEET, CONTAINS_BEEF };
|
||||
String names[] = { CONTAINS_MEAT, CONTAINS_BEEF };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
return table;
|
||||
}
|
||||
|
||||
public static ProbabilityDistribution pork() {
|
||||
String names[] = { CONTAINS_MEET, CONTAINS_PORK };
|
||||
String names[] = { CONTAINS_MEAT, CONTAINS_PORK };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
return table;
|
||||
}
|
||||
|
||||
public static ProbabilityDistribution meet() {
|
||||
String names[] = { SOMEONE_VEGETARIAN, CONTAINS_MEET };
|
||||
String names[] = { SOMEONE_VEGETARIAN, CONTAINS_MEAT };
|
||||
ProbabilityTable table = new ProbabilityTable(names);
|
||||
return table;
|
||||
}
|
||||
@@ -229,7 +229,7 @@ public class FoodExampleBuilder {
|
||||
public static BayesNet dishNet() {
|
||||
BayesNet net = new BayesNet(VARIABLES);
|
||||
net.setDistribution(new Variable(SOMEONE_VEGETARIAN, DOMAIN), vegi());
|
||||
net.setDistribution(new Variable(CONTAINS_MEET, DOMAIN), meet());
|
||||
net.setDistribution(new Variable(CONTAINS_MEAT, DOMAIN), meet());
|
||||
net.setDistribution(new Variable(CONTAINS_VEGETABLE, DOMAIN),
|
||||
vegetables());
|
||||
net.setDistribution(new Variable(CONTAINS_BEEF, DOMAIN), beef());
|
||||
@@ -238,19 +238,19 @@ public class FoodExampleBuilder {
|
||||
net.setDistribution(new Variable(CONTAINS_TOMATOS, DOMAIN), tomatos());
|
||||
net.setDistribution(new Variable(TASTE, RATING_DOMAIN), taste());
|
||||
|
||||
Ontology onthology = onto();
|
||||
for (String category : onthology.getClasses()) {
|
||||
Ontology ontology = createOntology();
|
||||
for (String category : ontology.getClasses()) {
|
||||
net.connect(category, SOMEONE_VEGETARIAN);
|
||||
}
|
||||
|
||||
for (String thing : OBSERVED) {
|
||||
net.connect(thing, onthology.getInheritance().get(thing));
|
||||
net.connect(thing, ontology.getInheritance().get(thing));
|
||||
net.connect(TASTE, thing);
|
||||
}
|
||||
|
||||
for (String category : onthology.getClasses()) {
|
||||
for (String category : ontology.getClasses()) {
|
||||
MaximumLikelihoodEstimation.estimate(examples(), net, category);
|
||||
for (String thing : onthology.getClasses2thing().get(category)) {
|
||||
for (String thing : ontology.getClasses2thing().get(category)) {
|
||||
MaximumLikelihoodEstimation.estimate(examples(), net, thing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.woodyfolsom.cs6601.p2.Ingredient.TYPE;
|
||||
import net.woodyfolsom.cs6601.p2.Recipe;
|
||||
import net.woodyfolsom.cs6601.p2.RecipeBook;
|
||||
import net.woodyfolsom.cs6601.p2.RecipeBookReader;
|
||||
@@ -17,15 +18,23 @@ import org.junit.Test;
|
||||
public class RecipeBookReaderTest {
|
||||
|
||||
@Test
|
||||
public void testReadRecipeBook() {
|
||||
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/PastelVasco.xml"));
|
||||
public void testReadSurveyDataset() {
|
||||
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/survey_recipes.xml"));
|
||||
assertNotNull(recipeBook);
|
||||
assertThat(recipeBook.getSize(), is(equalTo(1)));
|
||||
assertThat(recipeBook.getSize(), is(equalTo(22)));
|
||||
|
||||
Recipe recipe = recipeBook.getRecipe(0);
|
||||
assertThat(recipe.getHead().getTitle(), is(equalTo("Gateau Basque / Pastel Vasco")));
|
||||
assertTrue(recipe.getHead().isCategoryMatch("Desserts"));
|
||||
assertTrue(recipe.getHead().isCategoryMatch("Sweets"));
|
||||
assertFalse(recipe.getHead().isCategoryMatch("Meat"));
|
||||
System.out.println(recipe.getHead().getTitle());
|
||||
assertThat(recipe.getHead().getTitle(), is(equalTo("Honey cake")));
|
||||
assertTrue(recipe.getIngredients().contains(TYPE.EGGS));
|
||||
assertTrue(recipe.getIngredients().contains(TYPE.GLUTEN));
|
||||
assertTrue(recipe.getIngredients().contains(TYPE.SPICE));
|
||||
assertFalse(recipe.getIngredients().contains(TYPE.RED_MEAT));
|
||||
assertFalse(recipe.getIngredients().contains(TYPE.POULTRY));
|
||||
assertFalse(recipe.getIngredients().contains(TYPE.SHELLFISH));
|
||||
|
||||
for (int rIndex = 0; rIndex < recipeBook.getSize(); rIndex++) {
|
||||
System.out.println(recipeBook.getRecipe(rIndex).getHead().getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
test/net/woodyfolsom/cs6601/p2/RecipeReaderTest.java
Normal file
31
test/net/woodyfolsom/cs6601/p2/RecipeReaderTest.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.woodyfolsom.cs6601.p2.Recipe;
|
||||
import net.woodyfolsom.cs6601.p2.RecipeBook;
|
||||
import net.woodyfolsom.cs6601.p2.RecipeBookReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RecipeReaderTest {
|
||||
|
||||
@Test
|
||||
public void testReadRecipeBook() {
|
||||
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/PastelVasco.xml"));
|
||||
assertNotNull(recipeBook);
|
||||
assertThat(recipeBook.getSize(), is(equalTo(1)));
|
||||
|
||||
Recipe recipe = recipeBook.getRecipe(0);
|
||||
assertThat(recipe.getHead().getTitle(), is(equalTo("Gateau Basque / Pastel Vasco")));
|
||||
assertTrue(recipe.getHead().isCategoryMatch("Desserts"));
|
||||
assertTrue(recipe.getHead().isCategoryMatch("Sweets"));
|
||||
assertFalse(recipe.getHead().isCategoryMatch("Meat"));
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.woodyfolsom.cs6601.p2.Ingredient.TYPE;
|
||||
import net.woodyfolsom.cs6601.p2.Recipe;
|
||||
import net.woodyfolsom.cs6601.p2.RecipeBook;
|
||||
import net.woodyfolsom.cs6601.p2.RecipeBookReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SurveyDatasetReaderTest {
|
||||
|
||||
@Test
|
||||
public void testReadSurveyDataset() {
|
||||
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/survey_dataset.xml"));
|
||||
assertNotNull(recipeBook);
|
||||
assertThat(recipeBook.getSize(), is(equalTo(22)));
|
||||
|
||||
Recipe recipe = recipeBook.getRecipe(0);
|
||||
System.out.println(recipe.getHead().getTitle());
|
||||
assertThat(recipe.getHead().getTitle(), is(equalTo("Honey cake")));
|
||||
assertTrue(recipe.getIngredients().contains(TYPE.EGGS));
|
||||
assertTrue(recipe.getIngredients().contains(TYPE.GLUTEN));
|
||||
assertTrue(recipe.getIngredients().contains(TYPE.SPICE));
|
||||
assertFalse(recipe.getIngredients().contains(TYPE.RED_MEAT));
|
||||
assertFalse(recipe.getIngredients().contains(TYPE.POULTRY));
|
||||
assertFalse(recipe.getIngredients().contains(TYPE.SHELLFISH));
|
||||
|
||||
for (int rIndex = 0; rIndex < recipeBook.getSize(); rIndex++) {
|
||||
System.out.println(recipeBook.getRecipe(rIndex).getHead().getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
24
test/net/woodyfolsom/cs6601/p2/SurveyReaderTest.java
Normal file
24
test/net/woodyfolsom/cs6601/p2/SurveyReaderTest.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SurveyReaderTest {
|
||||
|
||||
@Test
|
||||
public void testReadSurveyDataset() {
|
||||
Survey survey = SurveyReader.readSurvey(new File("data/survey.xml"));
|
||||
assertNotNull(survey);
|
||||
|
||||
assertThat(survey.getDinerCount(), equalTo(5));
|
||||
|
||||
Diner diner = survey.getDiner(0);
|
||||
assertThat(diner.isAllergic(0), is(false));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user