/** * Expect directory with subdirectories for each evaluation. Subdirectories must contain following * in order for results to be processed: * * <ul> * <li>model.txt: libsvm model trained on training set * <li>predict.txt: libsvm predictions on test set * <li>options.properties: libsvm command line options * </ul> * * @param line * @throws Exception */ private static void importDirectory(CommandLine line) throws Exception { WekaResultsImporter importer = (WekaResultsImporter) KernelContextHolder.getApplicationContext().getBean("wekaResultsImporter"); File cvDir = new File(line.getOptionValue("cvDir")); if (cvDir.listFiles() == null || cvDir.listFiles().length == 0) { System.err.println("directory is empty: " + cvDir); } else { for (File resultDir : cvDir.listFiles()) { String model = resultDir + File.separator + "model.obj"; String output = resultDir + File.separator + "predict.txt"; String optionsFile = resultDir + File.separator + "options.properties"; if (checkFileRead(output) && checkFileRead(optionsFile)) { String options = null; Integer fold = null; InputStream isOptions = null; try { isOptions = new FileInputStream(optionsFile); Properties props = new Properties(); props.load(isOptions); options = props.getProperty("options"); String strFold = props.getProperty("fold"); if (strFold != null) { try { fold = Integer.parseInt(strFold); } catch (NumberFormatException nfe) { } } } finally { isOptions.close(); } if (options != null) { BufferedReader r = null; try { r = new BufferedReader(new FileReader(output)); importer.importClassifierEvaluation( line.getOptionValue("name"), fold, line.getOptionValue("algo", "weka"), line.getOptionValue("label"), options, line.getOptionValue("experiment"), r); } finally { try { r.close(); } catch (Exception e) { } } } } } } }
/** @param args */ public static void docPredImport(String predictions, String task) throws Exception { WekaResultsImporter importer = (WekaResultsImporter) KernelContextHolder.getApplicationContext().getBean("wekaResultsImporter"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(predictions)); importer.importDocumentResults(task, reader); } finally { if (reader != null) { reader.close(); } } }