Commits

muzny  committed f3df4e5

Commented classifier.config

  • Participants
  • Parent commits 24a3330

Comments (0)

Files changed (2)

File WiktionaryIdioms/src/classifier/config/ClassifierConfigs.java

+/**
+ * A configuration class specifically designed to live in harmony with the
+ * classifier and read the corresponding .xml files in a way that makes everyone happy.
+ */
+
 package classifier.config;
 
 import java.util.ArrayList;
 		}
 	}
 	
+	/**
+	 * Get an instance of ClassifierConfigs, using GeneralConfigs.CLASSIFIER_CONFIGS
+	 * as the default path.
+	 * @return a ClassifierConfigs object that reads from the config file located at
+	 * GeneralConfigs.CLASSIFIER_CONFIGS
+	 */
 	public static ClassifierConfigs getInstance() {
 		if (instance == null) {
 			instance = new ClassifierConfigs();
 		return instance;
 	}
 	
+	
+	/**
+	 * Get an instance of ClassifierConfigs, from the specified path.
+	 * @param path - The path to the config file.
+	 * @return a ClassifierConfigs object that reads from the config file located at path.
+	 */
 	public static ClassifierConfigs getInstance(String path) {
 		if (instance == null) {
 			instance = new ClassifierConfigs(path);
 		return instance;
 	}
 	
+	/**
+	 * Get the string associated with the field specified in the section that you
+	 * are in, defaulting to the default section.
+	 * @param name - field name you are interested in
+	 * @return The String that corresponds to field, first from the section you
+	 * are in, then from the default section.
+	 */
 	public String getSString(String name) {
 		String result = xmlInst.getString(section + "." + name);
 		if (result == null || result.length() == 0) {
 		return result;
 	}
 	
+	/**
+	 * Get the string array associated with the field specified in the section that you
+	 * are in, defaulting to the default section.
+	 * @param name - field name you are interested in
+	 * @return The String array that corresponds to field, first from the section you
+	 * are in, then from the default section.
+	 */
 	public String[] getSStringArray(String name) {
 		String[] result = xmlInst.getStringArray(section + "." + name);
 		if (result == null || result.length == 0) {
 		return result;
 	}
 	
+	
+	/**
+	 * Get the int associated with the field specified in the section that you
+	 * are in, defaulting to the default section.
+	 * @param name - field name you are interested in
+	 * @return The int that corresponds to field, first from the section you
+	 * are in, then from the default section.
+	 */
 	public Integer getSInt(String name) {
 		int result;
 		try {
 		return result;
 	}
 	
+	
+	/**
+	 * Get the boolean associated with the field specified in the section that you
+	 * are in, defaulting to the default section.
+	 * @param name - field name you are interested in
+	 * @return The boolean that corresponds to field, first from the section you
+	 * are in, then from the default section.
+	 */
 	public boolean getSBool(String name) {
 		boolean result;
 		try {
 		return result;
 	}
 	
+	/**
+	 * Get the double associated with the field specified in the section that you
+	 * are in, defaulting to the default section.
+	 * @param name - field name you are interested in
+	 * @return The double that corresponds to field, first from the section you
+	 * are in, then from the default section.
+	 */
 	public double getSDouble(String name) {
 		double result;
 		try {
 		return result;
 	}
 	
-	public void addConfig(String name, String value) {
-		xmlInst.addProperty(name, value);
-	}
-	
-	
+	/**
+	 * Set the specific section to look in before defaulting to the default section.
+	 * @param name - The name of the section in the xml config file.
+	 */
 	public void setSection(String name) {
 		section = name;
 	}
 	
+	/**
+	 * Get the list of ints associated with the field specified in the section that you
+	 * are in, defaulting to the default section. Specifically designed to get the
+	 * list of features that you want to use.
+	 * @param name - field name you are interested in
+	 * @return The list of ints that corresponds to field, first from the section you
+	 * are in, then from the default section.
+	 */
 	public List<Integer> getSFeatures(String name) {
 		// Now analyze which features we should be using
 		String[] feats = getSStringArray(name);
 		return featuresToUse;
 	}
 	
+	/**
+	 * Loads the classifier that is specified in the config file, meaning that it
+	 * loads all section fields associated with iterations, error bound, learning rate,
+	 * and features, as specified by the constants in this file. Calls the methods
+	 * that first read from the specific section, then default to the default section.
+	 * Reads the type from the config file too - "trusting" or "perceptron".
+	 * @return - The Classifier that this section of the config file specifies.
+	 */
 	public Classifier getSClassifier() {		
 		int iters = getSInt(ITERATIONS);
 		double errorBound = getSDouble(ERROR_BOUND);
 		return getClassifier(iters, errorBound, learningRate, feats);
 	}
 	
+	/**
+	 * Gets the classifier specified by the parameters, reading the type that it ought to
+	 * be from the config file. "trusting" maps to a TrustingPerception, "perceptron" maps
+	 * to a Perceptron.
+	 * @param iters - numIterations for the Classifier constructor
+	 * @param errorBound - as in the Classifier constructor
+	 * @param learningRate - as in the Classifier constructor
+	 * @param feats -  as in the Classifier constructor
+	 * @return Your newly constructed classifier of the type specified in the config file.
+	 */
 	public Classifier getClassifier(int iters, double errorBound, double learningRate, List<Integer> feats) {
 		String type = getSString(CLASSIFIER_TYPE);
 		if (type.equals("trusting")) {
 		return null;
 	}
 	
+	/**
+	 * Takes in a classifier model and returns the proper classifier according to the type
+	 * specified in the config file - "trusting" or "perceptron".
+	 * @param clm - ClassifierModel to build the classifier from.
+	 * @return Your newly constructed classifier according to the given model and the
+	 * type denoted in the config file.
+	 */
 	public Classifier getClassifier(ClassifierModel clm) {
 		String type = getSString(CLASSIFIER_TYPE);
 		if (type.equals("untrusting")) {
 			return new TrustingPerceptron(clm);
 		} else if (type.equals("perceptron")) {
-			// type.equals("perceptron")
 			return new Perceptron(clm);
 		}
 		return null;

File WiktionaryIdioms/src/classifier/config/GeneralConfigs.java

 package classifier.config;
+/**
+ * Basic config wrapper that reads the value for a 
+ * field from a specified config file.
+ */
 
 import java.util.HashMap;
 import java.util.Map;
 		}
 	}
 	
+	/**
+	 * Read and return the value at field name from file at path as
+	 * a String.
+	 * @param path - Location of config file to read from.
+	 * @param name - The name of the field to get the value from.
+	 * @return String value at name in file at path.
+	 */
 	public static String getString(String path, String name) {
 		initialize(path);
 		return xmlInsts.get(path).getString(name);