当前位置: 首页>>代码示例>>Java>>正文


Java TerminateToolException类代码示例

本文整理汇总了Java中opennlp.tools.cmdline.TerminateToolException的典型用法代码示例。如果您正苦于以下问题:Java TerminateToolException类的具体用法?Java TerminateToolException怎么用?Java TerminateToolException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TerminateToolException类属于opennlp.tools.cmdline包,在下文中一共展示了TerminateToolException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
public void run(String[] args) {
  Params params = validateAndParseParams(args, Params.class);

  File dictInFile = params.getInputFile();

  CmdLineUtil.checkInputFile("dictionary input file", dictInFile);
  Path metadataPath = DictionaryMetadata.getExpectedMetadataLocation(dictInFile.toPath());
  CmdLineUtil.checkInputFile("dictionary metadata (.info) input file", metadataPath.toFile());

  MorfologikDictionayBuilder builder = new MorfologikDictionayBuilder();
  try {
    builder.build(dictInFile.toPath(), params.getOverwrite(),
        params.getValidate(), params.getAcceptBOM(), params.getAcceptCR(),
        params.getIgnoreEmpty());
  } catch (Exception e) {
    throw new TerminateToolException(-1,
        "Error while creating Morfologik POS Dictionay: " + e.getMessage(), e);
  }

}
 
开发者ID:apache,项目名称:opennlp-addons,代码行数:21,代码来源:MorfologikDictionaryBuilderTool.java

示例2: main

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length < 2) {
    System.out.println("usage: <input> <output>\n");
    System.exit(0);
}

String input = args[0];
String output = args[1];

TrainingParameters params = new TrainingParameters();
params.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));
params.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(100));
//params.put(TrainingParameters.ALGORITHM_PARAM, NaiveBayesTrainer.NAIVE_BAYES_VALUE);

AgeClassifyModel model;
try {
    model = AgeClassifySparkTrainer.createModel("en", input, 
        "opennlp.tools.tokenize.SentenceTokenizer", "opennlp.tools.tokenize.BagOfWordsTokenizer", params);
} catch (IOException e) {
    throw new TerminateToolException(-1,
        "IO error while reading training data or indexing data: " + e.getMessage(), e);
}
CmdLineUtil.writeModel("age classifier", new File(output), model);
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:25,代码来源:AgeClassifySparkTrainer.java

示例3: getHelp

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
@Override
   @SuppressWarnings({"unchecked"})
   public String getHelp(String format) {
if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) {
    return getBasicHelp(paramsClass,
		 StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT)
		 .<PredictEvalToolParams>getParameters());
} else {
    ObjectStreamFactory<AuthorAgeSample> factory = StreamFactoryRegistry.getFactory(type, format);
    if (null == factory) {
 throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp());
    }
    return "Usage: " + CLI.CMD + " " + getName() + " " +
 ArgumentParser.createUsage(paramsClass, factory.<PredictEvalToolParams>getParameters());
}
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:17,代码来源:AgePredictEvaluatorTool.java

示例4: run

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
public void run(String format, String[] args) {
validateAllArgs(args, this.paramsClass, format);

SparkSession spark = SparkSession
    .builder()
    .appName("AgePredictEvaluator")
    .getOrCreate();

params = ArgumentParser.parse(ArgumentParser.filter(args, this.paramsClass), this.paramsClass);

try {
    AgePredictEvaluator.evaluate(spark, params.getClassifyModel(), params.getModel(), 
			  params.getReport(), params.getData());
} catch (IOException e) {
    System.err.println("failed");
    throw new TerminateToolException(-1, "IO error while reading test data: "
			      + e.getMessage(), e);
}

   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:21,代码来源:AgePredictEvaluatorTool.java

示例5: getHelp

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
@Override
   @SuppressWarnings({"unchecked"})
   public String getHelp(String format) {
if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) {
    return getBasicHelp(paramsClass,
			StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT)
			.<SparkTrainingToolParams>getParameters());
} else {
    ObjectStreamFactory<AuthorAgeSample> factory = StreamFactoryRegistry.getFactory(type, format);
    if (null == factory) {
	throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp());
    }
    return "Usage: " + CLI.CMD + " " + getName() + " " +
	ArgumentParser.createUsage(paramsClass, factory.<SparkTrainingToolParams>getParameters());
}
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:17,代码来源:AgeClassifySparkTrainerTool.java

示例6: getHelp

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
@Override
   @SuppressWarnings({"unchecked"})
   public String getHelp(String format) {
if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) {
    return getBasicHelp(paramsClass,
		 StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT)
		 .<SparkEvalToolParams>getParameters());
} else {
    ObjectStreamFactory<AuthorAgeSample> factory = StreamFactoryRegistry.getFactory(type, format);
    if (null == factory) {
 throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp());
    }
    return "Usage: " + CLI.CMD + " " + getName() + " " +
 ArgumentParser.createUsage(paramsClass, factory.<SparkEvalToolParams>getParameters());
}
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:17,代码来源:AgeClassifySparkEvaluatorTool.java

