本文整理汇总了Java中opennlp.tools.cmdline.BasicCmdLineTool类的典型用法代码示例。如果您正苦于以下问题:Java BasicCmdLineTool类的具体用法?Java BasicCmdLineTool怎么用?Java BasicCmdLineTool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicCmdLineTool类属于opennlp.tools.cmdline包,在下文中一共展示了BasicCmdLineTool类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import opennlp.tools.cmdline.BasicCmdLineTool; //导入依赖的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);
}
示例2: main
import opennlp.tools.cmdline.BasicCmdLineTool; //导入依赖的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());
}
}
示例3: main
import opennlp.tools.cmdline.BasicCmdLineTool; //导入依赖的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];
String formatName = 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());
}
}