Skip to content

Commit

Permalink
Merge pull request #7 from paulgoetze/feature/cleanup
Browse files Browse the repository at this point in the history
Code and specs cleanup
  • Loading branch information
paulgoetze authored Jun 23, 2016
2 parents 1e355bc + 1945b22 commit ca87645
Show file tree
Hide file tree
Showing 63 changed files with 315 additions and 372 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ cache:
- bundler

before_install:
- gem install bundler
- rvm get head
- rvm use jruby-9.0.1.0 --install
- gem install bundler

script: bundle exec rake spec
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The weka gem tries to carry over the namespaces defined in Weka and enhances som

The idea behind keeping the namespaces is, that you can also use the [Weka documentation](http://weka.sourceforge.net/doc.dev/) for looking up functionality and classes.

Please refer to [the gems Wiki](https://github.com/paulgoetze/weka-jruby/wiki) for
Please refer to [the gems Wiki](https://github.com/paulgoetze/weka-jruby/wiki) for
detailed information about how to use weka with JRuby and some examplary code snippets.

## Development
Expand All @@ -49,7 +49,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/paulgo

For development we use the [git branching model](http://nvie.com/posts/a-successful-git-branching-model/) described by [nvie](https://github.com/nvie).

Here's how to contribute:
Heres how to contribute:

1. Fork it ( https://github.com/paulgoetze/weka-jruby/fork )
2. Create your feature branch (`git checkout -b feature/my-new-feature develop`)
Expand Down
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :prepare
task :install => :prepare
task default: :prepare
task install: :prepare

desc 'Install weka jars & dependencies'
task :prepare do
Expand All @@ -15,7 +15,7 @@ task :prepare do
LockJar.install('Jarfile.lock', local_repo: jars_dir)
end

desc "Start an irb session with the gem loaded"
desc 'Start an irb session with the gem loaded'
task :irb do
sh 'irb -I ./lib -r weka'
end
8 changes: 4 additions & 4 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "weka"
require 'bundler/setup'
require 'weka'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# require 'pry'
# Pry.start

require "irb"
require 'irb'
IRB.start
5 changes: 2 additions & 3 deletions lib/weka/attribute_selection/attribute_selection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module AttributeSelection
java_import 'weka.attributeSelection.AttributeSelection'

class AttributeSelection

alias :summary :to_results_string
alias :selected_attributes_count :number_attributes_selected
alias summary to_results_string
alias selected_attributes_count number_attributes_selected
end
end
end
10 changes: 4 additions & 6 deletions lib/weka/class_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module ClassBuilder
extend ActiveSupport::Concern

module ClassMethods

def build_class(class_name, weka_module: nil, include_concerns: true)
java_import java_class_path(class_name, weka_module)
define_class(class_name, weka_module, include_concerns: include_concerns)
Expand Down Expand Up @@ -37,19 +36,19 @@ def java_super_modules
end

def super_modules
toplevel_module? ? self.name : self.name.deconstantize
toplevel_module? ? name : name.deconstantize
end

def java_including_module
downcase_first_char(including_module)
end

def including_module
self.name.demodulize unless toplevel_module?
name.demodulize unless toplevel_module?
end

def toplevel_module?
self.name.scan('::').count == 1
name.scan('::').count == 1
end

def define_class(class_name, weka_module, include_concerns: true)
Expand All @@ -66,7 +65,7 @@ def include_serializable_for(class_name, weka_module)
class_path = java_class_path(class_name, weka_module)
serializable = Weka::Core::SerializationHelper.serializable?(class_path)

"include Weka::Concerns::Serializable" if serializable
'include Weka::Concerns::Serializable' if serializable
end

def include_utils
Expand All @@ -91,6 +90,5 @@ def downcase_first_char(string)
string[0].downcase + string[1..-1]
end
end

end
end
36 changes: 17 additions & 19 deletions lib/weka/classifiers/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,33 @@ module Classifiers
java_import 'weka.classifiers.Evaluation'

class Evaluation

# Use both nomenclatures f_measure and fmeasure for consistency
# due to jruby's auto method generation of 'fMeasure' to 'f_measure' and
# 'weightedFMeasure' to 'weighted_fmeasure'.
alias :weighted_f_measure :weighted_fmeasure
alias :fmeasure :f_measure
alias weighted_f_measure weighted_fmeasure
alias fmeasure f_measure

alias :summary :to_summary_string
alias :class_details :to_class_details_string
alias summary to_summary_string
alias class_details to_class_details_string

alias :instance_count :num_instances
alias :correct_count :correct
alias :incorrect_count :incorrect
alias :unclassified_count :unclassified
alias instance_count num_instances
alias correct_count correct
alias incorrect_count incorrect
alias unclassified_count unclassified

alias :correct_percentage :pct_correct
alias :incorrect_percentage :pct_incorrect
alias :unclassified_percentage :pct_unclassified
alias correct_percentage pct_correct
alias incorrect_percentage pct_incorrect
alias unclassified_percentage pct_unclassified

alias :true_negative_count :num_true_negatives
alias :false_negative_count :num_false_negatives
alias :true_positive_count :num_true_positives
alias :false_positive_count :num_false_positives
alias :average_cost :avg_cost
alias true_negative_count num_true_negatives
alias false_negative_count num_false_negatives
alias true_positive_count num_true_positives
alias false_positive_count num_false_positives
alias average_cost avg_cost

alias :cumulative_margin_distribution :to_cumulative_margin_distribution_string
alias cumulative_margin_distribution to_cumulative_margin_distribution_string
end

Java::WekaClassifiers::Evaluation.__persistent__ = true

end
end
3 changes: 1 addition & 2 deletions lib/weka/classifiers/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def add_training_instance(instance)
end

def add_training_data(data)
values = self.training_instances.internal_values_of(data)
values = training_instances.internal_values_of(data)
instance = Weka::Core::DenseInstance.new(values)
add_training_instance(instance)
end
Expand Down Expand Up @@ -132,7 +132,6 @@ def class_distributions_from(distributions)
end
end
end

end
end
end
6 changes: 2 additions & 4 deletions lib/weka/clusterers/cluster_evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ module Clusterers
java_import 'weka.clusterers.ClusterEvaluation'

class ClusterEvaluation

alias :summary :cluster_results_to_string
alias :clusters_count :num_clusters
alias summary cluster_results_to_string
alias clusters_count num_clusters
end

Java::WekaClusterers::ClusterEvaluation.__persistent__ = true

end
end
4 changes: 1 addition & 3 deletions lib/weka/clusterers/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def add_training_instance(instance)
end

def add_training_data(data)
values = self.training_instances.internal_values_of(data)
values = training_instances.internal_values_of(data)
instance = Weka::Core::DenseInstance.new(values)
add_training_instance(instance)
end
Expand Down Expand Up @@ -96,8 +96,6 @@ def clusterable_instance_from(instance_or_values)
instances.first
end
end

end
end
end

2 changes: 0 additions & 2 deletions lib/weka/concerns/buildable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ module Buildable
extend ActiveSupport::Concern

module ClassMethods

def build(&block)
instance = new
instance.instance_eval(&block) if block_given?
instance
end
end

end
end
end
1 change: 0 additions & 1 deletion lib/weka/concerns/describable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Describable
extend ActiveSupport::Concern

module ClassMethods

def description
new.global_info
end
Expand Down
3 changes: 1 addition & 2 deletions lib/weka/concerns/optionizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Optionizable
extend ActiveSupport::Concern

included do
java_import "weka.core.Utils"
java_import 'weka.core.Utils'

def use_options(*single_options, **hash_options)
joined_options = join_options(single_options, hash_options)
Expand Down Expand Up @@ -43,7 +43,6 @@ def default_options
new.get_options.to_a.join(' ')
end
end

end
end
end
5 changes: 1 addition & 4 deletions lib/weka/concerns/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ module Persistent
extend ActiveSupport::Concern

included do
if self.respond_to?(:__persistent__=)
self.__persistent__ = true
end
self.__persistent__ = true if respond_to?(:__persistent__=)
end

end
end
end
3 changes: 1 addition & 2 deletions lib/weka/concerns/serializable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def serialize(filename)
Weka::Core::SerializationHelper.write(filename, self)
end
end

end
end
end
end
3 changes: 1 addition & 2 deletions lib/weka/core/attribute.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Weka
module Core
java_import "weka.core.Attribute"
java_import 'weka.core.Attribute'

class Attribute

def values
enumerate_values.to_a
end
Expand Down
12 changes: 6 additions & 6 deletions lib/weka/core/dense_instance.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Weka
module Core
java_import "weka.core.DenseInstance"
java_import 'weka.core.DenseInstance'

class DenseInstance
java_import "java.util.Date"
java_import "java.text.SimpleDateFormat"
java_import 'java.util.Date'
java_import 'java.text.SimpleDateFormat'

def initialize(data, weight: 1.0)
if data.kind_of?(Integer)
if data.is_a?(Integer)
super(data)
else
super(weight, to_java_double(data))
Expand Down Expand Up @@ -38,8 +38,8 @@ def to_a
end
end

alias :values :to_a
alias :values_count :num_values
alias values to_a
alias values_count num_values

private

Expand Down
Loading

0 comments on commit ca87645

Please sign in to comment.