Skip to content

Commit

Permalink
Refactoring dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasinov committed Dec 10, 2012
1 parent 6645b20 commit a0f21c2
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.DS_Store
log/*.log
pkg/
.rbenv-version
.rbenv-version
*.gem
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
jruby_mahout (0.2.0)
jruby_mahout (0.2.1)

GEM
remote: http://rubygems.org/
Expand Down
8 changes: 3 additions & 5 deletions jruby_mahout.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$LOAD_PATH << File.expand_path("../lib", __FILE__)
$:.push File.expand_path("../lib", __FILE__)
require "jruby_mahout/version"

Gem::Specification.new do |gem|
Expand All @@ -11,11 +11,9 @@ Gem::Specification.new do |gem|
gem.description = "Jruby Mahout is a gem that unleashes the power of Apache Mahout in the world of Jruby. Mahout is a superior machine learning library written in Java. It deals with recommendations, clustering and classification machine learning problems at scale. Until now it was difficult to use it in Ruby projects. You'd have to implement Java interfaces in Jruby yourself, which is not quick especially if you just started exploring the world of machine learning."
gem.license = "MIT"

gem.files = Dir["{lib}/**/*"] + ["MIT-LICENSE", "README.md"]
gem.files = Dir["lib/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
gem.test_files = Dir["spec/**/*"]
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.require_paths = ["lib"]
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }

gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
Expand Down
8 changes: 7 additions & 1 deletion lib/jruby_mahout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ module JrubyMahout
require File.join(ENV["MAHOUT_DIR"], 'mahout-integration-0.7.jar')
require File.join(ENV["MAHOUT_DIR"], 'mahout-math-0.7.jar')
Dir.glob(File.join(ENV["MAHOUT_DIR"], 'lib/*.jar')).each { |d| require d }
Dir['./lib/jruby_mahout/*.rb'].each{ |f| require f }

require 'jruby_mahout/recommender'
require 'jruby_mahout/recommender_builder'
require 'jruby_mahout/data_model'
require 'jruby_mahout/evaluator'
require 'jruby_mahout/postgres_manager'
require 'jruby_mahout/mysql_manager'
end
2 changes: 2 additions & 0 deletions lib/jruby_mahout/data_model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module JrubyMahout
class DataModel
java_import org.apache.mahout.cf.taste.impl.model.file.FileDataModel

attr_accessor :data_model

def initialize(data_model_type, params)
Expand Down
2 changes: 2 additions & 0 deletions lib/jruby_mahout/evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module JrubyMahout
class Evaluator
java_import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator

def initialize(data_model, recommender_builder)
@data_model = data_model
@recommender_builder = recommender_builder
Expand Down
27 changes: 7 additions & 20 deletions lib/jruby_mahout/mahout_imports.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
# Recommenders
java_import org.apache.mahout.cf.taste.eval.RecommenderBuilder
java_import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.EuclideanDistanceSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.SpearmanCorrelationSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity


# Neighborhoods
java_import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood


# Recommenders
java_import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender
java_import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender
java_import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender


# Weighting
java_import org.apache.mahout.cf.taste.common.Weighting


# Evaluators
java_import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator


# Data Models
java_import org.apache.mahout.cf.taste.impl.model.jdbc.PostgreSQLJDBCDataModel
java_import org.apache.mahout.cf.taste.impl.model.file.FileDataModel



# Postgres
begin
java_import org.postgresql.ds.PGPoolingDataSource
rescue Exception => e
puts e
end

8 changes: 8 additions & 0 deletions lib/jruby_mahout/postgres_manager.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module JrubyMahout
class PostgresManager
java_import org.apache.mahout.cf.taste.impl.model.jdbc.PostgreSQLJDBCDataModel

begin
java_import org.postgresql.ds.PGPoolingDataSource
rescue Exception => e
puts e
end

attr_accessor :data_model, :data_source, :statement

def initialize(params)
Expand Down
16 changes: 16 additions & 0 deletions lib/jruby_mahout/recommender_builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
module JrubyMahout
class RecommenderBuilder
java_import org.apache.mahout.cf.taste.eval.RecommenderBuilder
java_import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.EuclideanDistanceSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.SpearmanCorrelationSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity
java_import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity

java_import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood

java_import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender
java_import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender
java_import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender

java_import org.apache.mahout.cf.taste.common.Weighting

attr_accessor :recommender_name, :item_based_allowed
# public interface RecommenderBuilder
# Implementations of this inner interface are simple helper classes which create a Recommender to be evaluated based on the given DataModel.
Expand Down
2 changes: 1 addition & 1 deletion lib/jruby_mahout/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JrubyMahout
VERSION = '0.2.0'
VERSION = '0.2.1'
end

0 comments on commit a0f21c2

Please sign in to comment.