edu.illinois.cs.cogcomp.core.io.IOUtils.isDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中edu.illinois.cs.cogcomp.core.io.IOUtils.isDirectory()方法的一些代码示例,展示了IOUtils.isDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.isDirectory()方法的具体详情如下:
包路径:edu.illinois.cs.cogcomp.core.io.IOUtils
类名称:IOUtils
方法名:isDirectory

IOUtils.isDirectory介绍

[英]Check if the argument is a directory.
[中]检查参数是否为目录。

代码示例

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * 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();
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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();
}

代码示例来源:origin: CogComp/cogcomp-nlp

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();
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * 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()]);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * 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);
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

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();
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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()]);
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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);
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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()]);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * 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()]);
}

代码示例来源:origin: CogComp/cogcomp-nlp

@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());
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-corpusreaders

@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());
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

if (!IOUtils.isDirectory(ontonotesDirectory)) {
  files = new String[] {ontonotesDirectory};
} else {

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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);
    }
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * 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);
    }
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-edison

/**
 * 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);
    }
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-edison

/**
 * 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);
    }
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-corpusreaders

if (!IOUtils.isDirectory(conllDir)) {
  System.err.println("Output directory '" + conllDir
      + "' exists and is not a directory.");

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-verbsense

@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());
}

代码示例来源:origin: CogComp/cogcomp-nlp

@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());
}

相关文章