You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2010/02/22 14:54:48 UTC
svn commit: r912565 - in /lucene/mahout/trunk:
core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/
core/src/main/java/org/apache/mahout/cf/taste/recommender/
core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/
core/src/main/java...
Author: srowen
Date: Mon Feb 22 13:54:47 2010
New Revision: 912565
URL: http://svn.apache.org/viewvc?rev=912565&view=rev
Log:
More style items, I think
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/GenericJDBCDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/ClusteringRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/BayesAlgorithm.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/CBayesAlgorithm.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/FileLineIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/RandomWrapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/ClassifierData.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesClassifierSelfTest.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/ClusteringTestUtils.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayASNOutputState.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayDirichlet.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayOutputState.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/meanshift/DisplayMeanShift.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/Constants.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java
lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapper.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/SparseVectorsFromSequenceFiles.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/TextParagraphSplittingJob.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocCombiner.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocDriver.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapper.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducer.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/Gram.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducer.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizer.java
lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/tfidf/TFIDFConverter.java
lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java
lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapperTest.java
lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducerTest.java
lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/GramTest.java
lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducerTest.java
lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizerTest.java
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/GenericJDBCDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/GenericJDBCDataModel.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/GenericJDBCDataModel.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/GenericJDBCDataModel.java Mon Feb 22 13:54:47 2010
@@ -137,10 +137,5 @@
throw new TasteException(ioe);
}
}
-
- @Override
- public boolean hasPreferenceValues() {
- return true;
- }
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/ClusteringRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/ClusteringRecommender.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/ClusteringRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/ClusteringRecommender.java Mon Feb 22 13:54:47 2010
@@ -34,7 +34,7 @@
*
* @param userID
* user ID for which to find a cluster
- * @return {@link Collection} of IDs of users in the requested user's cluster
+ * @return {@link FastIDSet} of IDs of users in the requested user's cluster
* @throws TasteException
* if an error occurs while accessing the {@link org.apache.mahout.cf.taste.model.DataModel}
*/
@@ -45,7 +45,7 @@
* Returns all clusters of users.
* </p>
*
- * @return {@link Collection} of {@link Collection}s of user IDs
+ * @return array of {@link FastIDSet}s of user IDs
* @throws TasteException
* if an error occurs while accessing the {@link org.apache.mahout.cf.taste.model.DataModel}
*/
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/BayesAlgorithm.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/BayesAlgorithm.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/BayesAlgorithm.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/BayesAlgorithm.java Mon Feb 22 13:54:47 2010
@@ -111,13 +111,13 @@
String[] document) throws InvalidDatastoreException {
OpenObjectIntHashMap<String> wordList = new OpenObjectIntHashMap<String>(document.length / 2);
for (String word : document) {
- if (wordList.containsKey(word) == false) {
- wordList.put(word, 1);
- } else {
+ if (wordList.containsKey(word)) {
wordList.put(word, wordList.get(word) + 1);
+ } else {
+ wordList.put(word, 1);
}
}
- final MutableDouble result = new MutableDouble(0.0d);
+ final MutableDouble result = new MutableDouble(0.0);
wordList.forEachPair(new ObjectIntProcedure<String>() {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/CBayesAlgorithm.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/CBayesAlgorithm.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/CBayesAlgorithm.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/bayes/algorithm/CBayesAlgorithm.java Mon Feb 22 13:54:47 2010
@@ -120,13 +120,13 @@
String[] document) throws InvalidDatastoreException {
OpenObjectIntHashMap<String> wordList = new OpenObjectIntHashMap<String>(document.length / 2);
for (String word : document) {
- if (wordList.containsKey(word) == false) {
- wordList.put(word, 1);
- } else {
+ if (wordList.containsKey(word)) {
wordList.put(word, wordList.get(word) + 1);
+ } else {
+ wordList.put(word, 1);
}
}
- final MutableDouble result = new MutableDouble(0.0d);
+ final MutableDouble result = new MutableDouble(0.0);
wordList.forEachPair(new ObjectIntProcedure<String>() {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/FileLineIterator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/FileLineIterator.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/FileLineIterator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/FileLineIterator.java Mon Feb 22 13:54:47 2010
@@ -47,7 +47,7 @@
/**
* Creates a {@link FileLineIterator} over a given file, assuming a UTF-8 encoding.
*
- * @throws FileNotFoundException
+ * @throws java.io.FileNotFoundException
* if the file does not exist
* @throws IOException
* if the file cannot be read
@@ -59,7 +59,7 @@
/**
* Creates a {@link FileLineIterator} over a given file, assuming a UTF-8 encoding.
*
- * @throws FileNotFoundException
+ * @throws java.io.FileNotFoundException
* if the file does not exist
* @throws IOException
* if the file cannot be read
@@ -71,7 +71,7 @@
/**
* Creates a {@link FileLineIterator} over a given file, using the given encoding.
*
- * @throws FileNotFoundException
+ * @throws java.io.FileNotFoundException
* if the file does not exist
* @throws IOException
* if the file cannot be read
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/RandomWrapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/RandomWrapper.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/RandomWrapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/common/RandomWrapper.java Mon Feb 22 13:54:47 2010
@@ -18,6 +18,7 @@
package org.apache.mahout.common;
import org.uncommons.maths.random.MersenneTwisterRNG;
+import org.uncommons.maths.random.RepeatableRNG;
import java.nio.charset.Charset;
import java.util.Random;
@@ -64,7 +65,7 @@
}
public long getSeed() {
- return RandomUtils.seedBytesToLong(((MersenneTwisterRNG) random).getSeed());
+ return RandomUtils.seedBytesToLong(((RepeatableRNG) random).getSeed());
}
@Override
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/DistributedRowMatrix.java Mon Feb 22 13:54:47 2010
@@ -14,6 +14,7 @@
import java.io.IOException;
import java.util.Iterator;
+import java.util.NoSuchElementException;
/**
@@ -35,13 +36,14 @@
*
*/
public class DistributedRowMatrix implements VectorIterable, JobConfigurable {
- private String inputPathString;
- private String outputTmpPathString;
+
+ private final String inputPathString;
+ private final String outputTmpPathString;
private JobConf conf;
private Path rowPath;
private Path outputTmpBasePath;
- private int numRows;
- private int numCols;
+ private final int numRows;
+ private final int numCols;
@Override
public void configure(JobConf conf) {
@@ -124,11 +126,11 @@
}
public static class DistributedMatrixIterator implements Iterator<MatrixSlice> {
- private SequenceFile.Reader reader;
+ private final SequenceFile.Reader reader;
private boolean hasBuffered = false;
private boolean hasNext = false;
- private IntWritable i = new IntWritable();
- private VectorWritable v = new VectorWritable();
+ private final IntWritable i = new IntWritable();
+ private final VectorWritable v = new VectorWritable();
public DistributedMatrixIterator(SequenceFile.Reader reader) {
this.reader = reader;
@@ -155,11 +157,10 @@
@Override
public MatrixSlice next() {
if(!hasBuffered && !hasNext()) {
- return null;
+ throw new NoSuchElementException();
}
hasBuffered = false;
- MatrixSlice slice = new MatrixSlice(v.get(), i.get());
- return slice;
+ return new MatrixSlice(v.get(), i.get());
}
@Override
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/TimesSquaredJob.java Mon Feb 22 13:54:47 2010
@@ -1,3 +1,20 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.apache.mahout.math.hadoop;
import org.apache.hadoop.filecache.DistributedCache;
@@ -29,10 +46,8 @@
import java.net.URI;
import java.util.Iterator;
-import static org.apache.mahout.math.function.Functions.plusMult;
-
-
public class TimesSquaredJob {
+
private static final Logger log = LoggerFactory.getLogger(TimesSquaredJob.class);
public static final String INPUT_VECTOR = "timesSquared.inputVector";
@@ -41,6 +56,8 @@
public static final String OUTPUT_VECTOR_FILENAME = "timesSquaredOutputVector";
+ private TimesSquaredJob() {}
+
public static JobConf createTimesSquaredJobConf(Vector v,
Path matrixInputPath,
Path outputVectorPath) throws IOException {
@@ -63,7 +80,7 @@
outputVectorPathBase = fs.makeQualified(outputVectorPathBase);
long now = System.nanoTime();
- Path inputVectorPath = new Path(outputVectorPathBase, INPUT_VECTOR + "/" + now);
+ Path inputVectorPath = new Path(outputVectorPathBase, INPUT_VECTOR + '/' + now);
SequenceFile.Writer inputVectorPathWriter = new SequenceFile.Writer(fs,
conf, inputVectorPath, NullWritable.class, VectorWritable.class);
VectorWritable inputVW = new VectorWritable(v);
@@ -110,11 +127,11 @@
}
public static class TimesSquaredMapper extends MapReduceBase
- implements Mapper<WritableComparable,VectorWritable, NullWritable,VectorWritable> {
+ implements Mapper<WritableComparable<?>,VectorWritable, NullWritable,VectorWritable> {
- protected Vector inputVector;
- protected Vector outputVector;
- protected OutputCollector<NullWritable,VectorWritable> out;
+ private Vector inputVector;
+ private Vector outputVector;
+ private OutputCollector<NullWritable,VectorWritable> out;
@Override
public void configure(JobConf conf) {
@@ -147,18 +164,17 @@
}
@Override
- public void map(WritableComparable rowNum,
+ public void map(WritableComparable<?> rowNum,
VectorWritable v,
OutputCollector<NullWritable,VectorWritable> out,
Reporter rep) throws IOException {
this.out = out;
double d = scale(v);
- if(d == 0) {
- return;
- } else if(d == 1) {
+ //if(d == 0) return;
+ if (d == 1.0) {
outputVector.assign(v.get(), Functions.plus);
} else {
- outputVector.assign(v.get(), plusMult(d));
+ outputVector.assign(v.get(), Functions.plusMult(d));
}
}
@@ -176,7 +192,7 @@
public static class VectorSummingReducer extends MapReduceBase
implements Reducer<NullWritable,VectorWritable,NullWritable,VectorWritable> {
- protected Vector outputVector;
+ private Vector outputVector;
@Override
public void configure(JobConf conf) {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/DistributedLanczosSolver.java Mon Feb 22 13:54:47 2010
@@ -41,6 +41,7 @@
* @param corpus
* @return
*/
+ @Override
protected Vector getInitialVector(VectorIterable corpus) {
Vector initialVector = new DenseVector(corpus.numCols());
initialVector.assign(1/Math.sqrt(corpus.numCols()));
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/decomposer/EigenVerificationJob.java Mon Feb 22 13:54:47 2010
@@ -12,7 +12,6 @@
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.cf.taste.hadoop.AbstractJob;
import org.apache.mahout.common.CommandLineUtil;
@@ -35,7 +34,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -59,7 +57,8 @@
* If all the eigenvectors can fit in memory, --inMemory allows for a speedier completion of this task by doing so.
* </p>
*/
-public class EigenVerificationJob extends AbstractJob implements Tool {
+public class EigenVerificationJob extends AbstractJob {
+
private static final Logger log = LoggerFactory.getLogger(EigenVerificationJob.class);
private SingularVectorVerifier eigenVerifier;
@@ -230,7 +229,6 @@
}
public static void main(String[] args) throws Exception {
- int retVal = ToolRunner.run(new EigenVerificationJob(), args);
- System.exit(retVal);
+ ToolRunner.run(new EigenVerificationJob(), args);
}
}
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/ClassifierData.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/ClassifierData.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/ClassifierData.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/ClassifierData.java Mon Feb 22 13:54:47 2010
@@ -112,7 +112,7 @@
public static void writeDataToFile(String file, String[][] content) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
for (String[] entry : content) {
- writer.write(entry[0] + "\t" + entry[1] + "\n");
+ writer.write(entry[0] + '\t' + entry[1] + '\n');
}
writer.close();
}
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesClassifierSelfTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesClassifierSelfTest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesClassifierSelfTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/classifier/bayes/BayesClassifierSelfTest.java Mon Feb 22 13:54:47 2010
@@ -69,9 +69,9 @@
for (String[] entry : ClassifierData.DATA) {
List<String> document = new NGrams(entry[1], Integer.parseInt(params.get("gramSize")))
.generateNGramsWithoutLabel();
- assertEquals(3, classifier.classifyDocument(document.toArray(new String[] {}),
+ assertEquals(3, classifier.classifyDocument(document.toArray(new String[document.size()]),
params.get("defaultCat"), 100).length);
- ClassifierResult result = classifier.classifyDocument(document.toArray(new String[] {}), params
+ ClassifierResult result = classifier.classifyDocument(document.toArray(new String[document.size()]), params
.get("defaultCat"));
assertEquals(entry[0], result.getLabel());
resultAnalyzer.addInstance(entry[0], result);
@@ -79,8 +79,10 @@
int[][] matrix = resultAnalyzer.getConfusionMatrix().getConfusionMatrix();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i == j) assertEquals(4, matrix[i][j]);
- else assertEquals(0, matrix[i][j]);
+ if (i == j)
+ assertEquals(4, matrix[i][j]);
+ else
+ assertEquals(0, matrix[i][j]);
}
}
params.set("testDirPath", "testdata/bayesinput");
@@ -91,8 +93,10 @@
matrix = BayesClassifierDriver.readResult(fs, outputFiles, conf, params).getConfusionMatrix();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i == j) assertEquals(4, matrix[i][j]);
- else assertEquals(0, matrix[i][j]);
+ if (i == j)
+ assertEquals(4, matrix[i][j]);
+ else
+ assertEquals(0, matrix[i][j]);
}
}
}
@@ -119,9 +123,9 @@
for (String[] entry : ClassifierData.DATA) {
List<String> document = new NGrams(entry[1], Integer.parseInt(params.get("gramSize")))
.generateNGramsWithoutLabel();
- assertEquals(3, classifier.classifyDocument(document.toArray(new String[] {}),
+ assertEquals(3, classifier.classifyDocument(document.toArray(new String[document.size()]),
params.get("defaultCat"), 100).length);
- ClassifierResult result = classifier.classifyDocument(document.toArray(new String[] {}), params
+ ClassifierResult result = classifier.classifyDocument(document.toArray(new String[document.size()]), params
.get("defaultCat"));
assertEquals(entry[0], result.getLabel());
resultAnalyzer.addInstance(entry[0], result);
@@ -129,8 +133,10 @@
int[][] matrix = resultAnalyzer.getConfusionMatrix().getConfusionMatrix();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i == j) assertEquals(4, matrix[i][j]);
- else assertEquals(0, matrix[i][j]);
+ if (i == j)
+ assertEquals(4, matrix[i][j]);
+ else
+ assertEquals(0, matrix[i][j]);
}
}
params.set("testDirPath", "testdata/bayesinput");
@@ -141,8 +147,10 @@
matrix = BayesClassifierDriver.readResult(fs, outputFiles, conf, params).getConfusionMatrix();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i == j) assertEquals(4, matrix[i][j]);
- else assertEquals(0, matrix[i][j]);
+ if (i == j)
+ assertEquals(4, matrix[i][j]);
+ else
+ assertEquals(0, matrix[i][j]);
}
}
}
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/ClusteringTestUtils.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/ClusteringTestUtils.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/ClusteringTestUtils.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/clustering/ClusteringTestUtils.java Mon Feb 22 13:54:47 2010
@@ -26,7 +26,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.List;
public class ClusteringTestUtils {
private ClusteringTestUtils() {
Modified: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/math/hadoop/decomposer/TestDistributedLanczosSolver.java Mon Feb 22 13:54:47 2010
@@ -41,8 +41,10 @@
assertEigen(eigenVectors, corpus, eigenVectors.numRows() / 2, 0.01);
}
+ @Override
public void tearDown() throws Exception {
TestCanopyCreation.rmr("testData");
+ super.tearDown();
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayASNOutputState.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayASNOutputState.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayASNOutputState.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayASNOutputState.java Mon Feb 22 13:54:47 2010
@@ -109,7 +109,7 @@
}
}
- public static void main(String[] args) throws IOException, InvocationTargetException, NoSuchMethodException {
+ public static void main(String[] args) throws Exception {
RandomUtils.useTestSeed();
getSamples();
getResults();
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayDirichlet.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayDirichlet.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayDirichlet.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayDirichlet.java Mon Feb 22 13:54:47 2010
@@ -27,8 +27,6 @@
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -39,8 +37,13 @@
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;
import org.apache.mahout.math.function.TimesFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DisplayDirichlet extends Frame {
+
+ private static final Logger log = LoggerFactory.getLogger(DisplayDirichlet.class);
+
private static final List<Vector> sampleParams = new ArrayList<Vector>();
protected static final int ds = 72; // default scale = 72 pixels per inch
@@ -57,20 +60,6 @@
protected static List<Model<VectorWritable>[]> result;
protected int res; // screen resolution
-
-
- /**
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See
- * the NOTICE file distributed with this work for additional information regarding copyright ownership. The
- * ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this
- * file except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and limitations under the License.
- */
public DisplayDirichlet() {
initialize();
@@ -94,7 +83,7 @@
});
}
- public static void main(String[] args) throws IOException, InvocationTargetException, NoSuchMethodException {
+ public static void main(String[] args) throws Exception {
RandomUtils.useTestSeed();
generateSamples();
new DisplayDirichlet();
@@ -175,24 +164,24 @@
int h = size / 2;
double x = v2.get(0) + h;
double y = v2.get(1) + h;
- g2.draw(new Ellipse2D.Double(x * ds, y * ds, dv.get(0)
- * ds,
- dv.get(1) * ds));
+ g2.draw(new Ellipse2D.Double(x * ds, y * ds, dv.get(0) * ds, dv.get(1) * ds));
}
private static void printModels(List<Model<VectorWritable>[]> results, int significant) {
int row = 0;
+ StringBuilder models = new StringBuilder();
for (Model<VectorWritable>[] r : results) {
- System.out.print("sample[" + row++ + "]= ");
+ models.append("sample[").append(row++).append("]= ");
for (int k = 0; k < r.length; k++) {
Model<VectorWritable> model = r[k];
if (model.count() > significant) {
- System.out.print("m" + k + model.toString() + ", ");
+ models.append('m').append(k).append(model).append(", ");
}
}
- System.out.println();
+ models.append('\n');
}
- System.out.println();
+ models.append('\n');
+ log.info(models.toString());
}
public static void generateSamples() {
@@ -222,13 +211,12 @@
private static void generateSamples(int num, double mx, double my, double sd) {
double[] params = {mx, my, sd, sd};
sampleParams.add(new DenseVector(params));
- System.out.println("Generating " + num + " samples m=[" + mx + ", " + my + "] sd=" + sd);
+ log.info("Generating {} samples m=[{}, {}] sd={}", new Object[] {num, mx, my, sd});
for (int i = 0; i < num; i++) {
sampleData.add(new VectorWritable(new DenseVector(new double[] {
- UncommonDistributions
- .rNorm(mx, sd),
- UncommonDistributions
- .rNorm(my, sd)})));
+ UncommonDistributions.rNorm(mx, sd),
+ UncommonDistributions.rNorm(my, sd)}
+ )));
}
}
@@ -249,8 +237,7 @@
private static void generate2dSamples(int num, double mx, double my, double sdx, double sdy) {
double[] params = {mx, my, sdx, sdy};
sampleParams.add(new DenseVector(params));
- System.out.println("Generating " + num + " samples m=[" + mx + ", " + my + "] sd=[" + sdx + ", " + sdy
- + ']');
+ log.info("Generating {} samples m=[{}, {}] sd=[{}, {}]", new Object[] {num, mx, my, sdx, sdy});
for (int i = 0; i < num; i++) {
sampleData
.add(new VectorWritable(new DenseVector(new double[] {UncommonDistributions.rNorm(mx, sdx),
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayOutputState.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayOutputState.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayOutputState.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/dirichlet/DisplayOutputState.java Mon Feb 22 13:54:47 2010
@@ -106,7 +106,7 @@
}
}
- public static void main(String[] args) throws IOException, InvocationTargetException, NoSuchMethodException {
+ public static void main(String[] args) throws Exception {
RandomUtils.useTestSeed();
getSamples();
getResults();
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/meanshift/DisplayMeanShift.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/meanshift/DisplayMeanShift.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/meanshift/DisplayMeanShift.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/meanshift/DisplayMeanShift.java Mon Feb 22 13:54:47 2010
@@ -31,8 +31,12 @@
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
class DisplayMeanShift extends DisplayDirichlet {
+
+ private static final Logger log = LoggerFactory.getLogger(DisplayMeanShift.class);
private static final MeanShiftCanopyClusterer clusterer =
new MeanShiftCanopyClusterer(new EuclideanDistanceMeasure(), 1.0, 0.05, 0.5);
@@ -105,7 +109,7 @@
DisplayDirichlet.generateSamples();
testReferenceImplementation();
for (MeanShiftCanopy canopy : canopies) {
- System.out.println(canopy.toString());
+ log.info(canopy.toString());
}
new DisplayMeanShift();
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/Constants.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/Constants.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/Constants.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/Constants.java Mon Feb 22 13:54:47 2010
@@ -20,11 +20,6 @@
* Constants shared between examples.
*/
public interface Constants {
-
- /**
- * Directory containing output for examples.
- */
- String CLUSTERED_POINTS_OUTPUT_DIRECTORY = "/clustered-points";
/**
* Directory used to store the input after it has been processed from it's
* original form into one suitable for processing by the clustering examples.
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/canopy/Job.java Mon Feb 22 13:54:47 2010
@@ -38,12 +38,12 @@
import org.slf4j.LoggerFactory;
public final class Job {
- /** Logger for this class. */
- private static final Logger LOG = LoggerFactory.getLogger(Job.class);
+
+ private static final Logger log = LoggerFactory.getLogger(Job.class);
private Job() { }
- public static void main(String[] args) throws IOException, ClassNotFoundException {
+ public static void main(String[] args) throws Exception {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
ArgumentBuilder abuilder = new ArgumentBuilder();
GroupBuilder gbuilder = new GroupBuilder();
@@ -100,7 +100,7 @@
runJob(input, output, measureClass, t1, t2);
} catch (OptionException e) {
- Job.LOG.error("Exception", e);
+ Job.log.error("Exception", e);
CommandLineUtil.printHelp(group);
}
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/dirichlet/Job.java Mon Feb 22 13:54:47 2010
@@ -104,8 +104,7 @@
int numReducers = Integer.parseInt(cmdLine.getValue(redOpt, "1").toString());
String vectorClassName = cmdLine.getValue(vectorOpt, "org.apache.mahout.math.RandomAccessSparseVector")
.toString();
- Job
- .runJob(input, output, modelFactory, numModels, maxIterations, alpha_0, numReducers,
+ runJob(input, output, modelFactory, numModels, maxIterations, alpha_0, numReducers,
vectorClassName);
} catch (OptionException e) {
log.error("Exception parsing command line: ", e);
@@ -165,7 +164,7 @@
InputDriver.runJob(input, directoryContainingConvertedInput, vectorClassName);
DirichletDriver.runJob(directoryContainingConvertedInput, output + "/state", modelFactory,
vectorClassName, 60, numModels, maxIterations, alpha_0, numReducers);
- Job.printResults(output + "/state", modelFactory, vectorClassName, 60, maxIterations, numModels, alpha_0);
+ printResults(output + "/state", modelFactory, vectorClassName, 60, maxIterations, numModels, alpha_0);
}
/**
@@ -209,7 +208,7 @@
conf.set(DirichletDriver.PROTOTYPE_SIZE_KEY, Integer.toString(prototypeSize));
clusters.add(DirichletMapper.getDirichletState(conf).getClusters());
}
- Job.printResults(clusters, 0);
+ printResults(clusters, 0);
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/kmeans/Job.java Mon Feb 22 13:54:47 2010
@@ -41,14 +41,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class Job {
+public final class Job {
- /** Logger for this class. */
- private static final Logger LOG = LoggerFactory.getLogger(Job.class);
+ private static final Logger log = LoggerFactory.getLogger(Job.class);
private Job() { }
- public static void main(String[] args) throws IOException, ClassNotFoundException {
+ public static void main(String[] args) throws Exception {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
ArgumentBuilder abuilder = new ArgumentBuilder();
GroupBuilder gbuilder = new GroupBuilder();
@@ -101,7 +100,7 @@
runJob(input, output, measureClass, t1, t2, convergenceDelta, maxIterations);
} catch (OptionException e) {
- Job.LOG.error("Exception", e);
+ log.error("Exception", e);
CommandLineUtil.printHelp(group);
}
}
@@ -145,14 +144,14 @@
if (dfs.exists(outPath)) {
dfs.delete(outPath, true);
}
- final String directoryContainingConvertedInput = output + Constants.DIRECTORY_CONTAINING_CONVERTED_INPUT;
- System.out.println("Preparing Input");
+ String directoryContainingConvertedInput = output + Constants.DIRECTORY_CONTAINING_CONVERTED_INPUT;
+ log.info("Preparing Input");
InputDriver.runJob(input, directoryContainingConvertedInput,
"org.apache.mahout.math.RandomAccessSparseVector");
- System.out.println("Running Canopy to get initial clusters");
+ log.info("Running Canopy to get initial clusters");
CanopyDriver.runJob(directoryContainingConvertedInput,
output + CanopyClusteringJob.DEFAULT_CANOPIES_OUTPUT_DIRECTORY, measureClass, t1, t2);
- System.out.println("Running KMeans");
+ log.info("Running KMeans");
KMeansDriver.runJob(directoryContainingConvertedInput,
output + CanopyClusteringJob.DEFAULT_CANOPIES_OUTPUT_DIRECTORY, output, measureClass, convergenceDelta,
maxIterations, 1);
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/clustering/syntheticcontrol/meanshift/Job.java Mon Feb 22 13:54:47 2010
@@ -39,15 +39,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class Job {
- /** Logger for this class. */
- private static final Logger LOG = LoggerFactory.getLogger(Job.class);
+public final class Job {
+
+ private static final Logger log = LoggerFactory.getLogger(Job.class);
private static final String CLUSTERED_POINTS_OUTPUT_DIRECTORY = "/clusteredPoints";
private Job() {}
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) throws Exception {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
ArgumentBuilder abuilder = new ArgumentBuilder();
GroupBuilder gbuilder = new GroupBuilder();
@@ -93,7 +93,7 @@
int maxIterations = Integer.parseInt(cmdLine.getValue(maxIterOpt, "10").toString());
runJob(input, output, measureClassName, t1, t2, convergenceDelta, maxIterations);
} catch (OptionException e) {
- Job.LOG.error("Exception parsing command line: ", e);
+ log.error("Exception parsing command line: ", e);
CommandLineUtil.printHelp(group);
}
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/df/mapreduce/BuildForest.java Mon Feb 22 13:54:47 2010
@@ -143,7 +143,7 @@
datasetPath = new Path(datasetName);
} catch (OptionException e) {
- System.err.println("Exception : " + e);
+ log.error("Exception", e);
CommandLineUtil.printHelp(group);
return -1;
}
Modified: lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapper.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapper.java (original)
+++ lucene/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/hadoop/CDMapper.java Mon Feb 22 13:54:47 2010
@@ -80,7 +80,7 @@
}
void configure(List<Rule> rules, int target) {
- if (!(rules != null && !rules.isEmpty())) {
+ if (rules == null || rules.isEmpty()) {
throw new IllegalArgumentException("bad 'rules' configuration parameter");
}
if (target < 0) {
@@ -119,11 +119,11 @@
* actual label
*/
public static CDFitness evaluate(int target, int prediction, int label) {
- int tp = label == target && prediction == 1 ? 1 : 0;
- int fp = label != target && prediction == 1 ? 1 : 0;
- int tn = label != target && prediction == 0 ? 1 : 0;
- int fn = label == target && prediction == 0 ? 1 : 0;
-
+ boolean labelIsTarget = label == target;
+ int tp = labelIsTarget && prediction == 1 ? 1 : 0;
+ int fp = !labelIsTarget && prediction == 1 ? 1 : 0;
+ int tn = !labelIsTarget && prediction == 0 ? 1 : 0;
+ int fn = labelIsTarget && prediction == 0 ? 1 : 0;
return new CDFitness(tp, fp, tn, fn);
}
}
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/SparseVectorsFromSequenceFiles.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/SparseVectorsFromSequenceFiles.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/SparseVectorsFromSequenceFiles.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/SparseVectorsFromSequenceFiles.java Mon Feb 22 13:54:47 2010
@@ -142,7 +142,7 @@
int maxNGramSize = 1;
- if (cmdLine.hasOption(maxNGramSizeOpt) == true) {
+ if (cmdLine.hasOption(maxNGramSizeOpt)) {
try {
maxNGramSize = Integer.parseInt(cmdLine.getValue(maxNGramSizeOpt).toString());
} catch (NumberFormatException ex) {
@@ -151,7 +151,7 @@
}
log.info("Maximum n-gram size is: {}", maxNGramSize);
- if (cmdLine.hasOption(overwriteOutput) == true) {
+ if (cmdLine.hasOption(overwriteOutput)) {
HadoopUtil.overwriteOutput(outputDir);
}
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/TextParagraphSplittingJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/TextParagraphSplittingJob.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/TextParagraphSplittingJob.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/text/TextParagraphSplittingJob.java Mon Feb 22 13:54:47 2010
@@ -1,7 +1,6 @@
package org.apache.mahout.text;
import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocCombiner.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocCombiner.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocCombiner.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocCombiner.java Mon Feb 22 13:54:47 2010
@@ -25,7 +25,6 @@
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
-import org.apache.mahout.utils.nlp.collocations.llr.Gram.Type;
/** Combiner for pass1 of the CollocationDriver */
public class CollocCombiner extends MapReduceBase implements Reducer<Gram,Gram,Gram,Gram> {
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocDriver.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocDriver.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocDriver.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocDriver.java Mon Feb 22 13:54:47 2010
@@ -60,7 +60,10 @@
public static final int DEFAULT_PASS1_NUM_REDUCE_TASKS = 1;
private static final Logger log = LoggerFactory.getLogger(CollocDriver.class);
-
+
+ private CollocDriver() {
+ }
+
/**
* @param args
*/
@@ -136,7 +139,7 @@
int maxNGramSize = DEFAULT_MAX_NGRAM_SIZE;
- if (cmdLine.hasOption(maxNGramSizeOpt) == true) {
+ if (cmdLine.hasOption(maxNGramSizeOpt)) {
try {
maxNGramSize = Integer.parseInt(cmdLine.getValue(maxNGramSizeOpt).toString());
} catch (NumberFormatException ex) {
@@ -145,7 +148,7 @@
}
log.info("Maximum n-gram size is: {}", maxNGramSize);
- if (cmdLine.hasOption(overwriteOutput) == true) {
+ if (cmdLine.hasOption(overwriteOutput)) {
HadoopUtil.overwriteOutput(output);
}
@@ -175,7 +178,7 @@
Class<? extends Analyzer> analyzerClass = StandardAnalyzer.class;
if (cmdLine.hasOption(analyzerNameOpt)) {
String className = cmdLine.getValue(analyzerNameOpt).toString();
- analyzerClass = (Class<? extends Analyzer>) Class.forName(className);
+ analyzerClass = Class.forName(className).asSubclass(Analyzer.class);
// try instantiating it, b/c there isn't any point in setting it if
// you can't instantiate it
analyzerClass.newInstance();
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapper.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapper.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapper.java Mon Feb 22 13:54:47 2010
@@ -40,9 +40,6 @@
* Runs pass 1 of the Collocation discovery job on input of SequeceFile<Text,Text>, where the key is a
* document id and the value is the document contents. . Delegates to NGramCollector to perform tokenization,
* ngram-creation and output collection.
- *
- * @see org.apache.mahout.text.SequenceFilesFromDirectory
- * @see org.apache.mahout.utils.nlp.collocations.llr.colloc.NGramCollector
*/
public class CollocMapper extends MapReduceBase implements Mapper<Text,StringTuple,Gram,Gram> {
@@ -90,9 +87,6 @@
* Also counts the total number of ngrams encountered and adds it to the counter
* CollocDriver.Count.NGRAM_TOTAL
*
- * @param r
- * The reader to read input from -- used to create a tokenstream from the analyzer
- *
* @param collector
* The collector to send output to
*
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducer.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducer.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducer.java Mon Feb 22 13:54:47 2010
@@ -33,7 +33,9 @@
* Reducer for Pass 1 of the collocation identification job. Generates counts for ngrams and subgrams.
*/
public class CollocReducer extends MapReduceBase implements Reducer<Gram,Gram,Gram,Gram> {
-
+
+ private static final Logger log = LoggerFactory.getLogger(CollocReducer.class);
+
public static final String MIN_SUPPORT = "minSupport";
public static final int DEFAULT_MIN_SUPPORT = 2;
@@ -41,24 +43,19 @@
LESS_THAN_MIN_SUPPORT
}
- private static final Logger log = LoggerFactory.getLogger(CollocReducer.class);
-
private int minSupport;
- private boolean emitUnigrams;
-
+
@Override
public void configure(JobConf job) {
super.configure(job);
this.minSupport = job.getInt(MIN_SUPPORT, DEFAULT_MIN_SUPPORT);
+
+ boolean emitUnigrams = job.getBoolean(CollocDriver.EMIT_UNIGRAMS, CollocDriver.DEFAULT_EMIT_UNIGRAMS);
- this.emitUnigrams = job.getBoolean(CollocDriver.EMIT_UNIGRAMS, CollocDriver.DEFAULT_EMIT_UNIGRAMS);
-
- if (log.isInfoEnabled()) {
- log.info("Min support is {}", minSupport);
- log.info("Emit Unitgrams is {}", emitUnigrams);
- }
-
+ log.info("Min support is {}", minSupport);
+ log.info("Emit Unitgrams is {}", emitUnigrams);
+
}
/**
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/Gram.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/Gram.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/Gram.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/Gram.java Mon Feb 22 13:54:47 2010
@@ -71,7 +71,7 @@
/**
* Create an gram with a frequency of 1
*
- * @param gram
+ * @param ngram
* the gram string
* @param type
* whether the gram is at the head or tail of its text unit or it is a unigram
@@ -85,7 +85,7 @@
*
* Create a gram with the specified frequency.
*
- * @param gram
+ * @param ngram
* the gram string
* @param frequency
* the gram frequency
@@ -101,7 +101,7 @@
try {
// extra character is used for storing type which is part
// of the sort key.
- ByteBuffer bb = Text.encode(ngram + "\0", true);
+ ByteBuffer bb = Text.encode(ngram + '\0', true);
bytes = bb.array();
length = bb.limit();
}
@@ -201,7 +201,7 @@
}
public String toString() {
- return "'" + getString() + "'[" + getType().x + "]:" + frequency;
+ return '\'' + getString() + "'[" + getType().x + "]:" + frequency;
}
public static void encodeType(Type type, byte[] buf, int offset) {
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducer.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducer.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducer.java Mon Feb 22 13:54:47 2010
@@ -68,7 +68,6 @@
*
* @param ll
* the LL to use.
- * @see org.apache.mahout.utils.nlp.collocations.llr.colloc.LLCallback
*/
LLRReducer(LLCallback ll) {
this.ll = ll;
@@ -104,13 +103,11 @@
* number of times neither A or B appears (in that order): N - (subgramFreqA + subgramFreqB - ngramFreq)
*/
@Override
- public void reduce(Gram key,
+ public void reduce(Gram ngram,
Iterator<Gram> values,
OutputCollector<Text,DoubleWritable> output,
Reporter reporter) throws IOException {
- Gram ngram = key;
- String[] gram = new String[2];
int[] gramFreq = new int[2];
gramFreq[0] = gramFreq[1] = -1;
@@ -122,6 +119,7 @@
}
// FIXME: better way to handle errors? Wouldn't an exception thrown here
// cause hadoop to re-try the job?
+ String[] gram = new String[2];
while (values.hasNext()) {
Gram value = values.next();
@@ -169,8 +167,8 @@
reporter.incrCounter(Skipped.LLR_CALCULATION_ERROR, 1);
log.error("Problem calculating LLR ratio: " + ex.getMessage());
log.error("NGram: " + ngram);
- log.error("HEAD: " + gram[0] + ":" + gramFreq[0]);
- log.error("TAIL: " + gram[1] + ":" + gramFreq[1]);
+ log.error("HEAD: " + gram[0] + ':' + gramFreq[0]);
+ log.error("TAIL: " + gram[1] + ':' + gramFreq[1]);
log.error("k11: " + k11 + " k12: " + k12 + " k21: " + k21 + " k22: " + k22);
}
}
@@ -184,6 +182,7 @@
/** concrete implementation delegates to LogLikelihood class */
public static final class ConcreteLLCallback implements LLCallback {
+ @Override
public double logLikelihoodRatio(int k11, int k12, int k21, int k22) {
return LogLikelihood.logLikelihoodRatio(k11, k12, k21, k22);
}
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java Mon Feb 22 13:54:47 2010
@@ -230,15 +230,13 @@
List<TermInfoClusterInOut> clusteredTermInfo = new LinkedList<TermInfoClusterInOut>();
int clusterSize = ids.size();
- int corpusSize = numDocs;
-
+
for (TermEntry termEntry : termEntryMap.values()) {
int corpusDF = reader.terms(new Term(this.contentField, termEntry.term)).docFreq();
int outDF = corpusDF - termEntry.docFreq;
int inDF = termEntry.docFreq;
TermInfoClusterInOut termInfoCluster = new TermInfoClusterInOut(termEntry.term, inDF, outDF);
- double llr = scoreDocumentFrequencies(inDF, outDF, clusterSize, corpusSize);
- termInfoCluster.logLikelihoodRatio = llr;
+ termInfoCluster.logLikelihoodRatio = scoreDocumentFrequencies(inDF, outDF, clusterSize, numDocs);
clusteredTermInfo.add(termInfoCluster);
}
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizer.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizer.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizer.java Mon Feb 22 13:54:47 2010
@@ -316,8 +316,7 @@
conf.setOutputValueClass(LongWritable.class);
FileInputFormat.setInputPaths(conf, input);
- Path outPath = output;
- FileOutputFormat.setOutputPath(conf, outPath);
+ FileOutputFormat.setOutputPath(conf, output);
conf.setMapperClass(TermCountMapper.class);
@@ -326,9 +325,9 @@
conf.setReducerClass(TermCountReducer.class);
conf.setOutputFormat(SequenceFileOutputFormat.class);
- FileSystem dfs = FileSystem.get(outPath.toUri(), conf);
- if (dfs.exists(outPath)) {
- dfs.delete(outPath, true);
+ FileSystem dfs = FileSystem.get(output.toUri(), conf);
+ if (dfs.exists(output)) {
+ dfs.delete(output, true);
}
client.setConf(conf);
Modified: lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/tfidf/TFIDFConverter.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/tfidf/TFIDFConverter.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/tfidf/TFIDFConverter.java (original)
+++ lucene/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/tfidf/TFIDFConverter.java Mon Feb 22 13:54:47 2010
@@ -229,7 +229,7 @@
}
featureCount++;
freqWriter.close();
- Long[] counts = {Long.valueOf(featureCount), Long.valueOf(vectorCount)};
+ Long[] counts = {featureCount, vectorCount};
return new Pair<Long[],List<Path>>(counts, chunkPaths);
}
@@ -275,8 +275,8 @@
conf.setJobName(": MakePartialVectors: input-folder: " + input + ", dictionary-file: "
+ dictionaryFilePath.toString());
- conf.setLong(FEATURE_COUNT, featureCount.longValue());
- conf.setLong(VECTOR_COUNT, vectorCount.longValue());
+ conf.setLong(FEATURE_COUNT, featureCount);
+ conf.setLong(VECTOR_COUNT, vectorCount);
conf.setInt(MIN_DF, minDf);
conf.setInt(MAX_DF_PERCENTAGE, maxDFPercent);
conf.setBoolean(PartialVectorMerger.SEQUENTIAL_ACCESS, sequentialAccess);
@@ -317,8 +317,7 @@
conf.setOutputValueClass(LongWritable.class);
FileInputFormat.setInputPaths(conf, input);
- Path outPath = output;
- FileOutputFormat.setOutputPath(conf, outPath);
+ FileOutputFormat.setOutputPath(conf, output);
conf.setMapperClass(TermDocumentCountMapper.class);
@@ -327,9 +326,9 @@
conf.setReducerClass(TermDocumentCountReducer.class);
conf.setOutputFormat(SequenceFileOutputFormat.class);
- FileSystem dfs = FileSystem.get(outPath.toUri(), conf);
- if (dfs.exists(outPath)) {
- dfs.delete(outPath, true);
+ FileSystem dfs = FileSystem.get(output.toUri(), conf);
+ if (dfs.exists(output)) {
+ dfs.delete(output, true);
}
client.setConf(conf);
JobClient.runJob(conf);
Modified: lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java (original)
+++ lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/clustering/dirichlet/TestL1ModelClustering.java Mon Feb 22 13:54:47 2010
@@ -59,7 +59,7 @@
@Override
public String toString() {
- return pdf.toString() + ' ' + doc.toString();
+ return pdf.toString() + ' ' + doc;
}
}
Modified: lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapperTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapperTest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapperTest.java (original)
+++ lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocMapperTest.java Mon Feb 22 13:54:47 2010
@@ -63,18 +63,18 @@
inputTuple.add(i);
}
- String[][] values = new String[][] { {"h_the", "the best"},
- {"t_best", "the best"},
- {"h_of", "of times"},
- {"t_times", "of times"},
- {"h_best", "best of"},
- {"t_of", "best of"},
- {"h_the", "the worst"},
- {"t_worst", "the worst"},
- {"h_times", "times the"},
- {"t_the", "times the"},
- {"h_worst", "worst of"},
- {"t_of", "worst of"},};
+ String[][] values = { {"h_the", "the best"},
+ {"t_best", "the best"},
+ {"h_of", "of times"},
+ {"t_times", "of times"},
+ {"h_best", "best of"},
+ {"t_of", "best of"},
+ {"h_the", "the worst"},
+ {"t_worst", "the worst"},
+ {"h_times", "times the"},
+ {"t_the", "times the"},
+ {"h_worst", "worst of"},
+ {"t_of", "worst of"},};
// set up expectations for mocks. ngram max size = 2
for (String[] v : values) {
Type p = v[0].startsWith("h") ? Gram.Type.HEAD : Gram.Type.TAIL;
@@ -114,7 +114,7 @@
inputTuple.add(i);
}
- String[][] values = new String[][] {{"h_the", "the best"},
+ String[][] values = {{"h_the", "the best"},
{"t_best", "the best"},
{"h_of", "of times"},
{"t_times", "of times"},
@@ -163,7 +163,7 @@
final Analyzer a;
public TestAnalyzer() {
- a = new StandardAnalyzer(Version.LUCENE_29, Collections.EMPTY_SET);
+ a = new StandardAnalyzer(Version.LUCENE_29, Collections.emptySet());
}
@Override
Modified: lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducerTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducerTest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducerTest.java (original)
+++ lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/CollocReducerTest.java Mon Feb 22 13:54:47 2010
@@ -22,6 +22,7 @@
import static org.apache.mahout.utils.nlp.collocations.llr.Gram.Type.UNIGRAM;
import static org.apache.mahout.utils.nlp.collocations.llr.Gram.Type.NGRAM;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -51,13 +52,13 @@
// test input, input[*][0] is the key,
// input[*][1..n] are the values passed in via
// the iterator.
- Gram[][] input = new Gram[][] {{new Gram("the", UNIGRAM), new Gram("the", UNIGRAM), new Gram("the", UNIGRAM)},
+ Gram[][] input = {{new Gram("the", UNIGRAM), new Gram("the", UNIGRAM), new Gram("the", UNIGRAM)},
{new Gram("the", HEAD), new Gram("the best", NGRAM), new Gram("the worst", NGRAM)},
{new Gram("of", HEAD), new Gram("of times", NGRAM), new Gram("of times", NGRAM)},
{new Gram("times", TAIL), new Gram("of times", NGRAM), new Gram("of times", NGRAM)}};
// expected results.
- Gram[][] values = new Gram[][] {{new Gram("the", 2, UNIGRAM), new Gram("the", 2, UNIGRAM)},
+ Gram[][] values = {{new Gram("the", 2, UNIGRAM), new Gram("the", 2, UNIGRAM)},
{new Gram("the best", 1, NGRAM), new Gram("the", 2, HEAD)},
{new Gram("the worst", 1, NGRAM), new Gram("the", 2, HEAD)},
{new Gram("of times", 2, NGRAM), new Gram("of", 2, HEAD)},
@@ -74,9 +75,7 @@
for (Gram[] ii : input) {
List<Gram> vv = new LinkedList<Gram>();
- for (int i = 1; i < ii.length; i++) {
- vv.add(ii[i]);
- }
+ vv.addAll(Arrays.asList(ii).subList(1, ii.length));
c.reduce(ii[0], vv.iterator(), output, reporter);
}
Modified: lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/GramTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/GramTest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/GramTest.java (original)
+++ lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/GramTest.java Mon Feb 22 13:54:47 2010
@@ -25,7 +25,6 @@
import java.util.HashMap;
import junit.framework.Assert;
-import junit.framework.TestCase;
import org.junit.Test;
@@ -76,9 +75,9 @@
public void testEquality() {
Gram one = new Gram("foo", 2, Gram.Type.HEAD);
Gram two = new Gram("foo", 3, Gram.Type.HEAD);
-
- Assert.assertTrue(one.equals(two));
- Assert.assertTrue(two.equals(one));
+
+ Assert.assertEquals(one, two);
+ Assert.assertEquals(two, one);
Gram three = new Gram("foo", 4, Gram.Type.TAIL);
Gram four = new Gram("foo", Gram.Type.UNIGRAM);
@@ -88,14 +87,14 @@
Assert.assertTrue(!one.equals(four));
Gram five = new Gram("foo", 5, Gram.Type.UNIGRAM);
-
- Assert.assertTrue(four.equals(five));
+
+ Assert.assertEquals(four, five);
Gram six = new Gram("foo", 6, Gram.Type.NGRAM);
Gram seven = new Gram("foo", 7, Gram.Type.NGRAM);
Assert.assertTrue(!five.equals(six));
- Assert.assertTrue(six.equals(seven));
+ Assert.assertEquals(six, seven);
Gram eight = new Gram("foobar", 4, Gram.Type.TAIL);
@@ -164,14 +163,14 @@
public void testWritable() throws IOException {
Gram one = new Gram("foo", 2, Gram.Type.HEAD);
Gram two = new Gram("foobar", 3, Gram.Type.UNIGRAM);
-
- TestCase.assertEquals("foo", one.getString());
- TestCase.assertEquals(2, one.getFrequency());
- TestCase.assertEquals(Gram.Type.HEAD, one.getType());
-
- TestCase.assertEquals("foobar", two.getString());
- TestCase.assertEquals(3, two.getFrequency());
- TestCase.assertEquals(Gram.Type.UNIGRAM, two.getType());
+
+ Assert.assertEquals("foo", one.getString());
+ Assert.assertEquals(2, one.getFrequency());
+ Assert.assertEquals(Gram.Type.HEAD, one.getType());
+
+ Assert.assertEquals("foobar", two.getString());
+ Assert.assertEquals(3, two.getFrequency());
+ Assert.assertEquals(Gram.Type.UNIGRAM, two.getType());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bout);
@@ -184,10 +183,10 @@
DataInputStream din = new DataInputStream(bin);
one.readFields(din);
-
- TestCase.assertEquals("foobar", one.getString());
- TestCase.assertEquals(3, one.getFrequency());
- TestCase.assertEquals(Gram.Type.UNIGRAM, one.getType());
+
+ Assert.assertEquals("foobar", one.getString());
+ Assert.assertEquals(3, one.getFrequency());
+ Assert.assertEquals(Gram.Type.UNIGRAM, one.getType());
}
}
Modified: lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducerTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducerTest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducerTest.java (original)
+++ lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/nlp/collocations/llr/LLRReducerTest.java Mon Feb 22 13:54:47 2010
@@ -22,6 +22,7 @@
import static org.apache.mahout.utils.nlp.collocations.llr.Gram.Type.NGRAM;
import java.io.IOException;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@@ -55,7 +56,7 @@
OutputCollector<Text,DoubleWritable> collector = new OutputCollector<Text,DoubleWritable>() {
@Override
public void collect(Text key, DoubleWritable value) throws IOException {
- log.info(key.toString() + " " + value.toString());
+ log.info(key.toString() + ' ' + value.toString());
}
};
@@ -120,9 +121,7 @@
for (Gram[] ii: input) {
List<Gram> vv = new LinkedList<Gram>();
- for (int i = 1; i < ii.length; i++) {
- vv.add(ii[i]);
- }
+ vv.addAll(Arrays.asList(ii).subList(1, ii.length));
reducer.reduce(ii[0], vv.iterator(), collector, reporter);
}
Modified: lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizerTest.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizerTest.java?rev=912565&r1=912564&r2=912565&view=diff
==============================================================================
--- lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizerTest.java (original)
+++ lucene/mahout/trunk/utils/src/test/java/org/apache/mahout/utils/vectors/text/DictionaryVectorizerTest.java Mon Feb 22 13:54:47 2010
@@ -29,7 +29,6 @@
import org.apache.hadoop.io.Text;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.util.Version;
import org.apache.mahout.common.MahoutTestCase;
import org.apache.mahout.common.RandomUtils;
import org.apache.mahout.utils.vectors.tfidf.TFIDFConverter;
@@ -134,8 +133,7 @@
getRandomDocument()));
}
writer.close();
- Class<? extends Analyzer> analyzer = new StandardAnalyzer(
- Version.LUCENE_CURRENT).getClass();
+ Class<? extends Analyzer> analyzer = StandardAnalyzer.class;
DocumentProcessor.tokenizeDocuments(pathString, analyzer,
"output/tokenized-documents");
DictionaryVectorizer.createTermFrequencyVectors("output/tokenized-documents",