Fixed bm25() UDF for help message
diff --git a/core/src/main/java/hivemall/UDFWithOptions.java b/core/src/main/java/hivemall/UDFWithOptions.java
index 04d6fdc..89e7662 100644
--- a/core/src/main/java/hivemall/UDFWithOptions.java
+++ b/core/src/main/java/hivemall/UDFWithOptions.java
@@ -89,29 +89,46 @@
CommandLine cl = CommandLineUtils.parseOptions(args, opts);
if (cl.hasOption("help")) {
- Description funcDesc = getClass().getAnnotation(Description.class);
- final String cmdLineSyntax;
- if (funcDesc == null) {
- cmdLineSyntax = getClass().getSimpleName();
- } else {
- String funcName = funcDesc.name();
- cmdLineSyntax = funcName == null ? getClass().getSimpleName()
- : funcDesc.value().replace("_FUNC_", funcDesc.name());
- }
- StringWriter sw = new StringWriter();
- sw.write('\n');
- PrintWriter pw = new PrintWriter(sw);
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
- HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
- pw.flush();
- String helpMsg = sw.toString();
- throw new UDFArgumentException(helpMsg);
+ showHelp(opts);
}
return cl;
}
+ protected void showHelp(@Nullable String errMsg) throws UDFArgumentException {
+ showHelp(getOptions(), errMsg);
+ }
+
+ private void showHelp(@Nonnull Options opts) throws UDFArgumentException {
+ showHelp(getOptions(), null);
+ }
+
+ private void showHelp(@Nonnull Options opts, @Nullable String errMsg)
+ throws UDFArgumentException {
+ Description funcDesc = getClass().getAnnotation(Description.class);
+ final String cmdLineSyntax;
+ if (funcDesc == null) {
+ cmdLineSyntax = getClass().getSimpleName();
+ } else {
+ String funcName = funcDesc.name();
+ cmdLineSyntax = funcName == null ? getClass().getSimpleName()
+ : funcDesc.value().replace("_FUNC_", funcDesc.name());
+ }
+ StringWriter sw = new StringWriter();
+ sw.write('\n');
+ if (errMsg != null) {
+ sw.write(errMsg);
+ sw.write("\n\n");
+ }
+ PrintWriter pw = new PrintWriter(sw);
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
+ HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
+ pw.flush();
+ String helpMsg = sw.toString();
+ throw new UDFArgumentException(helpMsg);
+ }
+
/**
* Raise {@link UDFArgumentException} if the given condition is false.
*
diff --git a/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java b/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java
index cd36d6f..acd80bf 100644
--- a/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java
+++ b/core/src/main/java/hivemall/ftvec/text/OkapiBM25UDF.java
@@ -108,7 +108,7 @@
throws UDFArgumentException {
final int numArgOIs = argOIs.length;
if (numArgOIs < 5) {
- throw new UDFArgumentException("argOIs.length must be greater than or equal to 5");
+ showHelp("#arguments must be greater than or equal to 5: " + numArgOIs);
} else if (numArgOIs == 6) {
String opts = HiveUtils.getConstString(argOIs[5]);
processOptions(opts);