为命令行解析器添加新选项:无法识别的选项错误

时间:2016-07-04 14:55:16

标签: java command-line

所以我从包含需要命令行参数的java文件的github存储库中分叉并压缩了一些代码。

这是我的问题的相关代码 -

Options options = new Options();
    options.addOption("f", false, "force processing of text file");
    options.addOption("printHTML", false, "print HTML file for inspection");
    options.addOption("w", true, "coreference weight file");
    options.addOption("doc", true, "text document to process");
    options.addOption("tok", true, "processed text document");
    options.addOption("docId", true, "text document ID to process");
    options.addOption("p", true, "output directory");
    options.addOption("id", true, "book ID");
    options.addOption("d", false, "dump pronoun and quotes for annotation")

    CommandLine cmd = null;
    try {
        CommandLineParser parser = new BasicParser();
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        e.printStackTrace();
    }

我根据自己的要求添加了额外选项'quoteAttr'

Options options = new Options();
    options.addOption("f", false, "force processing of text file");
    options.addOption("printHTML", false, "print HTML file for inspection");
    options.addOption("quoteAttr", false, "print quote ids and their attributions");//Here
    options.addOption("w", true, "coreference weight file");
    options.addOption("doc", true, "text document to process");
    options.addOption("tok", true, "processed text document");
    options.addOption("docId", true, "text document ID to process");
    options.addOption("p", true, "output directory");
    options.addOption("id", true, "book ID");
    options.addOption("d", false, "dump pronoun and quotes for annotation");

    CommandLine cmd = null;
    try {
        CommandLineParser parser = new BasicParser();
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        e.printStackTrace();
    }

将此选项添加到代码本身对程序的常规功能没有任何作用。

如此处所示 -

./runjava novels/BookNLP -doc data/originalTexts/dickens.oliver.pg730.txt -printHTML -p data/output/dickens -tok data/tokens/dickens.oliver.tokens -f
Adding annotator tokenize
Adding annotator ssplit
Adding annotator pos
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.6 sec].
Adding annotator lemma
Adding annotator ner
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... done [4.6 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz ... 

但是当我在命令行上使用'quoteAttr'选项时 -

./runjava novels/BookNLP -doc data/originalTexts/dickens.oliver.pg730.txt -printHTML -quoteAttr -p data/output/dickens -tok data/tokens/dickens.oliver.tokens -f

我收到此错误 -

org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -quoteAttr
at org.apache.commons.cli.Parser.processOption(Parser.java:363)
at org.apache.commons.cli.Parser.parse(Parser.java:199)
at org.apache.commons.cli.Parser.parse(Parser.java:85)
at novels.BookNLP.main(BookNLP.java:98)
Exception in thread "main" java.lang.NullPointerException
at novels.BookNLP.main(BookNLP.java:106)

为什么会这样?

0 个答案:

没有答案