/** * CBR.java * Original Author: Nick Bridle (nbridle@cs.wisc.edu) * (feel free to add your name to this header) * * This is a starter file for the programming portion of HW3 for Professor Shavlik's * Fall 2011 class. It represents the beginning of a class that can perform two different * variations of case-based reasoning for semantic spell checking. * * Note: If you have any questions about this file or how to proceed, feel free to come see me. * Don't feel that you have to use this template if you don't want to; it's here for your convenience. */ import java.io.*; import java.util.*; public class CBR { public static void main(String[] args) { // Verify that the correct number of command-line arguments were passed in if(args.length != 5) { System.err.println("usage: java CBR wordX wordY fractionXoverY fileOfTrainingCases fileOfTestPhrases"); System.exit(1); } // Initialize the input variables String wordX = args[0]; String wordY = args[1]; double ratioXOverY = Double.parseDouble(args[2]); String trainFilename = args[3]; String testFilename = args[4]; // Open the training set and test file Scanner trainFile = null; Scanner testFile = null; try { trainFile = new Scanner(new File(trainFilename)); testFile = new Scanner(new File(testFilename)); } catch(IOException e) { e.printStackTrace(); } // Iterate through the lines in the training file while(trainFile.hasNextLine()) { String line = trainFile.nextLine(); // Here is where you need to parse the line and put it into a data structure // representing a single training set example. // I would recommend checking out the Scanner class, but you can do this // however you think is best. // ex: Scanner scanner = new Scanner(line); // // Since you need to parse the examples for both programs (this and BayesNet), you should // probably write this functionality in a single place and call it from both programs. // For now, we just print out the line from the file to show that the file read worked // Remove this in your actual code! System.out.println(line); } // Do something similar for the testFile, except that you want to read lines in groups of three // instead of single lines. // Iterate through your test file and classify each of the test examples, and print out the results. } /** * In some Java IDE's, the console window can close up before you get a chance to read it, * so this method can be used to wait until you're ready to proceed. * @param msg the message to display before waiting */ public static void waitHere(String msg) { System.out.print("\n" + msg); try { System.in.read(); } catch(Exception e) {} // Ignore any errors while reading. } }