opennlp.tools.cmdline.ArgumentParser类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(65)

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

ArgumentParser介绍

[英]Parser for command line arguments. The parser creates a dynamic proxy which can be access via a command line argument interface.

The command line argument proxy interface must follow these conventions:

  • Methods do not define arguments
  • Method names must start with get
  • Allowed return types are Integer, Boolean, String, File and Charset.

Note: Do not use this class, internal use only!
[中]命令行参数的解析器。解析器创建一个可以通过命令行参数接口访问的动态代理。
命令行参数代理接口必须遵循以下约定:
-方法不定义参数
-方法名称必须以get开头
-允许的返回类型有整数、布尔值、字符串、文件和字符集。
注意:请勿使用此类,仅限内部使用!

代码示例

代码示例来源:origin: apache/opennlp

public ObjectStream<POSSample> create(String[] args) {
 ParseSampleStreamFactory.Parameters params =
   ArgumentParser.parse(args, ParseSampleStreamFactory.Parameters.class);
 ObjectStream<Parse> parseSampleStream = StreamFactoryRegistry.getFactory(Parse.class,
   StreamFactoryRegistry.DEFAULT_FORMAT).create(
   ArgumentParser.filter(args, ParseSampleStreamFactory.Parameters.class));
 return new ParseToPOSSampleStream(parseSampleStream);
}

代码示例来源:origin: apache/opennlp

/**
 * Creates a usage string which can be printed in case the user did specify the arguments
 * incorrectly. Incorrectly is defined as {@link ArgumentParser#validateArguments(String[], Class)}
 * returns false.
 *
 * @param argProxyInterface interface with parameter descriptions
 * @return the help message usage string
 */
@SuppressWarnings({"unchecked"})
public static <T> String createUsage(Class<T> argProxyInterface) {
 return createUsage(new Class[]{argProxyInterface});
}

代码示例来源:origin: apache/opennlp

@Test(expected = IllegalArgumentException.class)
public void testAllOptionalArgumentsExtraArgument() {
 String argsString = "-encoding UTF-8";
 Assert.assertFalse(ArgumentParser.validateArguments(argsString.split(" "), AllOptionalArguments.class));
 ArgumentParser.parse(argsString.split(" "), AllOptionalArguments.class);
}

代码示例来源:origin: apache/opennlp

protected <T> T validateAndParseParams(String[] args, Class<T> argProxyInterface) {
 String errorMessage = ArgumentParser.validateArgumentsLoudly(args, argProxyInterface);
 if (null != errorMessage) {
  throw new TerminateToolException(1, errorMessage + "\n" + getHelp());
 }
 return ArgumentParser.parse(args, argProxyInterface);
}

代码示例来源:origin: apache/opennlp

/**
 * Validates arguments for a format processed by the <code>factory</code>.
 * @param factory a stream factory
 * @param args arguments
 */
protected void validateFactoryArgs(ObjectStreamFactory<T> factory, String[] args) {
 String errMessage = ArgumentParser.validateArgumentsLoudly(args, factory.getParameters());
 if (null != errMessage) {
  throw new TerminateToolException(1, "Format parameters are invalid: " + errMessage + "\n" +
    "Usage: " + ArgumentParser.createUsage(factory.getParameters()));
 }
}

代码示例来源:origin: apache/opennlp

public ObjectStream<NameSample> create(String[] args) {
 Parameters params = ArgumentParser.parse(args, Parameters.class);
 TokenizerModel tokenizerModel = new TokenizerModelLoader().load(params.getTokenizerModel());
 Tokenizer tokenizer = new TokenizerME(tokenizerModel);
 ObjectStream<String> mucDocStream = new FileToStringSampleStream(
   new DirectorySampleStream(params.getData(),
     file -> StringUtil.toLowerCase(file.getName()).endsWith(".sgm"), false),
   StandardCharsets.UTF_8);
 return new MucNameSampleStream(tokenizer, mucDocStream);
}

代码示例来源:origin: edu.usc.ir/age-predictor-cli

