You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ro...@apache.org on 2010/02/13 21:54:31 UTC
svn commit: r909912 [1/10] - in
/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste: common/
eval/ hadoop/ hadoop/cooccurence/ hadoop/item/ hadoop/pseudo/
hadoop/slopeone/ impl/common/ impl/common/jdbc/ impl/eval/ impl/model/
impl/model/...
Author: robinanil
Date: Sat Feb 13 20:54:05 2010
New Revision: 909912
URL: http://svn.apache.org/viewvc?rev=909912&view=rev
Log:
MAHOUT-291
Mahout CF Code style change
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchItemException.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchUserException.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Refreshable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/TasteException.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Weighting.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/DataModelBuilder.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderBuilder.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderIRStatsEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/AbstractJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemItemWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/MapFilesMap.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/Bigram.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemBigramGenerator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemSimilarityEstimator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/TupleWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/UserItemJoiner.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/UserItemRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ItemIDIndexMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ItemIDIndexReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ToUserVectorReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorToCooccurrenceMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/UserVectorToCooccurrenceReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/pseudo/RecommenderJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/pseudo/RecommenderReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/pseudo/ReducerMetrics.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/pseudo/UserIDsMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/ByItemIDComparator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneAverageDiffsJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneDiffsToAveragesReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOnePrefsToDiffsReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/AbstractLongPrimitiveIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/BitSet.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Cache.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/CompactRunningAverage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/CompactRunningAverageAndStdDev.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastByIDMap.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastIDSet.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FastMap.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FullRunningAverage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/FullRunningAverageAndStdDev.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/InvertedRunningAverageAndStdDev.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveArrayIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/LongPrimitiveIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RefreshHelper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Retriever.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RunningAverage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/RunningAverageAndStdDev.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/SamplingLongPrimitiveIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/SkippingIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/WeightedRunningAverage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/jdbc/AbstractJDBCComponent.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AbstractDifferenceRecommenderEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/GenericRecommenderIRStatsEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/IRStatisticsImpl.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/LoadEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractIDMigrator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractJDBCIDMigrator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanItemPreferenceArray.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanPreference.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/BooleanUserPreferenceArray.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericBooleanPrefDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericItemPreferenceArray.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericPreference.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericUserPreferenceArray.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MemoryIDMigrator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MySQLJDBCIDMigrator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserLongPrimitiveIterator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractBooleanPrefJDBCDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/ConnectionPoolDataSource.java
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/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/CachingUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ByRescoreComparator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ClusterSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericRecommendedItem.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemAverageRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemUserAverageRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NearestNeighborClusterSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/NullRescorer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/RandomRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/SimilarUser.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TopItems.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/TreeClusteringRecommender2.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/knn/ConjugateGradientOptimizer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/knn/KnnItemBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/knn/NonNegativeQuadraticOptimizer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/knn/Optimizer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/MemoryDiffStorage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/SlopeOneRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/file/FileDiffStorage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/AbstractJDBCDiffStorage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/ExpectationMaximizationSVD.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AbstractSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/AveragingPreferenceInferrer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingItemSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/CachingUserSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/EuclideanDistanceSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericItemSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/GenericUserSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/LogLikelihoodSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/PearsonCorrelationSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/SpearmanCorrelationSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/TanimotoCoefficientSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/AbstractJDBCItemSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/jdbc/MySQLJDBCItemSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/transforms/CaseAmplification.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/transforms/Counters.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/transforms/InverseUserFrequency.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/transforms/ZScore.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/DataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/IDMigrator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/JDBCDataModel.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/Preference.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/PreferenceArray.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/neighborhood/UserNeighborhood.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/cf/taste/recommender/IDRescorer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/ItemBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/RecommendedItem.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/Recommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/Rescorer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/UserBasedRecommender.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/recommender/slopeone/DiffStorage.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/ItemSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/PreferenceInferrer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/similarity/UserSimilarity.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/transforms/PreferenceTransform.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/transforms/SimilarityTransform.java
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchItemException.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchItemException.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchItemException.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchItemException.java Sat Feb 13 20:54:05 2010
@@ -18,12 +18,11 @@
package org.apache.mahout.cf.taste.common;
public final class NoSuchItemException extends TasteException {
-
- public NoSuchItemException() {
- }
-
+
+ public NoSuchItemException() { }
+
public NoSuchItemException(String message) {
super(message);
}
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchUserException.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchUserException.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchUserException.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/NoSuchUserException.java Sat Feb 13 20:54:05 2010
@@ -18,12 +18,11 @@
package org.apache.mahout.cf.taste.common;
public final class NoSuchUserException extends TasteException {
-
- public NoSuchUserException() {
- }
-
+
+ public NoSuchUserException() { }
+
public NoSuchUserException(String message) {
super(message);
}
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Refreshable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Refreshable.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Refreshable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Refreshable.java Sat Feb 13 20:54:05 2010
@@ -20,26 +20,34 @@
import java.util.Collection;
/**
- * <p>Implementations of this interface have state that can be periodically refreshed. For example, an implementation
- * instance might contain some pre-computed information that should be periodically refreshed. The {@link
- * #refresh(Collection)} method triggers such a refresh.</p>
- *
- * <p>All Taste components implement this. In particular, {@link org.apache.mahout.cf.taste.recommender.Recommender}s
- * do. Callers may want to call {@link #refresh(Collection)} periodically to re-compute information throughout the
- * system and bring it up to date, though this operation may be expensive.</p>
+ * <p>
+ * Implementations of this interface have state that can be periodically refreshed. For example, an
+ * implementation instance might contain some pre-computed information that should be periodically refreshed.
+ * The {@link #refresh(Collection)} method triggers such a refresh.
+ * </p>
+ *
+ * <p>
+ * All Taste components implement this. In particular,
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender}s do. Callers may want to call
+ * {@link #refresh(Collection)} periodically to re-compute information throughout the system and bring it up
+ * to date, though this operation may be expensive.
+ * </p>
*/
public interface Refreshable {
-
+
/**
- * <p>Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any {@link
- * Refreshable} should always leave itself in a consistent, operational state, and that the refresh atomically updates
- * internal state from old to new.</p>
- *
- * @param alreadyRefreshed {@link org.apache.mahout.cf.taste.common.Refreshable}s that are known to have already been
- * refreshed as a result of an initial call to a {@link #refresh(Collection)} method on some
- * object. This ensure that objects in a refresh dependency graph aren't refreshed twice
- * needlessly.
+ * <p>
+ * Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any
+ * {@link Refreshable} should always leave itself in a consistent, operational state, and that the refresh
+ * atomically updates internal state from old to new.
+ * </p>
+ *
+ * @param alreadyRefreshed
+ * {@link org.apache.mahout.cf.taste.common.Refreshable}s that are known to have already been
+ * refreshed as a result of an initial call to a {@link #refresh(Collection)} method on some
+ * object. This ensure that objects in a refresh dependency graph aren't refreshed twice
+ * needlessly.
*/
void refresh(Collection<Refreshable> alreadyRefreshed);
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/TasteException.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/TasteException.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/TasteException.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/TasteException.java Sat Feb 13 20:54:05 2010
@@ -17,22 +17,25 @@
package org.apache.mahout.cf.taste.common;
-/** <p>An exception thrown when an error occurs inside the Taste engine.</p> */
+/**
+ * <p>
+ * An exception thrown when an error occurs inside the Taste engine.
+ * </p>
+ */
public class TasteException extends Exception {
-
- public TasteException() {
- }
-
+
+ public TasteException() { }
+
public TasteException(String message) {
super(message);
}
-
+
public TasteException(Throwable cause) {
super(cause);
}
-
+
public TasteException(String message, Throwable cause) {
super(message, cause);
}
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Weighting.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Weighting.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Weighting.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/common/Weighting.java Sat Feb 13 20:54:05 2010
@@ -18,12 +18,14 @@
package org.apache.mahout.cf.taste.common;
/**
- * <p>A simple enum which gives symbolic names to the ideas of "weighted" and "unweighted", to make various API calls
- * which take a weighting parameter more readable.</p>
+ * <p>
+ * A simple enum which gives symbolic names to the ideas of "weighted" and "unweighted", to make various API
+ * calls which take a weighting parameter more readable.
+ * </p>
*/
public enum Weighting {
-
+
WEIGHTED,
UNWEIGHTED
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/DataModelBuilder.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/DataModelBuilder.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/DataModelBuilder.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/DataModelBuilder.java Sat Feb 13 20:54:05 2010
@@ -24,21 +24,26 @@
import org.apache.mahout.cf.taste.recommender.Recommender;
/**
- * <p>Implementations of this inner interface are simple helper classes which create a {@link DataModel} to be
+ * <p>
+ * Implementations of this inner interface are simple helper classes which create a {@link DataModel} to be
* used while evaluating a {@link Recommender}.
- *
+ *
* @see RecommenderBuilder
* @see RecommenderEvaluator
*/
public interface DataModelBuilder {
-
+
/**
- * <p>Builds a {@link DataModel} implementation to be used in an evaluation, given training data.</p>
- *
- * @param trainingData data to be used in the {@link DataModel}
+ * <p>
+ * Builds a {@link DataModel} implementation to be used in an evaluation, given training data.
+ * </p>
+ *
+ * @param trainingData
+ * data to be used in the {@link DataModel}
* @return {@link DataModel} based upon the given data
- * @throws TasteException if an error occurs while accessing the {@link DataModel}
+ * @throws TasteException
+ * if an error occurs while accessing the {@link DataModel}
*/
DataModel buildDataModel(FastByIDMap<PreferenceArray> trainingData);
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java Sat Feb 13 20:54:05 2010
@@ -18,26 +18,50 @@
package org.apache.mahout.cf.taste.eval;
/**
- * <p>Implementations encapsulate information retrieval-related statistics about a {@link
- * org.apache.mahout.cf.taste.recommender.Recommender}'s recommendations.</p>
- *
- * <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval">Information retrieval</a>.</p>
+ * <p>
+ * Implementations encapsulate information retrieval-related statistics about a
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender}'s recommendations.
+ * </p>
+ *
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval">Information retrieval</a>.
+ * </p>
*/
public interface IRStatistics {
-
- /** <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval#Precision">Precision</a>.</p> */
+
+ /**
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval#Precision">Precision</a>.
+ * </p>
+ */
double getPrecision();
-
- /** <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval#Recall">Recall</a>.</p> */
+
+ /**
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval#Recall">Recall</a>.
+ * </p>
+ */
double getRecall();
-
- /** <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval#Fall-Out">Fall-Out</a>.</p> */
+
+ /**
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval#Fall-Out">Fall-Out</a>.
+ * </p>
+ */
double getFallOut();
-
- /** <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval#F-measure">F-measure</a>.</p> */
+
+ /**
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval#F-measure">F-measure</a>.
+ * </p>
+ */
double getF1Measure();
-
- /** <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval#F-measure">F-measure</a>.</p> */
+
+ /**
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval#F-measure">F-measure</a>.
+ * </p>
+ */
double getFNMeasure(double n);
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderBuilder.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderBuilder.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderBuilder.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderBuilder.java Sat Feb 13 20:54:05 2010
@@ -22,18 +22,24 @@
import org.apache.mahout.cf.taste.recommender.Recommender;
/**
- * <p>Implementations of this inner interface are simple helper classes which create a {@link Recommender} to be
- * evaluated based on the given {@link DataModel}.</p>
+ * <p>
+ * Implementations of this inner interface are simple helper classes which create a {@link Recommender} to be
+ * evaluated based on the given {@link DataModel}.
+ * </p>
*/
public interface RecommenderBuilder {
-
+
/**
- * <p>Builds a {@link Recommender} implementation to be evaluated, using the given {@link DataModel}.</p>
- *
- * @param dataModel {@link DataModel} to build the {@link Recommender} on
+ * <p>
+ * Builds a {@link Recommender} implementation to be evaluated, using the given {@link DataModel}.
+ * </p>
+ *
+ * @param dataModel
+ * {@link DataModel} to build the {@link Recommender} on
* @return {@link Recommender} based upon the given {@link DataModel}
- * @throws TasteException if an error occurs while accessing the {@link DataModel}
+ * @throws TasteException
+ * if an error occurs while accessing the {@link DataModel}
*/
Recommender buildRecommender(DataModel dataModel) throws TasteException;
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java Sat Feb 13 20:54:05 2010
@@ -21,78 +21,91 @@
import org.apache.mahout.cf.taste.model.DataModel;
/**
- * <p>Implementations of this interface evaluate the quality of a
- * {@link org.apache.mahout.cf.taste.recommender.Recommender}'s recommendations.</p>
+ * <p>
+ * Implementations of this interface evaluate the quality of a
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender}'s recommendations.
+ * </p>
*/
public interface RecommenderEvaluator {
-
+
/**
- * <p>Evaluates the quality of a {@link org.apache.mahout.cf.taste.recommender.Recommender}'s recommendations. The
- * range of values that may be returned depends on the implementation, but <em>lower</em> values must mean better
- * recommendations, with 0 being the lowest / best possible evaluation, meaning a perfect match. This method does not
- * accept a {@link org.apache.mahout.cf.taste.recommender.Recommender} directly, but rather a {@link
- * RecommenderBuilder} which can build the {@link org.apache.mahout.cf.taste.recommender.Recommender} to test on top
- * of a given {@link DataModel}.</p>
- *
- * <p>Implementations will take a certain percentage of the preferences supplied by the given {@link DataModel} as
- * "training data". This is typically most of the data, like 90%. This data is used to produce recommendations, and
- * the rest of the data is compared against estimated preference values to see how much the {@link
- * org.apache.mahout.cf.taste.recommender.Recommender}'s predicted preferences match the user's real preferences.
- * Specifically, for each user, this percentage of the user's ratings are used to produce recommendatinos, and for
- * each user, the remaining preferences are compared against the user's real preferences.</p>
- *
- * <p>For large datasets, it may be desirable to only evaluate based on a small percentage of the data.
- * <code>evaluationPercentage</code> controls how many of the {@link DataModel}'s users are used in evaluation.</p>
- *
- * <p>To be clear, <code>trainingPercentage</code> and <code>evaluationPercentage</code> are not related. They do not
- * need to add up to 1.0, for example.</p>
- *
- * @param recommenderBuilder object that can build a {@link org.apache.mahout.cf.taste.recommender.Recommender} to
- * test
- * @param dataModelBuilder @param dataModelBuilder {@link DataModelBuilder} to use, or if null, a default {@link DataModel} implementation
- * will be used
- * @param dataModel dataset to test on
- * @param trainingPercentage percentage of each user's preferences to use to produce recommendations; the rest are
- * compared to estimated preference values to evaluate
- * {@link org.apache.mahout.cf.taste.recommender.Recommender}
- * performance
- * @param evaluationPercentage percentage of users to use in evaluation
- * @return a "score" representing how well the {@link org.apache.mahout.cf.taste.recommender.Recommender}'s estimated
- * preferences match real values; <em>lower</em> scores mean a better match and 0 is a perfect match
- * @throws TasteException if an error occurs while accessing the {@link DataModel}
+ * <p>
+ * Evaluates the quality of a {@link org.apache.mahout.cf.taste.recommender.Recommender}'s recommendations.
+ * The range of values that may be returned depends on the implementation, but <em>lower</em> values must
+ * mean better recommendations, with 0 being the lowest / best possible evaluation, meaning a perfect match.
+ * This method does not accept a {@link org.apache.mahout.cf.taste.recommender.Recommender} directly, but
+ * rather a {@link RecommenderBuilder} which can build the
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender} to test on top of a given {@link DataModel}.
+ * </p>
+ *
+ * <p>
+ * Implementations will take a certain percentage of the preferences supplied by the given {@link DataModel}
+ * as "training data". This is typically most of the data, like 90%. This data is used to produce
+ * recommendations, and the rest of the data is compared against estimated preference values to see how much
+ * the {@link org.apache.mahout.cf.taste.recommender.Recommender}'s predicted preferences match the user's
+ * real preferences. Specifically, for each user, this percentage of the user's ratings are used to produce
+ * recommendatinos, and for each user, the remaining preferences are compared against the user's real
+ * preferences.
+ * </p>
+ *
+ * <p>
+ * For large datasets, it may be desirable to only evaluate based on a small percentage of the data.
+ * <code>evaluationPercentage</code> controls how many of the {@link DataModel}'s users are used in
+ * evaluation.
+ * </p>
+ *
+ * <p>
+ * To be clear, <code>trainingPercentage</code> and <code>evaluationPercentage</code> are not related. They
+ * do not need to add up to 1.0, for example.
+ * </p>
+ *
+ * @param recommenderBuilder
+ * object that can build a {@link org.apache.mahout.cf.taste.recommender.Recommender} to test
+ * @param dataModelBuilder
+ * @param dataModelBuilder {@link DataModelBuilder} to use, or if null, a default {@link DataModel}
+ * implementation will be used
+ * @param dataModel
+ * dataset to test on
+ * @param trainingPercentage
+ * percentage of each user's preferences to use to produce recommendations; the rest are compared
+ * to estimated preference values to evaluate
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender} performance
+ * @param evaluationPercentage
+ * percentage of users to use in evaluation
+ * @return a "score" representing how well the {@link org.apache.mahout.cf.taste.recommender.Recommender}'s
+ * estimated preferences match real values; <em>lower</em> scores mean a better match and 0 is a
+ * perfect match
+ * @throws TasteException
+ * if an error occurs while accessing the {@link DataModel}
*/
double evaluate(RecommenderBuilder recommenderBuilder,
DataModelBuilder dataModelBuilder,
DataModel dataModel,
double trainingPercentage,
double evaluationPercentage) throws TasteException;
-
+
float getMaxPreference();
-
+
/**
- * Sets the maximum preference value that is possible in the current problem
- * domain being evaluated. For example, if the domain is movie ratings on a
- * scale of 1 to 5, this should be set to 5. While a
- * {@link org.apache.mahout.cf.taste.recommender.Recommender}
- * may estimate a preference value above 5.0, it isn't "fair" to consider
- * that the system is actually suggesting an impossible rating of, say,
- * 5.4 stars. In practice the application would cap this estimate to 5.0.
- * Since {@link RecommenderEvaluator}s evaluate the difference between
- * estimated and actual value, this at least prevents this effect from
- * unfairly penalizing a {@link org.apache.mahout.cf.taste.recommender.Recommender}.
- *
+ * Sets the maximum preference value that is possible in the current problem domain being evaluated. For
+ * example, if the domain is movie ratings on a scale of 1 to 5, this should be set to 5. While a
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender} may estimate a preference value above 5.0, it
+ * isn't "fair" to consider that the system is actually suggesting an impossible rating of, say, 5.4 stars.
+ * In practice the application would cap this estimate to 5.0. Since {@link RecommenderEvaluator}s evaluate
+ * the difference between estimated and actual value, this at least prevents this effect from unfairly
+ * penalizing a {@link org.apache.mahout.cf.taste.recommender.Recommender}.
+ *
* @see #setMinPreference(float)
*/
void setMaxPreference(float maxPreference);
-
+
float getMinPreference();
-
+
/**
- * Sets the minimum preference value that is possible in the current problem
- * domain being evaluated.
- *
+ * Sets the minimum preference value that is possible in the current problem domain being evaluated.
+ *
* @see #setMinPreference(float)
*/
void setMinPreference(float minPreference);
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderIRStatsEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderIRStatsEvaluator.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderIRStatsEvaluator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderIRStatsEvaluator.java Sat Feb 13 20:54:05 2010
@@ -22,26 +22,36 @@
import org.apache.mahout.cf.taste.recommender.IDRescorer;
/**
- * <p>Implementations collect information retrieval-related statistics on a {@link
- * org.apache.mahout.cf.taste.recommender.Recommender}'s performance, including precision, recall and f-measure.</p>
- *
- * <p>See <a href="http://en.wikipedia.org/wiki/Information_retrieval">Information retrieval</a>.
+ * <p>
+ * Implementations collect information retrieval-related statistics on a
+ * {@link org.apache.mahout.cf.taste.recommender.Recommender}'s performance, including precision, recall and
+ * f-measure.
+ * </p>
+ *
+ * <p>
+ * See <a href="http://en.wikipedia.org/wiki/Information_retrieval">Information retrieval</a>.
*/
public interface RecommenderIRStatsEvaluator {
-
+
/**
- * @param recommenderBuilder object that can build a {@link org.apache.mahout.cf.taste.recommender.Recommender} to
- * test
- * @param dataModelBuilder {@link DataModelBuilder} to use, or if null, a default {@link DataModel} implementation
- * will be used
- * @param dataModel dataset to test on
- * @param rescorer if any, to use when computing recommendations
- * @param at as in, "precision at 5". The number of recommendations to consider when evaluating
- * precision, etc.
- * @param relevanceThreshold items whose preference value is at least this value are considered "relevant" for
- * the purposes of computations
+ * @param recommenderBuilder
+ * object that can build a {@link org.apache.mahout.cf.taste.recommender.Recommender} to test
+ * @param dataModelBuilder
+ * {@link DataModelBuilder} to use, or if null, a default {@link DataModel} implementation will be
+ * used
+ * @param dataModel
+ * dataset to test on
+ * @param rescorer
+ * if any, to use when computing recommendations
+ * @param at
+ * as in, "precision at 5". The number of recommendations to consider when evaluating precision,
+ * etc.
+ * @param relevanceThreshold
+ * items whose preference value is at least this value are considered "relevant" for the purposes
+ * of computations
* @return {@link IRStatistics} with resulting precision, recall, etc.
- * @throws TasteException if an error occurs while accessing the {@link DataModel}
+ * @throws TasteException
+ * if an error occurs while accessing the {@link DataModel}
*/
IRStatistics evaluate(RecommenderBuilder recommenderBuilder,
DataModelBuilder dataModelBuilder,
@@ -50,5 +60,5 @@
int at,
double relevanceThreshold,
double evaluationPercentage) throws TasteException;
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/AbstractJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/AbstractJob.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/AbstractJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/AbstractJob.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,10 @@
package org.apache.mahout.cf.taste.hadoop;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.cli2.Argument;
import org.apache.commons.cli2.CommandLine;
import org.apache.commons.cli2.Group;
@@ -42,34 +46,30 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
public abstract class AbstractJob implements Tool {
-
+
private static final Logger log = LoggerFactory.getLogger(AbstractJob.class);
-
+
private Configuration configuration;
-
+
@Override
public Configuration getConf() {
return configuration;
}
-
+
@Override
public void setConf(Configuration configuration) {
this.configuration = configuration;
}
-
+
protected static Option buildOption(String name, String shortName, String description) {
- return buildOption(name, shortName, description, true, null);
+ return AbstractJob.buildOption(name, shortName, description, true, null);
}
-
+
protected static Option buildOption(String name, String shortName, String description, String defaultValue) {
- return buildOption(name, shortName, description, false, defaultValue);
+ return AbstractJob.buildOption(name, shortName, description, false, defaultValue);
}
-
+
private static Option buildOption(String name,
String shortName,
String description,
@@ -80,67 +80,63 @@
argBuilder = argBuilder.withDefault(defaultValue);
}
Argument arg = argBuilder.create();
- return new DefaultOptionBuilder().withLongName(name).withRequired(required)
- .withShortName(shortName).withArgument(arg).withDescription(description).create();
+ return new DefaultOptionBuilder().withLongName(name).withRequired(required).withShortName(shortName)
+ .withArgument(arg).withDescription(description).create();
}
-
+
protected static Map<String,String> parseArguments(String[] args, Option... extraOpts) {
-
+
Option inputOpt = DefaultOptionCreator.inputOption().create();
- Option tempDirOpt = buildOption("tempDir", "t", "Intermediate output directory", "temp");
+ Option tempDirOpt = AbstractJob.buildOption("tempDir", "t", "Intermediate output directory", "temp");
Option outputOpt = DefaultOptionCreator.outputOption().create();
Option helpOpt = DefaultOptionCreator.helpOption();
- Option jarFileOpt = buildOption("jarFile", "m", "Implementation jar");
-
- GroupBuilder gBuilder = new GroupBuilder().withName("Options")
- .withOption(inputOpt)
- .withOption(tempDirOpt)
- .withOption(outputOpt)
- .withOption(helpOpt)
- .withOption(jarFileOpt);
-
+ Option jarFileOpt = AbstractJob.buildOption("jarFile", "m", "Implementation jar");
+
+ GroupBuilder gBuilder = new GroupBuilder().withName("Options").withOption(inputOpt)
+ .withOption(tempDirOpt).withOption(outputOpt).withOption(helpOpt).withOption(jarFileOpt);
+
for (Option opt : extraOpts) {
gBuilder = gBuilder.withOption(opt);
}
-
+
Group group = gBuilder.create();
-
+
CommandLine cmdLine;
try {
Parser parser = new Parser();
parser.setGroup(group);
cmdLine = parser.parse(args);
} catch (OptionException e) {
- log.error(e.getMessage());
+ AbstractJob.log.error(e.getMessage());
CommandLineUtil.printHelp(group);
return null;
}
-
+
if (cmdLine.hasOption(helpOpt)) {
CommandLineUtil.printHelp(group);
return null;
}
-
+
Map<String,String> result = new HashMap<String,String>();
- maybePut(result, cmdLine, inputOpt);
- maybePut(result, cmdLine, tempDirOpt);
- maybePut(result, cmdLine, outputOpt);
- maybePut(result, cmdLine, helpOpt);
- maybePut(result, cmdLine, jarFileOpt);
+ AbstractJob.maybePut(result, cmdLine, inputOpt);
+ AbstractJob.maybePut(result, cmdLine, tempDirOpt);
+ AbstractJob.maybePut(result, cmdLine, outputOpt);
+ AbstractJob.maybePut(result, cmdLine, helpOpt);
+ AbstractJob.maybePut(result, cmdLine, jarFileOpt);
for (Option opt : extraOpts) {
- maybePut(result, cmdLine, opt);
+ AbstractJob.maybePut(result, cmdLine, opt);
}
-
- return result;
+
+ return result;
}
-
+
private static void maybePut(Map<String,String> args, CommandLine cmdLine, Option opt) {
Object value = cmdLine.getValue(opt);
if (value != null) {
args.put(opt.getPreferredName(), value.toString());
}
}
-
+
protected static JobConf prepareJobConf(String inputPath,
String outputPath,
String jarFile,
@@ -152,32 +148,32 @@
Class<? extends Writable> reducerKey,
Class<? extends Writable> reducerValue,
Class<? extends OutputFormat> outputFormat) throws IOException {
-
+
JobConf jobConf = new JobConf();
FileSystem fs = FileSystem.get(jobConf);
-
+
Path inputPathPath = new Path(inputPath).makeQualified(fs);
Path outputPathPath = new Path(outputPath).makeQualified(fs);
-
+
jobConf.set("mapred.jar", jarFile);
jobConf.setJar(jarFile);
-
+
jobConf.setClass("mapred.input.format.class", inputFormat, InputFormat.class);
jobConf.set("mapred.input.dir", StringUtils.escapeString(inputPathPath.toString()));
-
+
jobConf.setClass("mapred.mapper.class", mapper, Mapper.class);
jobConf.setClass("mapred.mapoutput.key.class", mapperKey, Writable.class);
jobConf.setClass("mapred.mapoutput.value.class", mapperValue, Writable.class);
-
+
jobConf.setClass("mapred.reducer.class", reducer, Reducer.class);
jobConf.setClass("mapred.output.key.class", reducerKey, Writable.class);
jobConf.setClass("mapred.output.value.class", reducerValue, Writable.class);
jobConf.setBoolean("mapred.output.compress", true);
-
+
jobConf.setClass("mapred.output.format.class", outputFormat, OutputFormat.class);
jobConf.set("mapred.output.dir", StringUtils.escapeString(outputPathPath.toString()));
-
+
return jobConf;
}
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemItemWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemItemWritable.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemItemWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemItemWritable.java Sat Feb 13 20:54:05 2010
@@ -17,81 +17,81 @@
package org.apache.mahout.cf.taste.hadoop;
-import org.apache.hadoop.io.WritableComparable;
-import org.apache.mahout.common.RandomUtils;
-
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.mahout.common.RandomUtils;
+
/** A {@link WritableComparable} encapsulating two items. */
public final class ItemItemWritable implements WritableComparable<ItemItemWritable> {
-
+
private long itemAID;
private long itemBID;
-
+
public ItemItemWritable() {
- // do nothing
+ // do nothing
}
-
+
public ItemItemWritable(long itemAID, long itemBID) {
this.itemAID = itemAID;
this.itemBID = itemBID;
}
-
+
public long getItemAID() {
return itemAID;
}
-
+
public long getItemBID() {
return itemBID;
}
-
+
@Override
public void write(DataOutput out) throws IOException {
out.writeLong(itemAID);
out.writeLong(itemBID);
}
-
+
@Override
public void readFields(DataInput in) throws IOException {
itemAID = in.readLong();
itemBID = in.readLong();
}
-
+
public static ItemItemWritable read(DataInput in) throws IOException {
ItemItemWritable writable = new ItemItemWritable();
writable.readFields(in);
return writable;
}
-
+
@Override
public int compareTo(ItemItemWritable that) {
- int aCompare = compare(itemAID, that.getItemAID());
- return aCompare == 0 ? compare(itemBID, that.getItemBID()) : aCompare;
+ int aCompare = ItemItemWritable.compare(itemAID, that.getItemAID());
+ return aCompare == 0 ? ItemItemWritable.compare(itemBID, that.getItemBID()) : aCompare;
}
-
+
private static int compare(long a, long b) {
return a < b ? -1 : a > b ? 1 : 0;
}
-
+
@Override
public int hashCode() {
return RandomUtils.hashLong(itemAID) + 31 * RandomUtils.hashLong(itemBID);
}
-
+
@Override
public boolean equals(Object o) {
if (o instanceof ItemItemWritable) {
ItemItemWritable that = (ItemItemWritable) o;
- return itemAID == that.getItemAID() && itemBID == that.getItemBID();
+ return (itemAID == that.getItemAID()) && (itemBID == that.getItemBID());
}
- return false;
+ return false;
}
-
+
@Override
public String toString() {
return itemAID + "\t" + itemBID;
}
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java Sat Feb 13 20:54:05 2010
@@ -17,55 +17,55 @@
package org.apache.mahout.cf.taste.hadoop;
-import org.apache.hadoop.io.Writable;
-
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import org.apache.hadoop.io.Writable;
+
/** A {@link Writable} encapsulating an item ID and a preference value. */
public final class ItemPrefWritable implements Writable {
-
+
private long itemID;
private float prefValue;
-
+
public ItemPrefWritable() {
- // do nothing
+ // do nothing
}
-
+
public ItemPrefWritable(long itemID, float prefValue) {
this.itemID = itemID;
this.prefValue = prefValue;
}
-
+
public ItemPrefWritable(ItemPrefWritable other) {
this(other.getItemID(), other.getPrefValue());
}
-
+
public long getItemID() {
return itemID;
}
-
+
public float getPrefValue() {
return prefValue;
}
-
+
@Override
public void write(DataOutput out) throws IOException {
out.writeLong(itemID);
out.writeFloat(prefValue);
}
-
+
@Override
public void readFields(DataInput in) throws IOException {
itemID = in.readLong();
prefValue = in.readFloat();
}
-
+
public static ItemPrefWritable read(DataInput in) throws IOException {
ItemPrefWritable writable = new ItemPrefWritable();
writable.readFields(in);
return writable;
}
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/MapFilesMap.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/MapFilesMap.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/MapFilesMap.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/MapFilesMap.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,11 @@
package org.apache.mahout.cf.taste.hadoop;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
@@ -26,33 +31,26 @@
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
/**
- * Represents a series of {@link MapFile}s, from which one might want to look up values
- * based on keys. It just provides a simplified way to open them all up, and search
- * from all of them.
+ * Represents a series of {@link MapFile}s, from which one might want to look up values based on keys. It just
+ * provides a simplified way to open them all up, and search from all of them.
*/
-public final class MapFilesMap<K extends WritableComparable, V extends Writable> implements Closeable {
-
+@SuppressWarnings("unchecked")
+public final class MapFilesMap<K extends WritableComparable,V extends Writable> implements Closeable {
+
private static final PathFilter PARTS_FILTER = new PathFilter() {
@Override
public boolean accept(Path path) {
return path.getName().startsWith("part-");
}
};
-
+
private final List<MapFile.Reader> readers;
-
- public MapFilesMap(FileSystem fs,
- Path parentDir,
- Configuration conf) throws IOException {
+
+ public MapFilesMap(FileSystem fs, Path parentDir, Configuration conf) throws IOException {
readers = new ArrayList<MapFile.Reader>();
try {
- for (FileStatus status : fs.listStatus(parentDir, PARTS_FILTER)) {
+ for (FileStatus status : fs.listStatus(parentDir, MapFilesMap.PARTS_FILTER)) {
readers.add(new MapFile.Reader(fs, status.getPath().toString(), conf));
}
} catch (IOException ioe) {
@@ -63,7 +61,7 @@
throw new IllegalArgumentException("No MapFiles found in " + parentDir);
}
}
-
+
/**
* @return value reference if key is found, filled in with value data, or null if not found
*/
@@ -75,7 +73,7 @@
}
return null;
}
-
+
@Override
public void close() {
for (MapFile.Reader reader : readers) {
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java Sat Feb 13 20:54:05 2010
@@ -17,10 +17,6 @@
package org.apache.mahout.cf.taste.hadoop;
-import org.apache.hadoop.io.Writable;
-import org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem;
-import org.apache.mahout.cf.taste.recommender.RecommendedItem;
-
import java.io.DataInput;
import java.io.DataOutput;
import java.io.EOFException;
@@ -28,35 +24,40 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.hadoop.io.Writable;
+import org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem;
+import org.apache.mahout.cf.taste.recommender.RecommendedItem;
+
/**
- * A {@link Writable} which encapsulates a list of {@link RecommendedItem}s. This is the mapper (and reducer) output,
- * and represents items recommended to a user. The first item is the one whose estimated preference is highest.
+ * A {@link Writable} which encapsulates a list of {@link RecommendedItem}s. This is the mapper (and reducer)
+ * output, and represents items recommended to a user. The first item is the one whose estimated preference is
+ * highest.
*/
public final class RecommendedItemsWritable implements Writable {
-
+
private List<RecommendedItem> recommended;
-
+
public RecommendedItemsWritable() {
- // do nothing
+ // do nothing
}
-
+
public RecommendedItemsWritable(List<RecommendedItem> recommended) {
this.recommended = recommended;
}
-
+
public List<RecommendedItem> getRecommendedItems() {
return recommended;
}
-
+
@Override
public void write(DataOutput out) throws IOException {
for (RecommendedItem item : recommended) {
out.writeLong(item.getItemID());
out.writeFloat(item.getValue());
}
-
+
}
-
+
@Override
public void readFields(DataInput in) throws IOException {
recommended = new ArrayList<RecommendedItem>();
@@ -75,13 +76,13 @@
// bizarre ByteArrayInputStream bug? sometimes throws from read(); done
}
}
-
+
public static RecommendedItemsWritable read(DataInput in) throws IOException {
RecommendedItemsWritable writable = new RecommendedItemsWritable();
writable.readFields(in);
return writable;
}
-
+
@Override
public String toString() {
StringBuilder result = new StringBuilder(200);
@@ -107,5 +108,5 @@
result.append(']');
return result.toString();
}
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,9 @@
package org.apache.mahout.cf.taste.hadoop;
+import java.io.IOException;
+import java.util.regex.Pattern;
+
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
@@ -24,38 +27,40 @@
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
-import java.io.IOException;
-import java.util.regex.Pattern;
-
/**
* <h1>Input</h1>
- *
- * <p>Intended for use with {@link org.apache.hadoop.mapred.TextInputFormat}; accepts
- * line number / line pairs as {@link LongWritable}/{@link Text} pairs.</p>
- *
- * <p>Each line is assumed to be of the form <code>userID,itemID,preference</code>.</p>
- *
+ *
+ * <p>
+ * Intended for use with {@link org.apache.hadoop.mapred.TextInputFormat}; accepts line number / line pairs as
+ * {@link LongWritable}/{@link Text} pairs.
+ * </p>
+ *
+ * <p>
+ * Each line is assumed to be of the form <code>userID,itemID,preference</code>.
+ * </p>
+ *
* <h1>Output</h1>
- *
- * <p>Outputs the user ID as a {@link LongWritable} mapped to the item ID and preference
- * as a {@link ItemPrefWritable}.</p>
+ *
+ * <p>
+ * Outputs the user ID as a {@link LongWritable} mapped to the item ID and preference as a
+ * {@link ItemPrefWritable}.
+ * </p>
*/
-public final class ToItemPrefsMapper
- extends MapReduceBase
- implements Mapper<LongWritable, Text, LongWritable, ItemPrefWritable> {
-
+public final class ToItemPrefsMapper extends MapReduceBase implements
+ Mapper<LongWritable,Text,LongWritable,ItemPrefWritable> {
+
private static final Pattern COMMA = Pattern.compile(",");
-
+
@Override
public void map(LongWritable key,
Text value,
- OutputCollector<LongWritable, ItemPrefWritable> output,
+ OutputCollector<LongWritable,ItemPrefWritable> output,
Reporter reporter) throws IOException {
- String[] tokens = COMMA.split(value.toString());
+ String[] tokens = ToItemPrefsMapper.COMMA.split(value.toString());
long userID = Long.parseLong(tokens[0]);
long itemID = Long.parseLong(tokens[1]);
float prefValue = Float.parseFloat(tokens[2]);
output.collect(new LongWritable(userID), new ItemPrefWritable(itemID, prefValue));
}
-
+
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/Bigram.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/Bigram.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/Bigram.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/Bigram.java Sat Feb 13 20:54:05 2010
@@ -17,64 +17,64 @@
package org.apache.mahout.cf.taste.hadoop.cooccurence;
-import org.apache.hadoop.io.WritableComparable;
-import org.apache.hadoop.io.WritableComparator;
-import org.apache.hadoop.io.WritableUtils;
-
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;
-public final class Bigram implements WritableComparable<Bigram> {
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.hadoop.io.WritableComparator;
+import org.apache.hadoop.io.WritableUtils;
+public final class Bigram implements WritableComparable<Bigram> {
+
private int first;
private int second;
-
+
public Bigram() {
set(-1, -1);
}
-
+
public Bigram(Bigram bigram) {
set(bigram.first, bigram.second);
}
-
+
public Bigram(int first, int second) {
set(first, second);
}
-
+
public void set(int first, int second) {
this.first = first;
this.second = second;
}
-
+
public int getFirst() {
return first;
}
-
+
public int getSecond() {
return second;
}
-
+
/** Read the two integers encoded using variable length encoding */
@Override
public void readFields(DataInput in) throws IOException {
first = WritableUtils.readVInt(in);
second = WritableUtils.readVInt(in);
}
-
+
/** Write the two integers encoded using variable length encoding */
@Override
public void write(DataOutput out) throws IOException {
WritableUtils.writeVInt(out, first);
WritableUtils.writeVInt(out, second);
}
-
+
@Override
public int hashCode() {
return first * 157 + second;
}
-
+
@Override
public boolean equals(Object right) {
if (right == null) {
@@ -82,12 +82,12 @@
}
if (right instanceof Bigram) {
Bigram r = (Bigram) right;
- return r.getFirst() == first && r.second == second;
+ return (r.getFirst() == first) && (r.second == second);
} else {
return false;
}
}
-
+
@Override
public int compareTo(Bigram o) {
if (first == o.first) {
@@ -100,23 +100,22 @@
return first < o.first ? -1 : 1;
}
}
-
+
@Override
public String toString() {
return first + "\t" + second;
}
-
+
/** A Comparator that compares serialized Bigrams. */
public static class Comparator extends WritableComparator implements Serializable {
-
+
public Comparator() {
super(Bigram.class);
}
-
+
/** Compare varibale length encoded numbers * */
@Override
- public int compare(byte[] b1, int s1, int l1,
- byte[] b2, int s2, int l2) {
+ public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
int ret;
try {
int firstb1 = WritableComparator.readVInt(b1, s1);
@@ -133,19 +132,21 @@
return ret;
}
}
-
- static { // register this comparator
+
+ static { // register this comparator
WritableComparator.define(Bigram.class, new Comparator());
}
-
- /** Compare only the first part of the bigram, so that reduce is called once for each value of the first part. */
- public static class FirstGroupingComparator
- extends WritableComparator implements Serializable {
-
+
+ /**
+ * Compare only the first part of the bigram, so that reduce is called once for each value of the first
+ * part.
+ */
+ public static class FirstGroupingComparator extends WritableComparator implements Serializable {
+
public FirstGroupingComparator() {
super(Bigram.class);
}
-
+
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
int ret;
@@ -158,7 +159,7 @@
}
return ret;
}
-
+
@Override
public int compare(Object o1, Object o2) {
if (o1 == null) {
@@ -171,47 +172,47 @@
return firstb1 - firstb2;
}
}
-
+
}
-
+
/** A wrapper class that associates pairs with frequency (Occurences) */
public static class Frequency implements Comparable<Frequency> {
-
+
private Bigram bigram = new Bigram();
private double frequency = 0.0;
-
+
public double getFrequency() {
return frequency;
}
-
+
public Bigram getBigram() {
return bigram;
}
-
+
public Frequency(Bigram bigram, double frequency) {
this.bigram = new Bigram(bigram);
this.frequency = frequency;
}
-
+
@Override
public int hashCode() {
return bigram.hashCode() + (int) Math.abs(Math.round(frequency * 31));
}
-
+
@Override
public boolean equals(Object right) {
- if (right == null || !(right instanceof Frequency)) {
+ if ((right == null) || !(right instanceof Frequency)) {
return false;
}
Frequency that = (Frequency) right;
return this.compareTo(that) == 0;
}
-
+
@Override
public int compareTo(Frequency that) {
return this.frequency > that.frequency ? 1 : -1;
}
-
+
@Override
public String toString() {
return bigram + "\t" + frequency;
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemBigramGenerator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemBigramGenerator.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemBigramGenerator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemBigramGenerator.java Sat Feb 13 20:54:05 2010
@@ -16,6 +16,11 @@
*/
package org.apache.mahout.cf.taste.hadoop.cooccurence;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
@@ -38,39 +43,35 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-
public final class ItemBigramGenerator extends Configured implements Tool {
-
+
private static final Logger log = LoggerFactory.getLogger(ItemBigramGenerator.class);
-
- public static class UserItemMapper extends MapReduceBase
- implements Mapper<LongWritable, Text, VIntWritable, VIntWritable> {
-
+
+ public static class UserItemMapper extends MapReduceBase implements
+ Mapper<LongWritable,Text,VIntWritable,VIntWritable> {
+
private static final Logger log = LoggerFactory.getLogger(UserItemMapper.class);
-
+
private final VIntWritable user = new VIntWritable(0);
private final VIntWritable item = new VIntWritable(0);
-
+
private String fieldSeparator;
-
+
enum Records {
INVALID_IDS,
INVALID_SCHEMA
}
-
+
@Override
public void configure(JobConf conf) {
fieldSeparator = conf.get("user.preference.field.separator", "\t");
}
-
+
@Override
- public void map(LongWritable lineNumber, Text userPrefEntry, OutputCollector<VIntWritable, VIntWritable> output,
- Reporter reporter)
- throws IOException {
+ public void map(LongWritable lineNumber,
+ Text userPrefEntry,
+ OutputCollector<VIntWritable,VIntWritable> output,
+ Reporter reporter) throws IOException {
String userPrefLine = userPrefEntry.toString();
String[] prefFields = userPrefLine.split(fieldSeparator);
if (prefFields.length > 1) {
@@ -82,47 +83,48 @@
output.collect(user, item);
} catch (NumberFormatException nfe) {
reporter.incrCounter(Records.INVALID_IDS, 1);
- log.warn("Invalid IDs in record: {}", userPrefLine);
+ UserItemMapper.log.warn("Invalid IDs in record: {}", userPrefLine);
} catch (IllegalArgumentException iae) {
reporter.incrCounter(Records.INVALID_IDS, 1);
- log.warn("Invalid IDs in record: {}", userPrefLine);
+ UserItemMapper.log.warn("Invalid IDs in record: {}", userPrefLine);
}
} else {
reporter.incrCounter(Records.INVALID_SCHEMA, 1);
- log.warn("No preference found in record: {}", userPrefLine);
+ UserItemMapper.log.warn("No preference found in record: {}", userPrefLine);
}
}
}
-
- public static class UserItemReducer extends MapReduceBase
- implements Reducer<VIntWritable, VIntWritable, VIntWritable, VIntWritable> {
-
+
+ public static class UserItemReducer extends MapReduceBase implements
+ Reducer<VIntWritable,VIntWritable,VIntWritable,VIntWritable> {
+
enum User {
TOO_FEW_ITEMS,
TOO_MANY_ITEMS
}
-
+
@Override
- public void reduce(VIntWritable user, Iterator<VIntWritable> itemIterator,
- OutputCollector<VIntWritable, VIntWritable> output, Reporter reporter)
- throws IOException {
+ public void reduce(VIntWritable user,
+ Iterator<VIntWritable> itemIterator,
+ OutputCollector<VIntWritable,VIntWritable> output,
+ Reporter reporter) throws IOException {
Collection<VIntWritable> itemSet = new HashSet<VIntWritable>();
while (itemIterator.hasNext()) {
itemSet.add(new VIntWritable(itemIterator.next().get()));
}
-
+
if (itemSet.size() <= 2) {
reporter.incrCounter(User.TOO_FEW_ITEMS, 1);
return;
}
-
+
if (itemSet.size() >= 10000) {
reporter.incrCounter(User.TOO_MANY_ITEMS, 1);
return;
}
-
+
VIntWritable[] items = itemSet.toArray(new VIntWritable[itemSet.size()]);
-
+
for (int i = 0; i < items.length; i++) {
for (int j = i + 1; j < items.length; j++) {
if (i != j) {
@@ -132,42 +134,41 @@
}
}
}
-
+
}
-
+
public JobConf prepareJob(String inputPaths, Path outputPath, int reducers) {
JobConf job = new JobConf(getConf());
job.setJarByClass(this.getClass());
job.setJobName("Item Bigram Generator");
-
+
job.setMapperClass(UserItemMapper.class);
job.setReducerClass(UserItemReducer.class);
-
+
job.setOutputKeyClass(VIntWritable.class);
job.setOutputValueClass(VIntWritable.class);
-
+
job.setOutputFormat(SequenceFileOutputFormat.class);
FileOutputFormat.setCompressOutput(job, true);
FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
- SequenceFileOutputFormat.setOutputCompressionType(job,
- SequenceFile.CompressionType.BLOCK);
-
+ SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.BLOCK);
+
job.setNumReduceTasks(reducers);
-
+
FileInputFormat.addInputPaths(job, inputPaths);
FileOutputFormat.setOutputPath(job, outputPath);
return job;
}
-
+
@Override
public int run(String[] args) throws IOException {
- // TODO use Commons CLI 2
+ // TODO use Commons CLI 2
if (args.length < 2) {
- log.error("Usage: ItemBigramGemerator <input-dir> <output-dir> [reducers]");
+ ItemBigramGenerator.log.error("Usage: ItemBigramGemerator <input-dir> <output-dir> [reducers]");
ToolRunner.printGenericCommandUsage(System.out);
return -1;
}
-
+
String inputPaths = args[0];
Path outputPath = new Path(args[1]);
int reducers = args.length > 2 ? Integer.parseInt(args[2]) : 1;
@@ -175,5 +176,5 @@
JobClient.runJob(jobConf);
return 0;
}
-
+
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemSimilarityEstimator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemSimilarityEstimator.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemSimilarityEstimator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/cooccurence/ItemSimilarityEstimator.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,11 @@
package org.apache.mahout.cf.taste.hadoop.cooccurence;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.PriorityQueue;
+import java.util.Queue;
+
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
@@ -41,62 +46,57 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.PriorityQueue;
-import java.util.Queue;
-
-
/**
- * This class feeds into all the item bigrams generated with ItemBigramGenerator. The input is partitioned on the first
- * item of the bigram, distributed and sorted by the map-reduce framework and grouped on first item of the bigram so
- * that each reducer sees all the bigrams for each unique first item.
+ * This class feeds into all the item bigrams generated with ItemBigramGenerator. The input is partitioned on
+ * the first item of the bigram, distributed and sorted by the map-reduce framework and grouped on first item
+ * of the bigram so that each reducer sees all the bigrams for each unique first item.
*/
public final class ItemSimilarityEstimator extends Configured implements Tool {
-
- private static final Logger log = LoggerFactory.getLogger(ItemSimilarityEstimator.class);
-
+
+ private static final Logger log = LoggerFactory.getLogger(ItemSimilarityEstimator.class);
+
/** Partition based on the first part of the bigram. */
- public static class FirstPartitioner implements Partitioner<Bigram, Writable> {
-
+ public static class FirstPartitioner implements Partitioner<Bigram,Writable> {
+
@Override
- public int getPartition(Bigram key, Writable value,
- int numPartitions) {
+ public int getPartition(Bigram key, Writable value, int numPartitions) {
return Math.abs(key.getFirst() % numPartitions);
}
-
+
@Override
public void configure(JobConf jobConf) {
- // Nothing to do here
+ // Nothing to do here
}
}
-
+
/** Output K -> (item1, item2), V -> ONE */
- public static class ItemItemMapper extends MapReduceBase
- implements Mapper<VIntWritable, VIntWritable, Bigram, Bigram> {
-
+ public static class ItemItemMapper extends MapReduceBase implements
+ Mapper<VIntWritable,VIntWritable,Bigram,Bigram> {
+
private final Bigram keyBigram = new Bigram();
private final Bigram valueBigram = new Bigram();
private static final int ONE = 1;
-
+
@Override
- public void map(VIntWritable item1, VIntWritable item2, OutputCollector<Bigram, Bigram> output, Reporter reporter)
- throws IOException {
+ public void map(VIntWritable item1,
+ VIntWritable item2,
+ OutputCollector<Bigram,Bigram> output,
+ Reporter reporter) throws IOException {
keyBigram.set(item1.get(), item2.get());
- valueBigram.set(item2.get(), ONE);
+ valueBigram.set(item2.get(), ItemItemMapper.ONE);
output.collect(keyBigram, valueBigram);
}
}
-
-
+
/* Test waters */
- public static class ItemItemCombiner extends MapReduceBase implements Reducer<Bigram, Bigram, Bigram, Bigram> {
-
+ public static class ItemItemCombiner extends MapReduceBase implements Reducer<Bigram,Bigram,Bigram,Bigram> {
+
@Override
- public void reduce(Bigram item, Iterator<Bigram> similarItemItr,
- OutputCollector<Bigram, Bigram> output, Reporter reporter)
- throws IOException {
+ public void reduce(Bigram item,
+ Iterator<Bigram> similarItemItr,
+ OutputCollector<Bigram,Bigram> output,
+ Reporter reporter) throws IOException {
int count = 0;
while (similarItemItr.hasNext()) {
Bigram candItem = similarItemItr.next();
@@ -106,26 +106,31 @@
output.collect(item, similarItem);
}
}
-
- /** All sorted bigrams for item1 are recieved in reduce. <p/> K -> (item1, item2), V -> (FREQ) */
- public static class ItemItemReducer extends MapReduceBase implements Reducer<Bigram, Bigram, Bigram, DoubleWritable> {
-
+
+ /**
+ * All sorted bigrams for item1 are recieved in reduce.
+ * <p/>
+ * K -> (item1, item2), V -> (FREQ)
+ */
+ public static class ItemItemReducer extends MapReduceBase implements
+ Reducer<Bigram,Bigram,Bigram,DoubleWritable> {
+
private final Queue<Bigram.Frequency> freqBigrams = new PriorityQueue<Bigram.Frequency>();
private Bigram key = new Bigram();
private DoubleWritable value = new DoubleWritable();
-
+
private long maxFrequentItems;
-
+
@Override
public void configure(JobConf conf) {
- maxFrequentItems = conf.
- getLong("max.frequent.items", 20);
+ maxFrequentItems = conf.getLong("max.frequent.items", 20);
}
-
+
@Override
- public void reduce(Bigram item, Iterator<Bigram> simItemItr,
- OutputCollector<Bigram, DoubleWritable> output, Reporter reporter)
- throws IOException {
+ public void reduce(Bigram item,
+ Iterator<Bigram> simItemItr,
+ OutputCollector<Bigram,DoubleWritable> output,
+ Reporter reporter) throws IOException {
int itemId = item.getFirst();
int prevItemId = item.getSecond();
int prevCount = 0;
@@ -144,7 +149,7 @@
enqueue(itemId, prevItemId, prevCount);
dequeueAll(output);
}
-
+
private void enqueue(int first, int second, int count) {
Bigram freqBigram = new Bigram(first, second);
freqBigrams.add(new Bigram.Frequency(freqBigram, count));
@@ -152,8 +157,8 @@
freqBigrams.poll();
}
}
-
- private void dequeueAll(OutputCollector<Bigram, DoubleWritable> output) throws IOException {
+
+ private void dequeueAll(OutputCollector<Bigram,DoubleWritable> output) throws IOException {
double totalScore = 0;
for (Bigram.Frequency freqBigram : freqBigrams) {
totalScore += freqBigram.getFrequency();
@@ -167,48 +172,47 @@
freqBigrams.clear();
}
}
-
-
+
public JobConf prepareJob(String inputPaths, Path outputPath, int maxFreqItems, int reducers) {
JobConf job = new JobConf(getConf());
job.setJobName("Item Bigram Counter");
job.setJarByClass(this.getClass());
-
+
job.setMapperClass(ItemItemMapper.class);
job.setCombinerClass(ItemItemCombiner.class);
job.setReducerClass(ItemItemReducer.class);
-
+
job.setMapOutputKeyClass(Bigram.class);
job.setMapOutputValueClass(Bigram.class);
job.setOutputKeyClass(Bigram.class);
job.setOutputValueClass(DoubleWritable.class);
-
+
job.setInputFormat(SequenceFileInputFormat.class);
job.setOutputFormat(SequenceFileOutputFormat.class);
FileOutputFormat.setCompressOutput(job, true);
FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
- SequenceFileOutputFormat.setOutputCompressionType(job,
- SequenceFile.CompressionType.BLOCK);
-
+ SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.BLOCK);
+
job.setPartitionerClass(FirstPartitioner.class);
job.setOutputValueGroupingComparator(Bigram.FirstGroupingComparator.class);
-
+
job.setInt("max.frequent.items", maxFreqItems);
job.setNumReduceTasks(reducers);
FileInputFormat.addInputPaths(job, inputPaths);
FileOutputFormat.setOutputPath(job, outputPath);
return job;
}
-
+
@Override
public int run(String[] args) throws IOException {
// TODO use Commons CLI 2
if (args.length < 2) {
- log.error("ItemSimilarityEstimator <input-dirs> <output-dir> [max-frequent-items] [reducers]");
+ ItemSimilarityEstimator.log
+ .error("ItemSimilarityEstimator <input-dirs> <output-dir> [max-frequent-items] [reducers]");
ToolRunner.printGenericCommandUsage(System.out);
return -1;
}
-
+
String inputPaths = args[0];
Path outputPath = new Path(args[1]);
int maxFreqItems = args.length > 2 ? Integer.parseInt(args[2]) : 20;
@@ -217,5 +221,5 @@
JobClient.runJob(jobConf);
return 0;
}
-
+
}