Work in progress.
This commit is contained in:
28
src/net/woodyfolsom/cs6601/p2/BayesChef.java
Normal file
28
src/net/woodyfolsom/cs6601/p2/BayesChef.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BayesChef {
|
||||
|
||||
public static void main(String... args) {
|
||||
System.out.println("Reading recipe book.");
|
||||
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/survey_recipes.xml"));
|
||||
|
||||
System.out.println("Read data for " + recipeBook.getSize() + " recipes.");
|
||||
|
||||
System.out.println("Reading survey data.");
|
||||
Survey survey = SurveyReader.readSurvey(new File("data/survey.xml"));
|
||||
|
||||
System.out.println("Read data for " + survey.getDinerCount() + " diner(s).");
|
||||
|
||||
System.out.println("Setting evidence for first 11 recipes.");
|
||||
|
||||
System.out.println("Evaluating preference for remaining recipes.");
|
||||
|
||||
System.out.println("RMSE for recipes #12-22 (calculated vs. surveyed preference):");
|
||||
|
||||
for (int dinerIndex = 0; dinerIndex < survey.getDinerCount(); dinerIndex++) {
|
||||
System.out.println("Diner # " + (dinerIndex + 1) + "...");
|
||||
}
|
||||
}
|
||||
}
|
||||
25
src/net/woodyfolsom/cs6601/p2/Diner.java
Normal file
25
src/net/woodyfolsom/cs6601/p2/Diner.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
@XStreamAlias("diner")
|
||||
public class Diner {
|
||||
private int id;
|
||||
private Map<Integer,Integer> ratings = new HashMap<Integer,Integer>();
|
||||
private Map<Integer,Boolean> allergies = new HashMap<Integer,Boolean>();
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getRating(int dishId) {
|
||||
return ratings.get(dishId);
|
||||
}
|
||||
|
||||
public boolean isAllergic(int categoryId) {
|
||||
return allergies.get(categoryId);
|
||||
}
|
||||
}
|
||||
42
src/net/woodyfolsom/cs6601/p2/Survey.java
Normal file
42
src/net/woodyfolsom/cs6601/p2/Survey.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamImplicit;
|
||||
|
||||
@XStreamAlias("survey")
|
||||
public class Survey {
|
||||
private Map<Integer,String> dishes = new HashMap<Integer,String>();
|
||||
private Map<Integer,String> categories = new HashMap<Integer,String>();
|
||||
|
||||
@XStreamImplicit(itemFieldName="diner")
|
||||
private List<Diner> diners = new ArrayList<Diner>();
|
||||
|
||||
public Diner getDiner(int dinerIndex) {
|
||||
return diners.get(dinerIndex);
|
||||
}
|
||||
|
||||
public int getDinerCount() {
|
||||
return diners.size();
|
||||
}
|
||||
|
||||
public String getDish(int dishId) {
|
||||
return dishes.get(dishId);
|
||||
}
|
||||
|
||||
public int getDishCount() {
|
||||
return dishes.size();
|
||||
}
|
||||
|
||||
public String getCategory(int catId) {
|
||||
return categories.get(catId);
|
||||
}
|
||||
|
||||
public int getCategoryCount() {
|
||||
return categories.size();
|
||||
}
|
||||
}
|
||||
13
src/net/woodyfolsom/cs6601/p2/SurveyReader.java
Normal file
13
src/net/woodyfolsom/cs6601/p2/SurveyReader.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package net.woodyfolsom.cs6601.p2;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
public class SurveyReader {
|
||||
private static XStream xstream = XStreamFactory.getInstance();
|
||||
|
||||
public static Survey readSurvey(File surveyFile) {
|
||||
return (Survey) xstream.fromXML(surveyFile);
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,9 @@ public class XStreamFactory {
|
||||
public static XStream getInstance() {
|
||||
XStream xstream = new XStream(new DomDriver());
|
||||
|
||||
///RecipeBook
|
||||
xstream.processAnnotations(RecipeBook.class);
|
||||
|
||||
|
||||
xstream.processAnnotations(Recipe.class);
|
||||
xstream.omitField(Recipe.class, "directions");
|
||||
|
||||
@@ -32,6 +32,10 @@ public class XStreamFactory {
|
||||
xstream.omitField(Ingredient.class, "amt");
|
||||
xstream.omitField(Ingredient.class, "prep");
|
||||
|
||||
///Survey
|
||||
xstream.processAnnotations(Survey.class);
|
||||
xstream.processAnnotations(Diner.class);
|
||||
|
||||
return xstream;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user