Class ArgumentParser
java.lang.Object
opennlp.tools.cmdline.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!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfacestatic @interface -
Method Summary
Modifier and TypeMethodDescriptionstatic List<opennlp.tools.cmdline.ArgumentParser.Argument> createArguments(Class<?>... argProxyInterfaces) Outputs the arguments as a data structure, so it can be used to create documentation.static StringcreateUsage(Class<?>... argProxyInterfaces) Creates a usage string which can be printed in case the user did specify the arguments incorrectly.static <T> StringcreateUsage(Class<T> argProxyInterface) Creates a usage string which can be printed in case the user did specify the arguments incorrectly.static <T> String[]Filters arguments leaving only those pertaining toargProxyInterface.static <T> TParses the passed arguments and creates an instance of the proxy interface.static booleanvalidateArguments(String[] args, Class<?>... argProxyInterfaces) Tests if the argument are correct or incorrect.static <T> booleanvalidateArguments(String[] args, Class<T> argProxyInterface) Tests if the argument are correct or incorrect.static StringvalidateArgumentsLoudly(String[] args, Class<?> argProxyInterface) Tests if the arguments are correct or incorrect.static StringvalidateArgumentsLoudly(String[] args, Class<?>... argProxyInterfaces) Tests if the arguments are correct or incorrect.
-
Method Details
-
createUsage
Creates a usage string which can be printed in case the user did specify the arguments incorrectly. Incorrectly is defined asvalidateArguments(String[], Class)returnsfalse.- Parameters:
argProxyInterface- interface with parameter descriptions- Returns:
- the help message usage string
-
createArguments
public static List<opennlp.tools.cmdline.ArgumentParser.Argument> createArguments(Class<?>... argProxyInterfaces) Outputs the arguments as a data structure, so it can be used to create documentation.- Parameters:
argProxyInterfaces- interfaces with parameter descriptions- Returns:
- the help message usage string
-
createUsage
Creates a usage string which can be printed in case the user did specify the arguments incorrectly. Incorrectly is defined asvalidateArguments(String[], Class[])returnsfalse.- Parameters:
argProxyInterfaces- interfaces with parameter descriptions- Returns:
- the help message usage string
-
validateArguments
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 theparse(String[], Class)method and reported accordingly.- Parameters:
args- command line argumentsargProxyInterface- interface with parameters description- Returns:
trueif arguments are valid,false otherwise
-
validateArguments
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 theparse(String[], Class)method and reported accordingly.- Parameters:
args- command line argumentsargProxyInterfaces- interfaces with parameters description- Returns:
trueif arguments are valid,false otherwise
-
validateArgumentsLoudly
Tests if the arguments are correct or incorrect.- Parameters:
args- command line argumentsargProxyInterface- interface with parameters description- Returns:
null, if arguments are valid or error message otherwise
-
validateArgumentsLoudly
Tests if the arguments are correct or incorrect.- Parameters:
args- command line argumentsargProxyInterfaces- interfaces with parameters description- Returns:
null, if arguments are valid or error message otherwise
-
parse
Parses the passed arguments and creates an instance of the proxy interface.In case an argument value cannot be parsed a
TerminateToolExceptionis thrown which contains an error message which explains the problems.- Parameters:
args- argumentsargProxyInterface- interface with parameters description- Returns:
- parsed parameters
- Throws:
TerminateToolException- if an argument value cannot be parsed.IllegalArgumentException- if validateArguments returnsfalse, if the proxy interface is not compatible.
-
filter
Filters arguments leaving only those pertaining toargProxyInterface.- Type Parameters:
T- T- Parameters:
args- argumentsargProxyInterface- interface with parameters description- Returns:
- arguments pertaining to
argProxyInterface
-