/** * Copy all files in the source directory to the target directory. * @param srcDir The source directory. * @param dstDir The target directory. * @param files The files to be copied. NOTE THAT this list contains only names (WITHOUT PATH). */ public static void copyFiles(final String srcDir, final String dstDir, final List<String> files) { for (final String file : files) { FileUtils.copyFile(srcDir + file, dstDir + file); } }
/** * Compare the performance of a set of systems to that of a baseline system * @param directory Contain files denoting the performance of the target systems to be compared * @param baseFile Performance file for the baseline system */ public void compare(String directory, final String baseFile) { directory = FileUtils.makePathStandard(directory); final List<String> targets = FileUtils.getAllFiles2(directory);//ONLY filenames are stored for (int i = 0; i < targets.size(); i++) { if (targets.get(i).compareTo(baseFile) == 0) { targets.remove(i); i--; } else { targets.set(i, directory + targets.get(i));//convert filename to full path } } compare(targets, directory + baseFile); }
public Ranker loadRankerFromFile(String modelFile) { return loadRankerFromString(FileUtils.read(modelFile, "ASCII")); } public Ranker loadRankerFromString(String fullText)
tvs = Float.parseFloat(args[++i]); else if(args[i].compareTo("-output")==0) outputDir = FileUtils.makePathStandard(args[++i]); String fn = FileUtils.getFileName(rankingFiles.get(0)); if(shuffle)
public static BufferedReader smartReader(final String inputFile) throws IOException { return smartReader(inputFile, "UTF-8"); }
public void save(String modelFile) { // Determine if the directory to write to exists. If not, create it. Path parentPath = Paths.get(modelFile).toAbsolutePath().getParent(); // Create the directory if it doesn't exist. Give it 755 perms if (Files.notExists (parentPath)) { try { Set<PosixFilePermission> perms = PosixFilePermissions.fromString ("rwxr-xr-x"); FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute (perms); Path outputDir = Files.createDirectory (parentPath, attr); } catch (Exception e) { System.out.println ("Error creating kcv model file directory " + modelFile); } } FileUtils.write(modelFile, "ASCII", model()); }
public void combine(final String directory, final String outputFile) { final RankerFactory rf = new RankerFactory(); final String[] fns = FileUtils.getAllFiles(directory); try (final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "ASCII"))) { out.write("## " + (new RFRanker()).name() + "\n"); for (final String fn2 : fns) { if (fn2.indexOf(".progress") != -1) { continue; } final String fn = directory + fn2; final RFRanker r = (RFRanker) rf.loadRankerFromFile(fn); final Ensemble en = r.getEnsembles()[0]; out.write(en.toString()); } } catch (final Exception e) { throw RankLibError.create("Error in Combiner::combine(): " + e.toString(), e); } } }
ranker.save(FileUtils.makePathStandard(modelDir) + "f" + (i+1) + "." + modelFile); System.out.println("Fold-" + (i+1) + " model saved to: " + modelFile);
System.out.println("------------------------------------------------------------------------"); System.out.println("System\tPerformance\tImprovement\tWin\tLoss\tp-value"); System.out.println(FileUtils.getFileName(baseFile) + " [baseline]\t" + SimpleMath.round(base.get("all").doubleValue(), 4)); for(int i=0;i<rs.length;i++) String msg = FileUtils.getFileName(targetFiles.get(i)) + "\t" + SimpleMath.round(targets.get(i).get("all").doubleValue(), 4); msg += "\t" + ((delta>0)?"+":"") + SimpleMath.round(delta, 4) + " (" + ((delta>0)?"+":"") + SimpleMath.round(dp, 2) + "%)"; msg += "\t" + rs[i].win + "\t" + rs[i].loss; String msg = FileUtils.getFileName(targetFiles.get(i)); for(int j=0;j<rs[i].countByImprovementRange.length;j++) msg += "\t" + rs[i].countByImprovementRange[j];
tts = Float.parseFloat(args[++i]); } else if (args[i].equalsIgnoreCase("-output")) { outputDir = FileUtils.makePathStandard(args[++i]); } else if (args[i].equalsIgnoreCase("-feature_stats")) { doFeatureStats = true; String fn = FileUtils.getFileName(rankingFiles.get(0));
public static List<String> readLine(final String filename, final String encoding) { final List<String> lines = new ArrayList<>(); try (final BufferedReader in = smartReader(filename, encoding)) { String content = null; while ((content = in.readLine()) != null) { content = content.trim(); if (content.length() == 0) { continue; } lines.add(content); } } catch (final Exception ex) { throw RankLibError.create(ex); } return lines; }
public void save(final String modelFile) { // Determine if the directory to write to exists. If not, create it. final Path parentPath = Paths.get(modelFile).toAbsolutePath().getParent(); // Create the directory if it doesn't exist. Give it 755 perms if (Files.notExists(parentPath)) { try { final Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x"); final FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms); Files.createDirectory(parentPath, attr); } catch (final Exception e) { throw RankLibError.create("Error creating kcv model file directory " + modelFile, e); } } FileUtils.write(modelFile, "ASCII", model()); }
public void combine(String directory, String outputFile) { RankerFactory rf = new RankerFactory(); String[] fns = FileUtils.getAllFiles(directory); BufferedWriter out = null; try{ out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "ASCII")); out.write("## " + (new RFRanker()).name() + "\n"); for(int i=0;i<fns.length;i++) { if(fns[i].indexOf(".progress") != -1) continue; String fn = directory + fns[i]; RFRanker r = (RFRanker)rf.loadRankerFromFile(fn); Ensemble en = r.getEnsembles()[0]; out.write(en.toString()); } out.close(); } catch(Exception e) { System.out.println("Error in Combiner::combine(): " + e.toString()); } } }
ranker.save(FileUtils.makePathStandard(modelDir) + "f" + (i + 1) + "." + modelFile); if (logger.isLoggable(Level.INFO)) { logger.info("Fold-" + (i + 1) + " model saved to: " + modelFile);
logger.info(() -> FileUtils.getFileName(baseFile) + " [baseline]\t" + SimpleMath.round(base.get("all").doubleValue(), 4)); for (int i = 0; i < rs.length; i++) { if (rs[i].status == 0) { final double delta = targets.get(i).get("all") - base.get("all"); final double dp = delta * 100 / base.get("all"); logger.info(FileUtils.getFileName(targetFiles.get(i)) + "\t" + SimpleMath.round(targets.get(i).get("all").doubleValue(), 4) + "\t" + ((delta > 0) ? "+" : "") + SimpleMath.round(delta, 4) + " (" + ((delta > 0) ? "+" : "") + SimpleMath.round(dp, 2) + "%)" + "\t" + rs[i].win + "\t" + rs[i].loss + "\t" String msg = FileUtils.getFileName(targetFiles.get(i)); for (final int element : rs[i].countByImprovementRange) { msg += "\t" + element;
/** * Compare the performance of a set of systems to that of a baseline system * @param directory Contain files denoting the performance of the target systems to be compared * @param baseFile Performance file for the baseline system */ public void compare(String directory, String baseFile) { directory = FileUtils.makePathStandard(directory); List<String> targets = FileUtils.getAllFiles2(directory);//ONLY filenames are stored for(int i=0;i<targets.size();i++) { if(targets.get(i).compareTo(baseFile) == 0) { targets.remove(i); i--; } else targets.set(i, directory+targets.get(i));//convert filename to full path } compare(targets, directory+baseFile); } /**
/** * Read the content of a file. * @param filename The file to read. * @param encoding The encoding of the file. * @return The content of the input file. */ public static String read(final String filename, final String encoding) { final StringBuilder content = new StringBuilder(1000); try (BufferedReader in = smartReader(filename, encoding)) { final char[] newContent = new char[40960]; int numRead = -1; while ((numRead = in.read(newContent)) != -1) { content.append(new String(newContent, 0, numRead)); } } catch (final Exception e) { throw RankLibError.create(e); } return content.toString(); }
public Ranker loadRankerFromFile(final String modelFile) { return loadRankerFromString(FileUtils.read(modelFile, "ASCII")); }
/** * Copy all files in the source directory to the target directory. * @param srcDir The source directory. * @param dstDir The target directory. * @param files The files to be copied. NOTE THAT this list contains only names (WITHOUT PATH). */ public static void copyFiles(String srcDir, String dstDir, List<String> files) { for (String file : files) FileUtils.copyFile(srcDir + file, dstDir + file); } public static final int BUF_SIZE = 51200;
@Override public void loadExternalRelevanceJudgment(final String qrelFile) { relDocCount = new HashMap<>(); try (BufferedReader in = FileUtils.smartReader(qrelFile)) { String content = ""; while ((content = in.readLine()) != null) { content = content.trim(); if (content.length() == 0) { continue; } final String[] s = content.split(" "); final String qid = s[0].trim(); final int label = (int) Math.rint(Double.parseDouble(s[3].trim())); if (label > 0) { final int prev = relDocCount.getOrDefault(qid, 0); relDocCount.put(qid, prev + 1); } } logger.info(() -> "Relevance judgment file loaded. [#q=" + relDocCount.size() + "]"); } catch (final IOException ex) { throw RankLibError.create("Error in APScorer::loadExternalRelevanceJudgment(): ", ex); } }