示例7: getHelp

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
@Override
   @SuppressWarnings({"unchecked"})
   public String getHelp(String format) {
if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) {
    return getBasicHelp(paramsClass,
			StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT)
			.<ClassifyTrainingToolParams>getParameters());
} else {
    ObjectStreamFactory<AuthorAgeSample> factory = StreamFactoryRegistry.getFactory(type, format);
    if (null == factory) {
	throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp());
    }
    return "Usage: " + CLI.CMD + " " + getName() + " " +
	ArgumentParser.createUsage(paramsClass, factory.<ClassifyTrainingToolParams>getParameters());
}
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:17,代码来源:AgeClassifyTrainerTool.java

示例8: getHelp

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
@Override
   @SuppressWarnings({"unchecked"})
   public String getHelp(String format) {
if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) {
    return getBasicHelp(paramsClass,
			StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT)
			.<EvalToolParams>getParameters());
} else {
    ObjectStreamFactory<AuthorAgeSample> factory = StreamFactoryRegistry.getFactory(type, format);
    if (null == factory) {
	throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp());
    }
    return "Usage: " + CLI.CMD + " " + getName() + " " +
	ArgumentParser.createUsage(paramsClass, factory.<EvalToolParams>getParameters());
}
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:17,代码来源:AgeClassifyEvaluatorTool.java

示例9: createAutomaticDictionary

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
/**
 * Automatically create a tag dictionary from training data.
 * 
 * @param aDictSamples
 *          the dictSamples created from training data
 * @param aDictCutOff
 *          the cutoff to create the dictionary
 */
protected final void createAutomaticDictionary(
    final ObjectStream<POSSample> aDictSamples, final int aDictCutOff) {
  if (aDictCutOff != Flags.DEFAULT_DICT_CUTOFF) {
    try {
      TagDictionary dict = getPosTaggerFactory().getTagDictionary();
      if (dict == null) {
        dict = getPosTaggerFactory().createEmptyTagDictionary();
        getPosTaggerFactory().setTagDictionary(dict);
      }
      if (dict instanceof MutableTagDictionary) {
        POSTaggerME.populatePOSDictionary(aDictSamples,
            (MutableTagDictionary) dict, aDictCutOff);
      } else {
        throw new IllegalArgumentException("Can't extend a POSDictionary"
            + " that does not implement MutableTagDictionary.");
      }
      this.dictSamples.reset();
    } catch (final IOException e) {
      throw new TerminateToolException(-1,
          "IO error while creating/extending POS Dictionary: "
              + e.getMessage(), e);
    }
  }
}
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:33,代码来源:AbstractTaggerTrainer.java

示例10: checkInputFile

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
/**
 * Check input file integrity.
 * 
 * @param name
 *          the name of the file
 * @param inFile
 *          the file
 */
private static void checkInputFile(final String name, final File inFile) {

  String isFailure = null;

  if (inFile.isDirectory()) {
    isFailure = "The " + name + " file is a directory!";
  } else if (!inFile.exists()) {
    isFailure = "The " + name + " file does not exist!";
  } else if (!inFile.canRead()) {
    isFailure = "No permissions to read the " + name + " file!";
  }

  if (null != isFailure) {
    throw new TerminateToolException(-1, isFailure + " Path: "
        + inFile.getAbsolutePath());
  }
}
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:26,代码来源:InputOutputUtils.java

示例11: checkInputFile

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
/**
 * Check input file integrity.
 * @param name
 *          the name of the file
 * @param inFile
 *          the file
 */
private static void checkInputFile(final String name, final File inFile) {

  String isFailure = null;
  if (inFile.isDirectory()) {
    isFailure = "The " + name + " file is a directory!";
  } else if (!inFile.exists()) {
    isFailure = "The " + name + " file does not exist!";
  } else if (!inFile.canRead()) {
    isFailure = "No permissions to read the " + name + " file!";
  }
  if (null != isFailure) {
    throw new TerminateToolException(-1, isFailure + " Path: "
        + inFile.getAbsolutePath());
  }
}
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-chunk,代码行数:23,代码来源:InputOutputUtils.java

