本文整理汇总了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);
}
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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());
}
}