List of usage examples for org.apache.commons.cli BasicParser parse
public CommandLine parse(Options options, String[] arguments) throws ParseException
arguments
based on the specifed Options . From source file:org.fnlp.nlp.parser.dep.train.JointParerTester.java
public static void main(String[] args) throws Exception { Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); BasicParser parser = new BasicParser(); CommandLine cl;//ww w . j a va 2 s. co m try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("Tagger:\n" + "ParserTester [option] model_file test_file result_file;\n", opt); return; } String[] args1 = cl.getArgs(); String modelfile = args1[0]; String testfile = args1[1]; String resultfile = args1[2]; JointParerTester tester = new JointParerTester(modelfile); tester.test(testfile, resultfile, "UTF-8"); }
From source file:org.fnlp.nlp.parser.dep.train.JointParerTrainer.java
/** * /*from w ww. jav a2s . c om*/ * * @param args * * @throws Exception */ public static void main(String[] args) throws Exception { // args = new String[2]; // args[0] = "./tmp/malt.train"; // args[1] = "./tmp/Malt2Model.gz"; Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters 1, default 1"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("Tagger:\n" + "ParserTrainer [option] train_file model_file;\n", opt); return; } args = cl.getArgs(); String datafile = args[0]; String modelfile = args[1]; int maxite = Integer.parseInt(cl.getOptionValue("iter", "50")); float c = Float.parseFloat(cl.getOptionValue("c", "1")); JointParerTrainer trainer = new JointParerTrainer(modelfile); trainer.train(datafile, maxite, c); }
From source file:org.fnlp.nlp.parser.dep.train.ParserTrainer.java
/** * //from ww w. j a v a 2 s .c om * * @param args * * @throws Exception */ public static void main(String[] args) throws Exception { args = new String[2]; args[0] = "./tmp/CoNLL2009-ST-Chinese-train.txt"; args[1] = "./tmp/modelConll.gz"; Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters 1, default 1"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("Tagger:\n" + "ParserTrainer [option] train_file model_file;\n", opt); return; } args = cl.getArgs(); String datafile = args[0]; String modelfile = args[1]; int maxite = Integer.parseInt(cl.getOptionValue("iter", "50")); float c = Float.parseFloat(cl.getOptionValue("c", "1")); ParserTrainer trainer = new ParserTrainer(modelfile); trainer.train(datafile, maxite, c); }
From source file:org.fnlp.nlp.similarity.train.WordCluster.java
/** * @param args//from w w w . j a v a 2 s. c o m * @throws Exception */ public static void main(String[] args) throws Exception { /** * ?? */ Options opt = new Options(); opt.addOption("path", true, "?"); opt.addOption("res", true, "?"); opt.addOption("slot", true, "?"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } int slotsize = Integer.parseInt(cl.getOptionValue("slot", "50")); System.out.println("?:" + slotsize); String file = cl.getOptionValue("path", "./tmp/news.allsites.txt"); System.out.println("?:" + file); String resfile = cl.getOptionValue("res", "./tmp/res.txt"); System.out.println(":" + resfile); SougouCA sca = new SougouCA(file); WordCluster wc = new WordCluster(); wc.slotsize = slotsize; wc.read(sca); wc.startClustering(); wc.saveModel(resfile + ".m"); wc.saveTxt(resfile); wc = WordCluster.loadFrom(resfile + ".m"); wc.saveTxt(resfile + "1"); System.out.println(new Date().toString()); System.out.println("Done"); }
From source file:org.fnlp.nlp.similarity.train.WordClusterM.java
/** * @param args/*from w w w . ja va 2 s. c om*/ * @throws Exception */ public static void main(String[] args) throws Exception { /** * ?? */ Options opt = new Options(); opt.addOption("path", true, "?"); opt.addOption("res", true, "?"); opt.addOption("slot", true, "?"); opt.addOption("thd", true, ""); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } int threads = Integer.parseInt(cl.getOptionValue("thd", "3")); System.out.println("?:" + threads); int slotsize = Integer.parseInt(cl.getOptionValue("slot", "20")); System.out.println("?:" + slotsize); String file = cl.getOptionValue("path", "./tmp/SogouCA.mini.txt"); System.out.println("?:" + file); String resfile = cl.getOptionValue("res", "./tmp/cluster.txt"); System.out.println(":" + resfile); long starttime = System.currentTimeMillis(); SougouCA sca = new SougouCA(file); WordClusterM wc = new WordClusterM(threads); wc.slotsize = slotsize; wc.read(sca); wc.startClustering(); wc.saveModel(resfile + ".m"); wc.saveTxt(resfile); wc = (WordClusterM) WordCluster.loadFrom(resfile + ".m"); wc.saveTxt(resfile + "1"); long endtime = System.currentTimeMillis(); System.out.println("Total Time:" + (endtime - starttime) / 60000); System.out.println("Done"); System.exit(0); }
From source file:org.fnlp.nlp.tag.Tagger.java
/** * ??//from ww w .java 2s. c o m * java -classpath fnlp-core.jar org.fnlp.nlp.tag.Tagger -train template train model * java -classpath fnlp-core.jar org.fnlp.nlp.tag.Tagger [-haslabel] model test [result] * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters C in PA algorithm, default 0.8"); opt.addOption("train", false, "switch to training mode(Default: test model"); opt.addOption("retrain", false, "switch to retraining mode(Default: test model"); opt.addOption("margin", false, "use hamming loss as margin threshold"); opt.addOption("interim", false, "save interim model file"); opt.addOption("haslabel", false, "test file has includes label or not"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("Tagger:\n" + "tagger [option] -train templet_file train_file model_file [test_file];\n" + "tagger [option] -retrain train_file model_file newmodel_file [test_file];\n" + "tagger [option] -label model_file test_file output_file\n", opt); return; } Tagger tagger = new Tagger(); tagger.iterNum = Integer.parseInt(cl.getOptionValue("iter", "50")); tagger.c = Float.parseFloat(cl.getOptionValue("c", "0.8")); tagger.useLoss = cl.hasOption("margin"); tagger.interim = cl.hasOption("interim"); tagger.hasLabel = cl.hasOption("haslabel"); String[] arg = cl.getArgs(); if (cl.hasOption("train") && arg.length == 3) { tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; System.out.println("Training model ..."); tagger.train(); } else if (cl.hasOption("train") && arg.length == 4) { tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; tagger.testfile = arg[3]; System.out.println("Training model ..."); tagger.train(); } else if (cl.hasOption("train") && arg.length == 5) { tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; tagger.testfile = arg[3]; System.out.println("Training model ..."); tagger.train(); System.gc(); tagger.output = arg[4]; tagger.test(); } else if (cl.hasOption("retrain") && arg.length == 3) { tagger.train = arg[0]; tagger.model = arg[1]; tagger.newmodel = arg[2]; System.out.println("Re-Training model ..."); tagger.loadFrom(tagger.model); tagger.train(); } else if (cl.hasOption("retrain") && arg.length == 4) { tagger.train = arg[0]; tagger.model = arg[1]; tagger.newmodel = arg[2]; tagger.testfile = arg[3]; System.out.println("Re-Training model ..."); tagger.loadFrom(tagger.model); tagger.train(); } else if (cl.hasOption("retrain") && arg.length == 5) { tagger.train = arg[0]; tagger.model = arg[1]; tagger.newmodel = arg[2]; tagger.testfile = arg[3]; System.out.println("Re-Training model ..."); tagger.loadFrom(tagger.model); tagger.train(); System.gc(); tagger.output = arg[4]; tagger.test(); } else if (arg.length == 3) { tagger.model = arg[0]; tagger.testfile = arg[1]; tagger.output = arg[2]; tagger.test(); } else if (arg.length == 2) { tagger.model = arg[0]; tagger.testfile = arg[1]; tagger.test(); } else { System.err.println("paramenters format error!"); System.err.println("Print option \"-h\" for help."); return; } System.gc(); }
From source file:org.fnlp.train.tag.addedTagger.java
/** * java -classpath fudannlp.jar edu.fudan.nlp.tag.Tagger -train template train model * java -classpath fudannlp.jar edu.fudan.nlp.tag.Tagger model test [result] * /*from w ww.j ava 2 s . c o m*/ * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c1", true, "parameters 1, default 1"); opt.addOption("c2", true, "parameters 2, default 0.1"); opt.addOption("train", false, "switch to training mode(Default: test model"); opt.addOption("labelwise", false, "switch to labelwise mode(Default: viterbi model"); opt.addOption("margin", false, "use hamming loss as margin threshold"); opt.addOption("interim", false, "save interim model file"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("Tagger:\n" + "tagger [option] -train templet_file train_file model_file [test_file];\n" + "tagger [option] model_file test_file output_file\n", opt); return; } addedTagger tagger = new addedTagger(); tagger.iterNum = Integer.parseInt(cl.getOptionValue("iter", "50")); tagger.c1 = Float.parseFloat(cl.getOptionValue("c1", "1")); tagger.c2 = Float.parseFloat(cl.getOptionValue("c2", "0.1")); tagger.useLoss = cl.hasOption("margin"); tagger.interim = cl.hasOption("interim"); String[] arg = cl.getArgs(); if (cl.hasOption("train") && arg.length == 3) { tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; System.out.println("Training model ..."); tagger.train(); } else if (cl.hasOption("train") && arg.length == 4) { tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; tagger.testfile = arg[3]; System.out.println("Training model ..."); tagger.train(); } else if (cl.hasOption("train") && arg.length == 5) { tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; tagger.testfile = arg[3]; System.out.println("Training model ..."); tagger.train(); System.gc(); tagger.output = arg[4]; tagger.test(); } else if (arg.length == 3) { tagger.model = arg[0]; tagger.testfile = arg[1]; tagger.output = arg[2]; tagger.test(); } else if (arg.length == 2) { tagger.model = arg[0]; tagger.testfile = arg[1]; tagger.test(); } else { System.err.println("paramenters format error!"); System.err.println("Print option \"-h\" for help."); return; } System.gc(); }
From source file:org.fnlp.train.tag.CWSTrain.java
/** * ??/*w ww . j a v a 2s . com*/ * java -classpath fudannlp.jar org.fnlp.nlp.tag.Tagger -train template train model * java -classpath fudannlp.jar org.fnlp.nlp.tag.Tagger model test [result] * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Options opt = new Options(); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters C in PA algorithm, default 0.8"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } CWSTrain tagger = new CWSTrain(); tagger.iterNum = Integer.parseInt(cl.getOptionValue("iter", "50")); tagger.c = Float.parseFloat(cl.getOptionValue("c", "0.8")); String[] arg = cl.getArgs(); tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; System.out.println("Training model ..."); tagger.train(); System.gc(); }
From source file:org.fnlp.train.tag.POSTrain.java
/** * ??/*w w w . j a v a 2 s.com*/ * java -classpath fudannlp.jar edu.fudan.nlp.tag.Tagger -train template train model * java -classpath fudannlp.jar edu.fudan.nlp.tag.Tagger model test [result] * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Options opt = new Options(); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters C in PA algorithm, default 0.8"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } POSTrain tagger = new POSTrain(); tagger.iterNum = Integer.parseInt(cl.getOptionValue("iter", "50")); tagger.c = Float.parseFloat(cl.getOptionValue("c", "0.8")); String[] arg = cl.getArgs(); tagger.templateFile = arg[0]; tagger.train = arg[1]; tagger.model = arg[2]; System.out.println("Training model ..."); tagger.train(); System.gc(); }
From source file:org.freeeed.main.FreeEedMain.java
/** * Process the command line arguments/*from w w w. j a va 2 s . c o m*/ * * @param args command line arguments */ private void processOptions(String[] args) { String customParameterFile; Project project = null; try { BasicParser parser = new BasicParser(); commandLine = parser.parse(options, args); // one-time actions if (commandLine.hasOption(CommandLineOption.HELP.getName()) || commandLine.getOptions().length == 0) { HelpFormatter f = new HelpFormatter(); f.printHelp("java -jar FreeEed.jar [options]\n\n" + "where options include:", options); } else if (commandLine.hasOption(CommandLineOption.VERSION.getName())) { System.out.println(Version.getVersionAndBuild()); } else if (commandLine.hasOption(CommandLineOption.GUI.getName())) { openGUI(); } else if (commandLine.hasOption(CommandLineOption.ENRON.getName())) { processEnronDataSet(); } else { if (commandLine.hasOption(CommandLineOption.PARAM_FILE.getName())) { // independent actions customParameterFile = commandLine.getOptionValue(CommandLineOption.PARAM_FILE.getName()); project = Project.loadFromFile(new File(customParameterFile)); } if (commandLine.hasOption(CommandLineOption.DRY.getName())) { System.out.println("Dry run - exiting now."); } else { if (project.isStage()) { stagePackageInput(); } String runWhere = project.getProcessWhere(); if (runWhere != null) { process(runWhere); } } } } catch (Exception e) { logger.error("Error in processing", e); } }