示例12: run

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
public void run(String format, String[] args) {
validateAllArgs(args, this.paramsClass, format);

params = ArgumentParser.parse(ArgumentParser.filter(args, this.paramsClass), this.paramsClass);
try {
    AgeClassifySparkEvaluator.evaluate(params.getModel(), params.getData());
    
} catch (IOException e) {
    System.err.println("failed");
    throw new TerminateToolException(-1, "IO error while reading test data: "
			      + e.getMessage(), e);
}


   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:16,代码来源:AgeClassifySparkEvaluatorTool.java

示例13: createTagDictionary

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
/**
 * Create a tag dictionary with the dictionary contained in the dictPath.
 * 
 * @param dictPath
 *          the string pointing to the tag dictionary
 */
protected final void createTagDictionary(final String dictPath) {
  if (!dictPath.equalsIgnoreCase(Flags.DEFAULT_DICT_PATH)) {
    try {
      getPosTaggerFactory().setTagDictionary(
          getPosTaggerFactory().createTagDictionary(new File(dictPath)));
    } catch (final IOException e) {
      throw new TerminateToolException(-1,
          "IO error while loading POS Dictionary: " + e.getMessage(), e);
    }
  }
}
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:18,代码来源:AbstractTaggerTrainer.java

示例14: main

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
public static void main(String[] args) {

    if (args.length == 0) {
      usage();
      System.exit(0);
    }

    String toolArguments[] = new String[args.length -1];
    System.arraycopy(args, 1, toolArguments, 0, toolArguments.length);

    String toolName = args[0];

    //check for format
    String formatName = StreamFactoryRegistry.DEFAULT_FORMAT;
    int idx = toolName.indexOf(".");
    if (-1 < idx) {
      formatName = toolName.substring(idx + 1);
      toolName = toolName.substring(0, idx);
    }
    CmdLineTool tool = toolLookupMap.get(toolName);

    try {
      if (null == tool) {
        throw new TerminateToolException(1, "Tool " + toolName + " is not found.");
      }

      if ((0 == toolArguments.length && tool.hasParams()) ||
          0 < toolArguments.length && "help".equals(toolArguments[0])) {
          if (tool instanceof TypedCmdLineTool) {
            System.out.println(((TypedCmdLineTool) tool).getHelp(formatName));
          } else if (tool instanceof BasicCmdLineTool) {
            System.out.println(tool.getHelp());
          }

          System.exit(0);
      }

      if (tool instanceof TypedCmdLineTool) {
        ((TypedCmdLineTool) tool).run(formatName, toolArguments);
      } else if (tool instanceof BasicCmdLineTool) {
        if (-1 == idx) {
          ((BasicCmdLineTool) tool).run(toolArguments);
        } else {
          throw new TerminateToolException(1, "Tool " + toolName + " does not support formats.");
        }
      } else {
        throw new TerminateToolException(1, "Tool " + toolName + " is not supported.");
      }
    }
    catch (TerminateToolException e) {

      if (e.getMessage() != null) {
        System.err.println(e.getMessage());
      }

      if (e.getCause() != null) {
        System.err.println(e.getCause().getMessage());
        e.getCause().printStackTrace(System.err);
      }

      System.exit(e.getCode());
    }
    
    System.out.println("Completed!");
    System.exit(1);
  }
 
开发者ID:datancoffee,项目名称:sirocco,代码行数:67,代码来源:CLI.java

示例15: main

import opennlp.tools.cmdline.TerminateToolException; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
 public static void main(String[] args) {

  if (args.length == 0) {
    usage();
    System.exit(0);
  }

  String toolArguments[] = new String[args.length -1];
  System.arraycopy(args, 1, toolArguments, 0, toolArguments.length);

  String toolName = args[0];

  //check for format
  String formatName = StreamFactoryRegistry.DEFAULT_FORMAT;
  int idx = toolName.indexOf(".");
  if (-1 < idx) {
    formatName = toolName.substring(idx + 1);
    toolName = toolName.substring(0, idx);
  }
  CmdLineTool tool = toolLookupMap.get(toolName);

  try {
    if (null == tool) {
      throw new TerminateToolException(1, "Tool " + toolName + " is not found.");
    }

    if ((0 == toolArguments.length && tool.hasParams()) ||
        0 < toolArguments.length && "help".equals(toolArguments[0])) {
        if (tool instanceof TypedCmdLineTool) {
          System.out.println(((TypedCmdLineTool) tool).getHelp(formatName));
        } else if (tool instanceof BasicCmdLineTool) {
          System.out.println(tool.getHelp());
        }

        System.exit(0);
    }

    if (tool instanceof TypedCmdLineTool) {
      ((TypedCmdLineTool) tool).run(formatName, toolArguments);
    } else if (tool instanceof BasicCmdLineTool) {
      if (-1 == idx) {
        ((BasicCmdLineTool) tool).run(toolArguments);
      } else {
        throw new TerminateToolException(1, "Tool " + toolName + " does not support formats.");
      }
    } else {
      throw new TerminateToolException(1, "Tool " + toolName + " is not supported.");
    }
  }
  catch (TerminateToolException e) {

    if (e.getMessage() != null) {
      System.err.println(e.getMessage());
    }

    if (e.getCause() != null) {
      System.err.println(e.getCause().getMessage());
      e.getCause().printStackTrace(System.err);
    }

    System.exit(e.getCode());
  }
}
 
开发者ID:apache,项目名称:opennlp-addons,代码行数:65,代码来源:CLI.java


注:本文中的opennlp.tools.cmdline.TerminateToolException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。