Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgoetze committed Dec 22, 2016
2 parents 1e355bc + 042e5b8 commit d83cc86
Show file tree
Hide file tree
Showing 69 changed files with 1,118 additions and 635 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--format documentation
--color
--order rand
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
7 changes: 5 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 All @@ -59,6 +59,9 @@ Here's how to contribute:

Please try to add RSpec tests along with your new features. This will ensure that your code does not break existing functionality and that your feature is working as expected.

We use [Rubocop](https://github.com/bbatsov/rubocop) for code style recommendations.
Please make sure your contributions comply with the default config of Rubocop.

## Acknowledgement

The original ideas for wrapping Weka in JRuby come from [@arrigonialberto86](https://github.com/arrigonialberto86) and his [ruby-band](https://github.com/arrigonialberto86/ruby-band) gem. Great thanks!
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
33 changes: 21 additions & 12 deletions lib/weka/class_builder.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require 'active_support/concern'
require 'active_support/core_ext/string'
require 'active_support/core_ext/module'
require 'weka/concerns'

module Weka
module ClassBuilder
extend ActiveSupport::Concern
def self.included(base)
base.extend(ClassMethods)
end

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 +35,27 @@ def java_super_modules
end

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

def deconstantize(name)
name.split('::')[0...-1].join('::')
end

def java_including_module
downcase_first_char(including_module)
end

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

def demodulize(name)
name.split('::').last
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 +72,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 @@ -75,7 +81,11 @@ def include_utils
end

def utils_defined?
utils_super_modules.constantize.const_defined?(:Utils)
constantize(utils_super_modules).const_defined?(:Utils)
end

def constantize(module_names)
Object.module_eval("::#{module_names}")
end

def utils
Expand All @@ -87,10 +97,9 @@ def utils_super_modules
end

def downcase_first_char(string)
return if string.blank?
return if string.nil? || string.empty?
string[0].downcase + string[1..-1]
end
end

end
end
37 changes: 18 additions & 19 deletions lib/weka/classifiers/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,34 @@ 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 confusion_matrix to_matrix_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
Loading

0 comments on commit d83cc86

Please sign in to comment.