List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.GenerateCrossDomainCVReport.java
/** * Merges id2outcome files from sub-folders with cross-domain and creates a new folder * with overall results/*from w ww . j a v a 2 s . c om*/ * * @param folder folder * @throws java.io.IOException */ public static void aggregateDomainResults(File folder, String subDirPrefix, final String taskFolderSubText, String outputFolderName) throws IOException { // list all sub-folders File[] folders = folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && pathname.getName().contains(taskFolderSubText); } }); if (folders.length == 0) { throw new IllegalArgumentException("No sub-folders 'SVMHMMTestTask*' found in " + folder); } // write to a file File outFolder = new File(folder, outputFolderName); File output = new File(outFolder, subDirPrefix); output.mkdirs(); File outCsv = new File(output, TOKEN_LEVEL_PREDICTIONS_CSV); CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(outCsv), SVMHMMUtils.CSV_FORMAT); csvPrinter.printComment(SVMHMMUtils.CSV_COMMENT); ConfusionMatrix cm = new ConfusionMatrix(); for (File domain : folders) { File tokenLevelPredictionsCsv = new File(domain, subDirPrefix + "/" + TOKEN_LEVEL_PREDICTIONS_CSV); if (!tokenLevelPredictionsCsv.exists()) { throw new IllegalArgumentException( "Cannot locate tokenLevelPredictions.csv: " + tokenLevelPredictionsCsv); } CSVParser csvParser = new CSVParser(new FileReader(tokenLevelPredictionsCsv), CSVFormat.DEFAULT.withCommentMarker('#')); for (CSVRecord csvRecord : csvParser) { // copy record csvPrinter.printRecord(csvRecord); // update confusion matrix cm.increaseValue(csvRecord.get(0), csvRecord.get(1)); } } // write to file FileUtils.writeStringToFile(new File(outFolder, "confusionMatrix.txt"), cm.toString() + "\n" + cm.printNiceResults() + "\n" + cm.printLabelPrecRecFm() + "\n" + cm.printClassDistributionGold()); // write csv IOUtils.closeQuietly(csvPrinter); }
From source file:de.fatalix.book.importer.BookMigrator.java
private static List<File> walkTree(List<File> result, File currentFolder) { if (hasFolderBook(currentFolder)) { result.add(currentFolder);//w w w. ja v a 2s . c o m } else { File[] subFolders = currentFolder.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } }); for (File subFolder : subFolders) { result = walkTree(result, subFolder); } } return result; }
From source file:com.bowprog.sql.constructeur.CreateDataBase.java
/** * lance la cration//w ww .j a va 2 s. co m */ public void launch() { File[] listFile = dirStructure.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.getName().contains(".json")) { return true; } return false; } }); for (File file : listFile) { fileRead(file); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.helpers.FinalTableExtractor.java
public static void createCrossEvaluationTables(File mainFolder, final String prefix) throws IOException { Map<String, Table<String, String, Double>> domainResults = new TreeMap<>(); File[] crossDomainFolders = mainFolder.listFiles(new FileFilter() { @Override//from www.j a v a 2 s . co m public boolean accept(File pathname) { return pathname.isDirectory() && pathname.getName().startsWith(prefix); } }); System.out.println(Arrays.toString(crossDomainFolders)); for (File crossDomainFolder : crossDomainFolders) { // get the target domain String[] folderNameSplit = crossDomainFolder.getName().split("_"); String domain = folderNameSplit[1]; String featureSet = folderNameSplit[2]; File resultSummaryFile = new File(crossDomainFolder, "resultSummary.txt"); for (String line : FileUtils.readLines(resultSummaryFile)) { // parse the line with evaluation String[] split = line.split("\\s+"); String argumentComponent = split[0]; Double value = Double.valueOf(split[1]); // create a new table if needed if (!domainResults.containsKey(domain)) { domainResults.put(domain, TreeBasedTable.<String, String, Double>create()); } // fill the table Table<String, String, Double> table = domainResults.get(domain); if (includeColumn(argumentComponent)) { table.put(featureSet, argumentComponent, value); } } } System.out.println(domainResults.keySet()); for (Map.Entry<String, Table<String, String, Double>> entry : domainResults.entrySet()) { System.out.println(entry.getKey()); System.out.println(tableToCsv(entry.getValue())); } }
From source file:com.aerospike.load.Utils.java
/** * Get list of data file names //from w w w . j av a2s. co m * @param files * @return */ protected static List<String> getFileNames(String[] files) { List<String> allFileNames = new ArrayList<String>(); // Expand directories for (String fileName : files) { File file = new File(fileName); if (!file.exists()) { log.error("File " + fileName + " does not exist"); continue; } if (file.isDirectory()) { File[] subFiles = file.listFiles(new FileFilter() { public boolean accept(File file) { return !file.getName().endsWith("."); } }); for (File subFile : subFiles) { allFileNames.add(subFile.getAbsolutePath()); } } else if (!file.getName().endsWith(".")) { allFileNames.add(file.getAbsolutePath()); } } return allFileNames; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.significance.SignificanceMain.java
/** * Test significance between all methods in the folder and prints them as a CSV table * * @param mainFolder folder/*from w ww.java 2 s . c om*/ * @param folderResultPrefix prefix of folders to test, i.e. "cv_" * @throws IOException */ public static void compareMethods(File mainFolder, final String folderResultPrefix) throws IOException { File[] cvResults = mainFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && pathname.getName().startsWith(folderResultPrefix); } }); Table<String, String, Boolean> table = TreeBasedTable.create(); for (int i = 0; i < cvResults.length; i++) { for (int j = 0; j < cvResults.length; j++) { if (i != j) { File one = cvResults[i]; File two = cvResults[j]; double pValue = TestSignificanceTwoFiles.compareId2OutcomeFiles( new File(one, TOKEN_LEVEL_PREDICTIONS_CSV), new File(two, TOKEN_LEVEL_PREDICTIONS_CSV), new OutcomeSuccessMapReaderSequenceTokenCSVImpl()); // order of methods does not matter List<String> methods = new ArrayList<>(); methods.add(one.getName()); methods.add(two.getName()); Collections.sort(methods); table.put(methods.get(0), methods.get(1), pValue < P_VALUE); // and make symmetric matrix table.put(methods.get(1), methods.get(0), pValue < P_VALUE); } } } System.out.println(tableToCsv(table)); }
From source file:cat.ogasoft.protocolizer.processor.CompilerPhase.java
public static void processCompiler(RoundEnvironment roundEnv) throws CompilerException { try {/*from w w w .j a v a2s . com*/ String protocPath = "src" + File.separatorChar + "cat" + File.separatorChar + "ogasoft" + File.separatorChar + "protocolizer" + File.separatorChar + "protoc"; DefaultExecutor de = new DefaultExecutor(); for (Element element : roundEnv.getElementsAnnotatedWith(ProtoFileV2.Compiler.class)) { ProtoFileV2.Compiler compiler = element.getAnnotation(ProtoFileV2.Compiler.class); if (compiler.compile()) { String base = protocPath.replace('.', File.separatorChar); File dst = new File(base); if (!dst.exists() && !dst.mkdirs()) { throw new Exception("Cann not be created directory " + dst.getAbsolutePath()); } File rootDirectori = new File(base); //Compile all the files in compiler.protoFilePaths() FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".proto"); } }; for (File protoc : rootDirectori.listFiles(filter)) { String target = base + File.separatorChar + protoc.getName(); LOG.info("\tCompiling " + target + "..."); CommandLine cmd = CommandLine.parse(compiler.command() + " --proto_path=" + protocPath + " " + compiler.language().option + "=src " + target); int result = de.execute(cmd); if (result != 0) { throw new CompilerException("HO ho... somthing went wrong, code: " + result); } LOG.info("\t" + target + " compiled"); } } } } catch (Exception e) { //Any exception is a CompilerException. throw new CompilerException(e.getMessage()); } }
From source file:com.doculibre.constellio.plugins.PluginFactory.java
private static void initPluginManager() { if (pm == null) { pm = PluginManagerFactory.createPluginManager(); File classesDir = ClasspathUtils.getClassesDir(); pm.addPluginsFrom(classesDir.toURI()); File pluginsDir = getPluginsDir(); File[] pluginDirs = pluginsDir.listFiles(new FileFilter() { @Override//w ww . j ava 2 s.c o m public boolean accept(File pathname) { boolean accept; if (pathname.isFile()) { accept = false; } else if (DefaultConstellioPlugin.NAME.equals(pathname)) { accept = true; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); accept = availablePluginNames.contains(pathname.getName()); } return accept; } }); if (pluginDirs == null) { return; } for (File pluginDir : pluginDirs) { // Plugin root dir jars Collection<File> pluginJarFiles = FileUtils.listFiles(pluginDir, new String[] { "jar" }, false); // Accept only one root dir jar File pluginJarFile = pluginJarFiles.isEmpty() ? null : pluginJarFiles.iterator().next(); if (pluginJarFile != null) { URI pluginJarFileURI = pluginJarFile.toURI(); pm.addPluginsFrom(pluginJarFileURI); PluginManagerImpl pmImpl = (PluginManagerImpl) pm; ClassPathManager classPathManager = pmImpl.getClassPathManager(); ClassLoader classLoader = ClassPathManagerUtils.getClassLoader(classPathManager, pluginJarFile); classLoaders.add(classLoader); File pluginLibDir = new File(pluginDir, "lib"); if (pluginLibDir.exists() && pluginLibDir.isDirectory()) { Collection<File> pluginDependencies = FileUtils.listFiles(pluginLibDir, new String[] { "jar" }, false); ClassPathManagerUtils.addJarDependencies(classPathManager, pluginJarFile, pluginDependencies); } } } File webInfDir = ClasspathUtils.getWebinfDir(); File libDir = new File(webInfDir, "lib"); File[] contellioJarFiles = libDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean accept; if (pathname.isDirectory()) { accept = false; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName()); accept = availablePluginNames.contains(jarNameWoutExtension); } return accept; } }); for (File constellioJarFile : contellioJarFiles) { URI constellioJarFileURI = constellioJarFile.toURI(); pm.addPluginsFrom(constellioJarFileURI); } } }
From source file:net.shopxx.service.impl.ThemeServiceImpl.java
public List<Theme> getAll() { File[] files = new File(servletContext.getRealPath(themeTemplatePath)).listFiles(new FileFilter() { public boolean accept(File file) { File themeXmlFile = new File(file, "theme.xml"); return themeXmlFile.exists() && themeXmlFile.isFile(); }/*from w w w . j ava 2s . c o m*/ }); List<Theme> themes = new ArrayList<Theme>(); for (File file : files) { File themeXmlFile = new File(file, "theme.xml"); themes.add(get(themeXmlFile)); } return themes; }
From source file:com.googlecode.t7mp.steps.CopySetenvScriptStep.java
@Override public void execute(Context context) { File tomcatConfigDirectory = context.getConfiguration().getTomcatConfigDirectory(); if (tomcatConfigDirectory == null || !tomcatConfigDirectory.exists()) { return;/* ww w .ja v a 2 s . co m*/ } File tomcatDirectory = tomcatConfigDirectory.getParentFile(); File tomcatBinDirectory = new File(tomcatDirectory, "/bin/"); File[] setEnvFiles = tomcatBinDirectory.listFiles(new FileFilter() { @Override public boolean accept(File file) { return (file.isFile() && file.getName().startsWith(PREFIX)); } }); // listFiles returns null if binDirectory does not exist // https://github.com/t7mp/t7mp/issues/28 if (setEnvFiles != null) { for (File scriptFile : setEnvFiles) { try { FileUtils.copyFile(scriptFile, new File(TomcatUtil.getBinDirectory(context.getConfiguration().getCatalinaBase()), scriptFile.getName())); } catch (IOException e) { throw new TomcatSetupException(e.getMessage(), e); } } } }