Author: gsingers
Date: Thu Oct 16 17:50:27 2008
New Revision: 705435
URL: http://svn.apache.org/viewvc?rev=705435&view=rev
Log:
upgrade to CLI2
Modified:
lucene/mahout/trunk/core/pom.xml
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/Classify.java
lucene/mahout/trunk/examples/pom.xml
lucene/mahout/trunk/pom.xml
Modified: lucene/mahout/trunk/core/pom.xml
URL:
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/pom.xml?rev=705435&r1=705434&r2=705435&view=diff
==============================================================================
--- lucene/mahout/trunk/core/pom.xml (original)
+++ lucene/mahout/trunk/core/pom.xml Thu Oct 16 17:50:27 2008
@@ -326,7 +326,7 @@
<version>2.3.2</version>
</dependency>
<dependency>
- <groupId>commons-cli</groupId>
+ <groupId>org.apache.commons</groupId>
<artifactId>commons-cli</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
@@ -338,6 +338,17 @@
</dependency>
</dependencies>
-
+ <repositories>
+ <repository>
+ <id>Apache snapshots</id>
+ <url>http://people.apache.org/maven-snapshot-repository</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+ </repositories>
</project>
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java
URL:
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java?rev=705435&r1=705434&r2=705435&view=diff
==============================================================================
---
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java
(original)
+++
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/BayesFileFormatter.java
Thu Oct 16 17:50:27 2008
@@ -17,13 +17,15 @@
* limitations under the License.
*/
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
-import org.apache.commons.cli.Parser;
+
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.commandline.Parser;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.CharArraySet;
import org.apache.lucene.analysis.Token;
@@ -249,58 +251,62 @@
@SuppressWarnings("static-access")
public static void main(String[] args) throws ClassNotFoundException,
IllegalAccessException, InstantiationException, IOException {
- Options options = new Options();
- Option inputOpt = OptionBuilder.withLongOpt("input").isRequired().hasArg()
- .withDescription("The input file").create("i");
- options.addOption(inputOpt);
- Option outputOpt = OptionBuilder.withLongOpt("output").isRequired()
- .hasArg().withDescription("The output file").create("o");
- options.addOption(outputOpt);
- Option labelOpt = OptionBuilder.withLongOpt("label").isRequired().hasArg()
- .withDescription("The label of the file").create("l");
- options.addOption(labelOpt);
- Option analyzerOpt = OptionBuilder
- .withLongOpt("analyzer")
- .hasArg()
- .withDescription(
- "The fully qualified class name of the analyzer to use. Must have
a no-arg constructor. Default is the StandardAnalyzer")
- .create("a");
- options.addOption(analyzerOpt);
- Option charsetOpt = OptionBuilder.withLongOpt("charset").hasArg()
- .withDescription("The character encoding of the input file")
- .create("c");
- options.addOption(charsetOpt);
- Option collapseOpt = OptionBuilder.withLongOpt("collapse").hasArg()
- .withDescription(
- "Collapse a whole directory to a single file, one doc per line")
- .create("p");
- options.addOption(collapseOpt);
- Option helpOpt = OptionBuilder.withLongOpt("help").withDescription(
- "Print out help info").create("h");
- options.addOption(helpOpt);
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+ final ArgumentBuilder abuilder = new ArgumentBuilder();
+ final GroupBuilder gbuilder = new GroupBuilder();
+
+ Option inputOpt =
obuilder.withLongName("input").withRequired(true).withArgument(
+ abuilder.withName("input").withMinimum(1).withMaximum(1).create()).
+ withDescription("The Input file").withShortName("i").create();
+
+ Option outputOpt =
obuilder.withLongName("output").withRequired(true).withArgument(
+
abuilder.withName("output").withMinimum(1).withMaximum(1).create()).
+ withDescription("The output file").withShortName("o").create();
+
+ Option labelOpt =
obuilder.withLongName("label").withRequired(true).withArgument(
+ abuilder.withName("label").withMinimum(1).withMaximum(1).create()).
+ withDescription("The label of the
file").withShortName("l").create();
+
+ Option analyzerOpt =
obuilder.withLongName("analyzer").withRequired(true).withArgument(
+
abuilder.withName("analyzer").withMinimum(1).withMaximum(1).create()).
+ withDescription("The fully qualified class name of the analyzer to
use. Must have a no-arg constructor. Default is the
StandardAnalyzer").withShortName("a").create();
+
+ Option charsetOpt =
obuilder.withLongName("charset").withRequired(true).withArgument(
+
abuilder.withName("charset").withMinimum(1).withMaximum(1).create()).
+ withDescription("The character encoding of the input
file").withShortName("c").create();
+
+ Option collapseOpt =
obuilder.withLongName("collapse").withRequired(true).withArgument(
+
abuilder.withName("collapse").withMinimum(1).withMaximum(1).create()).
+ withDescription("Collapse a whole directory to a single file, one
doc per line").withShortName("p").create();
+
+ Option helpOpt = obuilder.withLongName("help").withRequired(true).
+ withDescription("Print out help").withShortName("h").create();
+ Group group =
gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(labelOpt).withOption(analyzerOpt).withOption(charsetOpt).withOption(collapseOpt).withOption(helpOpt).create();
CommandLine cmdLine;
try {
- Parser parser = new PosixParser();
- cmdLine = parser.parse(options, args);
- if (cmdLine.hasOption(helpOpt.getOpt())) {
- log.info("Options: {}", options);
+ Parser parser = new Parser();
+ parser.setGroup(group);
+ cmdLine = parser.parse(args);
+
+ if (cmdLine.hasOption(helpOpt)) {
+
return;
}
- File input = new File(cmdLine.getOptionValue(inputOpt.getOpt()));
- File output = new File(cmdLine.getOptionValue(outputOpt.getOpt()));
- String label = cmdLine.getOptionValue(labelOpt.getOpt());
+ File input = new File((String) cmdLine.getValue(inputOpt));
+ File output = new File((String) cmdLine.getValue(outputOpt));
+ String label = (String) cmdLine.getValue(labelOpt);
Analyzer analyzer;
- if (cmdLine.hasOption(analyzerOpt.getOpt())) {
+ if (cmdLine.hasOption(analyzerOpt)) {
analyzer = Class.forName(
-
cmdLine.getOptionValue(analyzerOpt.getOpt())).asSubclass(Analyzer.class).newInstance();
+ (String)
cmdLine.getValue(analyzerOpt)).asSubclass(Analyzer.class).newInstance();
} else {
analyzer = new StandardAnalyzer();
}
Charset charset = Charset.forName("UTF-8");
- if (cmdLine.hasOption(charsetOpt.getOpt())) {
- charset = Charset.forName(cmdLine.getOptionValue(charsetOpt.getOpt()));
+ if (cmdLine.hasOption(charsetOpt)) {
+ charset = Charset.forName((String) cmdLine.getValue(charsetOpt));
}
- boolean collapse = cmdLine.hasOption(collapseOpt.getOpt());
+ boolean collapse = cmdLine.hasOption(collapseOpt);
if (collapse) {
collapse(label, analyzer, input, charset, output);
@@ -308,9 +314,8 @@
format(label, analyzer, input, charset, output);
}
- } catch (ParseException exp) {
- log.warn(exp.toString(), exp);
- log.info("Options: {}", options);
+ } catch (OptionException e) {
+ log.error("Exception", e);
}
}
}
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/Classify.java
URL:
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/Classify.java?rev=705435&r1=705434&r2=705435&view=diff
==============================================================================
---
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/Classify.java
(original)
+++
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/Classify.java
Thu Oct 16 17:50:27 2008
@@ -16,13 +16,15 @@
* limitations under the License.
*/
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
-import org.apache.commons.cli.Parser;
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapred.JobConf;
@@ -53,30 +55,49 @@
@SuppressWarnings({ "static-access" })
public static void main(String[] args)
- throws IOException, ClassNotFoundException, IllegalAccessException,
InstantiationException, ParseException {
- Options options = new Options();
- Option pathOpt =
OptionBuilder.withLongOpt("path").isRequired().hasArg().withDescription("The
local file system path").create("p");
- options.addOption(pathOpt);
- Option classifyOpt =
OptionBuilder.withLongOpt("classify").isRequired().hasArg().withDescription("The
document to classify").create("c");
- options.addOption(classifyOpt);
- Option encodingOpt =
OptionBuilder.withLongOpt("encoding").hasArg().withDescription("The file
encoding. defaults to UTF-8").create("e");
- options.addOption(encodingOpt);
- Option analyzerOpt =
OptionBuilder.withLongOpt("analyzer").hasArg().withDescription("The Analyzer to
use").create("a");
- options.addOption(analyzerOpt);
- Option defaultCatOpt =
OptionBuilder.withLongOpt("defaultCat").hasArg().withDescription("The default
category").create("d");
- options.addOption(defaultCatOpt);
- Option gramSizeOpt =
OptionBuilder.withLongOpt("gramSize").hasArg().withDescription("Size of the
n-gram").create("ng");
- options.addOption(gramSizeOpt);
- Option typeOpt =
OptionBuilder.withLongOpt("classifierType").isRequired().hasArg().withDescription("Type
of classifier").create("type");
- options.addOption(typeOpt);
+ throws IOException, ClassNotFoundException, IllegalAccessException,
InstantiationException, OptionException {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+ final ArgumentBuilder abuilder = new ArgumentBuilder();
+ final GroupBuilder gbuilder = new GroupBuilder();
+
+ Option pathOpt =
obuilder.withLongName("path").withRequired(true).withArgument(
+
abuilder.withName("path").withMinimum(1).withMaximum(1).create()).withDescription("The
local file system path").withShortName("p").create();
+
+ Option classifyOpt =
obuilder.withLongName("classify").withRequired(true).withArgument(
+
abuilder.withName("classify").withMinimum(1).withMaximum(1).create()).
+ withDescription("The doc to classify").withShortName("").create();
+
+ Option encodingOpt =
obuilder.withLongName("encoding").withRequired(true).withArgument(
+
abuilder.withName("encoding").withMinimum(1).withMaximum(1).create()).
+ withDescription("The file encoding. Default:
UTF-8").withShortName("e").create();
+
+ Option analyzerOpt =
obuilder.withLongName("analyzer").withRequired(true).withArgument(
+
abuilder.withName("analyzer").withMinimum(1).withMaximum(1).create()).
+ withDescription("The Analyzer to use").withShortName("a").create();
+
+ Option defaultCatOpt =
obuilder.withLongName("defaultCat").withRequired(true).withArgument(
+
abuilder.withName("defaultCat").withMinimum(1).withMaximum(1).create()).
+ withDescription("The default
category").withShortName("d").create();
+
+ Option gramSizeOpt =
obuilder.withLongName("gramSize").withRequired(true).withArgument(
+
abuilder.withName("gramSize").withMinimum(1).withMaximum(1).create()).
+ withDescription("Size of the n-gram").withShortName("ng").create();
+
+ Option typeOpt =
obuilder.withLongName("classifierType").withRequired(true).withArgument(
+
abuilder.withName("classifierType").withMinimum(1).withMaximum(1).create()).
+ withDescription("Type of
classifier").withShortName("type").create();
+
+ Group options =
gbuilder.withName("Options").withOption(pathOpt).withOption(classifyOpt).withOption(encodingOpt).withOption(analyzerOpt).withOption(defaultCatOpt).withOption(gramSizeOpt).withOption(typeOpt).create();
+
+ Parser parser = new Parser();
+ parser.setGroup(options);
+ CommandLine cmdLine = parser.parse(args);
- Parser parser = new PosixParser();
- CommandLine cmdLine = parser.parse(options, args);
SequenceFileModelReader reader = new SequenceFileModelReader();
JobConf conf = new JobConf(Classify.class);
Map<String, Path> modelPaths = new HashMap<String, Path>();
- String modelBasePath = cmdLine.getOptionValue(pathOpt.getOpt());
+ String modelBasePath = (String) cmdLine.getValue(pathOpt);
modelPaths.put("sigma_j", new Path(modelBasePath +
"/trainer-weights/Sigma_j/part-*"));
modelPaths.put("sigma_k", new Path(modelBasePath +
"/trainer-weights/Sigma_k/part-*"));
modelPaths.put("sigma_kSigma_j", new Path(modelBasePath +
"/trainer-weights/Sigma_kSigma_j/part-*"));
@@ -90,7 +111,7 @@
Model model;
Classifier classifier;
- String classifierType = cmdLine.getOptionValue(typeOpt.getOpt());
+ String classifierType = (String) cmdLine.getValue(typeOpt);
if (classifierType.equalsIgnoreCase("bayes")) {
log.info("Testing Bayes Classifier");
@@ -112,17 +133,17 @@
String defaultCat = "unknown";
- if (cmdLine.hasOption(defaultCatOpt.getOpt())) {
- defaultCat = cmdLine.getOptionValue(defaultCatOpt.getOpt());
+ if (cmdLine.hasOption(defaultCatOpt)) {
+ defaultCat = (String) cmdLine.getValue(defaultCatOpt);
}
- File docPath = new File(cmdLine.getOptionValue(classifyOpt.getOpt()));
+ File docPath = new File((String) cmdLine.getValue(classifyOpt));
String encoding = "UTF-8";
- if (cmdLine.hasOption(encodingOpt.getOpt())) {
- encoding = cmdLine.getOptionValue(encodingOpt.getOpt());
+ if (cmdLine.hasOption(encodingOpt)) {
+ encoding = (String) cmdLine.getValue(encodingOpt);
}
Analyzer analyzer = null;
- if (cmdLine.hasOption(analyzerOpt.getOpt())) {
- String className = cmdLine.getOptionValue(analyzerOpt.getOpt());
+ if (cmdLine.hasOption(analyzerOpt)) {
+ String className = (String) cmdLine.getValue(analyzerOpt);
analyzer =
Class.forName(className).asSubclass(Analyzer.class).newInstance();
}
if (analyzer == null) {
@@ -130,9 +151,9 @@
}
int gramSize = 1;
- if (cmdLine.hasOption(gramSizeOpt.getOpt())) {
- gramSize = Integer.parseInt(cmdLine
- .getOptionValue(gramSizeOpt.getOpt()));
+ if (cmdLine.hasOption(gramSizeOpt)) {
+ gramSize = Integer.parseInt((String) cmdLine
+ .getValue(gramSizeOpt));
}
Modified: lucene/mahout/trunk/examples/pom.xml
URL:
http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/pom.xml?rev=705435&r1=705434&r2=705435&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/pom.xml (original)
+++ lucene/mahout/trunk/examples/pom.xml Thu Oct 16 17:50:27 2008
@@ -89,9 +89,9 @@
</dependency>
<dependency>
- <groupId>javax.ejb</groupId>
+ <groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
- <version>5.0.1</version>
+ <version>5.0-1</version>
</dependency>
Modified: lucene/mahout/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/lucene/mahout/trunk/pom.xml?rev=705435&r1=705434&r2=705435&view=diff
==============================================================================
--- lucene/mahout/trunk/pom.xml (original)
+++ lucene/mahout/trunk/pom.xml Thu Oct 16 17:50:27 2008
@@ -79,7 +79,7 @@
</modules>
<repositories>
- <!--repository>
+ <repository>
<id>Apache snapshots</id>
<url>http://people.apache.org/maven-snapshot-repository</url>
<snapshots>
@@ -88,7 +88,7 @@
<releases>
<enabled>false</enabled>
</releases>
- </repository-->
+ </repository>
</repositories>