@Override
public void run(String[] args) {
String errMessage = ArgumentParser.validateArgumentsLoudly(args, this.paramsClass);
if (null != errMessage) {
  throw new TerminateToolException(1, errMessage + "\n" + getHelp());
  .getOrCreate();
params = (PredictTrainingToolParams) ArgumentParser.parse(
  ArgumentParser.filter(args, this.paramsClass), this.paramsClass);

代码示例来源:origin: apache/opennlp

public static <T> T parse(String[] args, Class<T> argProxyInterface) {
 checkProxyInterfaces(argProxyInterface);
 if (!validateArguments(args, argProxyInterface))
  throw new IllegalArgumentException("Passed args must be valid!");
  String parameterName = methodNameToParameter(method.getName());
  String valueString = CmdLineUtil.getParameter(parameterName, args);

代码示例来源:origin: apache/opennlp

/**
 * Tests if the argument are correct or incorrect. Incorrect means, that mandatory arguments are missing or
 * there are unknown arguments. The argument value itself can also be incorrect, but this
 * is checked by the {@link ArgumentParser#parse(String[], Class)} method and reported accordingly.
 *
 * @param args command line arguments
 * @param argProxyInterfaces interfaces with parameters description
 * @return true, if arguments are valid
 */
public static boolean validateArguments(String[] args, Class<?>... argProxyInterfaces) {
 return null == validateArgumentsLoudly(args, argProxyInterfaces);
}

代码示例来源:origin: apache/opennlp

checkProxyInterfaces(argProxyInterfaces);
    String paramName = methodNameToParameter(method.getName());

代码示例来源:origin: apache/opennlp

/**
 * Tests if the argument are correct or incorrect. Incorrect means, that mandatory arguments are missing or
 * there are unknown arguments. The argument value itself can also be incorrect, but this
 * is checked by the {@link ArgumentParser#parse(String[], Class)} method and reported accordingly.
 *
 * @param args command line arguments
 * @param argProxyInterface interface with parameters description
 * @return true, if arguments are valid
 */
@SuppressWarnings({"unchecked"})
public static <T> boolean validateArguments(String[] args, Class<T> argProxyInterface) {
 return validateArguments(args, new Class[]{argProxyInterface});
}

代码示例来源:origin: apache/opennlp

public final void run(String format, String[] args) {
 ModelUpdaterParams params = validateAndParseParams(
   ArgumentParser.filter(args, ModelUpdaterParams.class), ModelUpdaterParams.class);
 String[] fargs = ArgumentParser.filter(args, factory.getParameters());
 validateFactoryArgs(factory, fargs);
 ObjectStream<Parse> sampleStream = factory.create(fargs);

代码示例来源:origin: apache/opennlp

private static void appendHelpForTool(TypedCmdLineTool<?> tool,
  StringBuilder sb) {
 Class<?> type = tool.type;
 Set<String> formats = StreamFactoryRegistry.getFactories(type).keySet();
 sb.append("<para>The supported formats and arguments are:</para>\n\n");
 Map<String, List<Argument>> formatArguments = new LinkedHashMap<>();
 for (String formatName : formats) {
  if (!StreamFactoryRegistry.DEFAULT_FORMAT.equals(formatName)) {
   ObjectStreamFactory<?> format = tool.getStreamFactory(formatName);
   formatArguments.put(formatName,
     ArgumentParser.createArguments(format.getParameters()));
  }
 }
 appendArgumentTable(formatArguments, sb);
}

代码示例来源:origin: apache/opennlp

public ObjectStream<TokenSample> create(String[] args) {

  Parameters params = ArgumentParser.parse(args, Parameters.class);

  CmdLineUtil.checkInputFile("Data", params.getData());

  IrishSentenceBankDocument isbDoc = null;
  try {
   isbDoc = IrishSentenceBankDocument.parse(params.getData());
  } catch (IOException ex) {
   CmdLineUtil.handleCreateObjectStreamError(ex);
  }

  return new IrishSentenceBankTokenSampleStream(isbDoc);
 }
}

代码示例来源:origin: apache/opennlp

System.arraycopy(args, 1, formatArgs, 0, formatArgs.length);
String helpString = createHelpString(format, ArgumentParser.createUsage(streamFactory.getParameters()));
if (0 == formatArgs.length || (1 == formatArgs.length && "help".equals(formatArgs[0]))) {
 System.out.println(helpString);
String errorMessage = ArgumentParser.validateArgumentsLoudly(formatArgs, streamFactory.getParameters());
if (null != errorMessage) {
 throw new TerminateToolException(1, errorMessage + "\n" + helpString);

代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3

protected <T> T validateAndParseParams(String[] args, Class<T> argProxyInterface) {
 String errorMessage = ArgumentParser.validateArgumentsLoudly(args, argProxyInterface);
 if (null != errorMessage) {
  throw new TerminateToolException(1, errorMessage + "\n" + getHelp());
 }
 return ArgumentParser.parse(args, argProxyInterface);
}

代码示例来源:origin: org.apache.opennlp/opennlp-tools

public static <T> T parse(String[] args, Class<T> argProxyInterface) {
 checkProxyInterfaces(argProxyInterface);
 if (!validateArguments(args, argProxyInterface))
  throw new IllegalArgumentException("Passed args must be valid!");
  String parameterName = methodNameToParameter(method.getName());
  String valueString = CmdLineUtil.getParameter(parameterName, args);

代码示例来源:origin: apache/opennlp

/**
 * Tests if the arguments are correct or incorrect.
 *
 * @param args command line arguments
 * @param argProxyInterface interface with parameters description
 * @return null, if arguments are valid or error message otherwise
 */
public static String validateArgumentsLoudly(String[] args, Class<?> argProxyInterface) {
 return validateArgumentsLoudly(args, new Class[]{argProxyInterface});
}

代码示例来源:origin: apache/opennlp

checkProxyInterfaces(argProxyInterfaces);
    String paramName = methodNameToParameter(method.getName());

代码示例来源:origin: org.apache.opennlp/opennlp-tools

/**
 * Tests if the argument are correct or incorrect. Incorrect means, that mandatory arguments are missing or
 * there are unknown arguments. The argument value itself can also be incorrect, but this
 * is checked by the {@link ArgumentParser#parse(String[], Class)} method and reported accordingly.
 *
 * @param args command line arguments
 * @param argProxyInterface interface with parameters description
 * @return true, if arguments are valid
 */
@SuppressWarnings({"unchecked"})
public static <T> boolean validateArguments(String[] args, Class<T> argProxyInterface) {
 return validateArguments(args, new Class[]{argProxyInterface});
}

相关文章