/** * List the contents of a directory. NOTE: Order of list is not guaranteed to be consistent across runs/machines. */ public static String[] ls(String directory) throws IOException { if (!isDirectory(directory)) { throw new IOException("Invalid directory! " + directory); } return (new File(directory)).list(); }
/** * List the contents of a directory. NOTE: Order of list is not guaranteed to be consistent across runs/machines. */ public static String[] ls(String directory) throws IOException { if (!isDirectory(directory)) { throw new IOException("Invalid directory! " + directory); } return (new File(directory)).list(); }
public static boolean rmDir(String directory) throws IOException { if (!exists(directory)) return false; if (!isDirectory(directory)) throw new IOException(directory + " is not a directory!"); return (new File(directory)).delete(); }
/** * List the directories contained within a directory. */ public static String[] lsDirectories(String directory) throws Exception { String[] tmp = ls(directory); ArrayList<String> files = new ArrayList<>(); for (String s : tmp) { if (isDirectory(directory + File.separator + s)) files.add(s); } return files.toArray(new String[files.size()]); }
/** * Create a directory, if it does not exist. */ public static boolean mkdir(String dir) { if (!exists(dir)) { return (new File(dir)).mkdirs(); } else { return isDirectory(dir); } }
public static boolean rmDir(String directory) throws IOException { if (!exists(directory)) return false; if (!isDirectory(directory)) throw new IOException(directory + " is not a directory!"); return (new File(directory)).delete(); }
/** * List the directories contained within a directory. */ public static String[] lsDirectories(String directory) throws Exception { String[] tmp = ls(directory); ArrayList<String> files = new ArrayList<>(); for (String s : tmp) { if (isDirectory(directory + File.separator + s)) files.add(s); } return files.toArray(new String[files.size()]); }
/** * Create a directory, if it does not exist. */ public static boolean mkdir(String dir) { if (!exists(dir)) { return (new File(dir)).mkdirs(); } else { return isDirectory(dir); } }
/** * Filters the files contained in a directory or in its subdirectory structure. Returns all * files (not directories) that pass the filter. */ public static String[] lsFilesRecursive(String directory, FilenameFilter filter) throws IOException { File dir = new File(directory); ArrayList<String> files = new ArrayList<>(); for (File filepath : dir.listFiles(filter)) { if (isFile(filepath.getAbsolutePath())) files.add(filepath.getAbsolutePath()); else if (isDirectory(filepath.getAbsolutePath())) files.addAll(Arrays.asList(lsFilesRecursive(filepath.getAbsolutePath(), filter))); } return files.toArray(new String[files.size()]); }
/** * Filters the files contained in a directory or in its subdirectory structure. Returns all * files (not directories) that pass the filter. */ public static String[] lsFilesRecursive(String directory, FilenameFilter filter) throws IOException { File dir = new File(directory); ArrayList<String> files = new ArrayList<>(); for (File filepath : dir.listFiles(filter)) { if (isFile(filepath.getAbsolutePath())) files.add(filepath.getAbsolutePath()); else if (isDirectory(filepath.getAbsolutePath())) files.addAll(Arrays.asList(lsFilesRecursive(filepath.getAbsolutePath(), filter))); } return files.toArray(new String[files.size()]); }
@Override protected void initializeReader() { String[] files = new String[0]; this.textAnnotations = new ArrayList<>(); String corpusdirectory = this.resourceManager.getString(CorpusReaderConfigurator.SOURCE_DIRECTORY.key); // In case the input argument is a single file if (!IOUtils.isDirectory(corpusdirectory)) { files = new String[] {corpusdirectory}; } else { try { files = IOUtils.ls(corpusdirectory); Arrays.sort(files); for (int i = 0; i < files.length; i++) { files[i] = Paths.get(corpusdirectory, files[i]).toString(); } } catch (IOException e) { logger.error("Error listing directory."); logger.error(e.getMessage()); } } try { for (String file : files) { textAnnotations.add(loadCoNLLfile(file)); } } catch (IOException e) { logger.error("Error reading file."); logger.error(e.getMessage()); } }
@Override protected void initializeReader() { String[] files = new String[0]; this.textAnnotations = new ArrayList<>(); String corpusdirectory = this.resourceManager.getString(CorpusReaderConfigurator.SOURCE_DIRECTORY.key); // In case the input argument is a single file if (!IOUtils.isDirectory(corpusdirectory)) { files = new String[] {corpusdirectory}; } else { try { files = IOUtils.ls(corpusdirectory); Arrays.sort(files); for (int i = 0; i < files.length; i++) { files[i] = Paths.get(corpusdirectory, files[i]).toString(); } } catch (IOException e) { logger.error("Error listing directory."); logger.error(e.getMessage()); } } try { for (String file : files) { textAnnotations.add(loadCoNLLfile(file)); } } catch (IOException e) { logger.error("Error reading file."); logger.error(e.getMessage()); } }
if (!IOUtils.isDirectory(ontonotesDirectory)) { files = new String[] {ontonotesDirectory}; } else {
/** * A table is built from either a given source corpus file or source corpus directory by simply * counting the number of times that each form-POS association appear in a source corpus. * * @param home file name or directory name of the source corpus * @throws Exception **/ public void buildTable(String home) throws Exception { if (IOUtils.isFile(home)) this.buildTableHelper(home); else if (IOUtils.isDirectory(home)) { String[] files = IOUtils.lsFiles(home); for (String file : files) { // logger.info(file); this.buildTableHelper(home + "\\" + file); } } }
/** * A table is built from either a given source corpus file or source corpus directory by * counting the number of times that each suffix-POS association in a source corpus. * * @param home file name or directory name of the source corpus * @throws Exception **/ public void buildTable(String home) throws Exception { if (IOUtils.isFile(home)) this.buildTableHelper(home); else if (IOUtils.isDirectory(home)) { String[] files = IOUtils.lsFiles(home); for (String file : files) { // logger.info(file); this.buildTableHelper(home + "\\" + file); } } }
/** * A table is built from either a given source corpus file or source corpus directory by * counting the number of times that each suffix-POS association in a source corpus. * * @param home file name or directory name of the source corpus * @throws Exception **/ public void buildTable(String home) throws Exception { if (IOUtils.isFile(home)) this.buildTableHelper(home); else if (IOUtils.isDirectory(home)) { String[] files = IOUtils.lsFiles(home); for (String file : files) { // logger.info(file); this.buildTableHelper(home + "\\" + file); } } }
/** * A table is built from either a given source corpus file or source corpus directory by simply * counting the number of times that each form-POS association appear in a source corpus. * * @param home file name or directory name of the source corpus * @throws Exception **/ public void buildTable(String home) throws Exception { if (IOUtils.isFile(home)) this.buildTableHelper(home); else if (IOUtils.isDirectory(home)) { String[] files = IOUtils.lsFiles(home); for (String file : files) { // logger.info(file); this.buildTableHelper(home + "\\" + file); } } }
if (!IOUtils.isDirectory(conllDir)) { System.err.println("Output directory '" + conllDir + "' exists and is not a directory.");
@CommandDescription( description = "Pre-extracts the features for the verb-sense model. Run this before training.", usage = "preExtract") public static void preExtract() throws Exception { SenseManager manager = getManager(true); ResourceManager conf = new VerbSenseConfigurator().getDefaultConfig(); // If models directory doesn't exist create it if (!IOUtils.isDirectory(conf.getString(conf .getString(VerbSenseConfigurator.MODELS_DIRECTORY)))) IOUtils.mkdir(conf.getString(conf.getString(VerbSenseConfigurator.MODELS_DIRECTORY))); int numConsumers = Runtime.getRuntime().availableProcessors(); Dataset dataset = Dataset.PTBTrainDev; log.info("Pre-extracting features"); ModelInfo modelInfo = manager.getModelInfo(); String featureSet = "" + modelInfo.featureManifest.getIncludedFeatures().hashCode(); String allDataCacheFile = VerbSenseConfigurator.getFeatureCacheFile(featureSet, dataset, rm); FeatureVectorCacheFile featureCache = preExtract(numConsumers, manager, dataset, allDataCacheFile); pruneFeatures(numConsumers, manager, featureCache, VerbSenseConfigurator.getPrunedFeatureCacheFile(featureSet, rm)); Lexicon lexicon = modelInfo.getLexicon().getPrunedLexicon(manager.getPruneSize()); log.info("Saving lexicon with {} features to {}", lexicon.size(), manager.getLexiconFileName()); log.info(lexicon.size() + " features in the lexicon"); lexicon.save(manager.getLexiconFileName()); }
@CommandDescription( description = "Pre-extracts the features for the verb-sense model. Run this before training.", usage = "preExtract") public static void preExtract() throws Exception { SenseManager manager = getManager(true); ResourceManager conf = new VerbSenseConfigurator().getDefaultConfig(); // If models directory doesn't exist create it if (!IOUtils.isDirectory(conf.getString(conf .getString(VerbSenseConfigurator.MODELS_DIRECTORY)))) IOUtils.mkdir(conf.getString(conf.getString(VerbSenseConfigurator.MODELS_DIRECTORY))); int numConsumers = Runtime.getRuntime().availableProcessors(); Dataset dataset = Dataset.PTBTrainDev; log.info("Pre-extracting features"); ModelInfo modelInfo = manager.getModelInfo(); String featureSet = "" + modelInfo.featureManifest.getIncludedFeatures().hashCode(); String allDataCacheFile = VerbSenseConfigurator.getFeatureCacheFile(featureSet, dataset, rm); FeatureVectorCacheFile featureCache = preExtract(numConsumers, manager, dataset, allDataCacheFile); pruneFeatures(numConsumers, manager, featureCache, VerbSenseConfigurator.getPrunedFeatureCacheFile(featureSet, rm)); Lexicon lexicon = modelInfo.getLexicon().getPrunedLexicon(manager.getPruneSize()); log.info("Saving lexicon with {} features to {}", lexicon.size(), manager.getLexiconFileName()); log.info(lexicon.size() + " features in the lexicon"); lexicon.save(manager.getLexiconFileName()); }