weka 0.5.0-java → 0.6.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +3 -11
- data/CHANGELOG.md +68 -0
- data/README.md +6 -2
- data/Rakefile +1 -11
- data/lib/weka.rb +1 -3
- data/lib/weka/class_builder.rb +1 -1
- data/lib/weka/classifiers/evaluation.rb +2 -0
- data/lib/weka/classifiers/utils.rb +44 -18
- data/lib/weka/clusterers/utils.rb +39 -15
- data/lib/weka/core/instances.rb +39 -31
- data/lib/weka/core/serialization_helper.rb +38 -0
- data/lib/weka/exceptions.rb +2 -0
- data/lib/weka/version.rb +1 -1
- data/weka.gemspec +3 -2
- metadata +20 -21
- data/Jarfile +0 -1
- data/Jarfile.lock +0 -17
- data/lib/weka/jars.rb +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 17c3a647cf8e23d2c81a4f456c7e3e576a8e768c
|
|
4
|
+
data.tar.gz: 90419f5ac130f3a1e44c860947b68ed8fd7e1fc3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e940c23d7234b6a3dad46e9625040912122d046916bb1db31f1c57abc0eacd14b2ee08178010340a12e55a3fe99039f348ea944067ec1b1c6996e0adb4954fd
|
|
7
|
+
data.tar.gz: ad512593515521dbe0dc5627628df1ccfa2e8a9279acf1359a75f2321911c65bfe2e5ef32527ffa872743514e48554e73fbf88744e8989f6ae93449c40266df1
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
|
@@ -2,14 +2,6 @@ sudo: false
|
|
|
2
2
|
language: ruby
|
|
3
3
|
|
|
4
4
|
rvm:
|
|
5
|
-
- jruby-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
- bundler
|
|
9
|
-
|
|
10
|
-
before_install:
|
|
11
|
-
- rvm get head
|
|
12
|
-
- rvm use jruby-9.0.1.0 --install
|
|
13
|
-
- gem install bundler
|
|
14
|
-
|
|
15
|
-
script: bundle exec rake spec
|
|
5
|
+
- jruby-9.0.0.0
|
|
6
|
+
- jruby-9.1.0.0
|
|
7
|
+
- jruby-head
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.6.0] – 2017-12-17
|
|
11
|
+
### Added
|
|
12
|
+
- #copy method for Weka::Core::Instances
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Load Jars with jar-dependencies instead of lock_jar gem
|
|
16
|
+
- Make Weka::Core::Instances#instance_from public
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- Weka::UnassignedTrainingInstancesError when running #classify/#cluster and
|
|
20
|
+
#distribution_for on deserialized classfiers and clusterers
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## [0.5.0] – 2017-06-17
|
|
24
|
+
### Added
|
|
25
|
+
- #to_m (to Matrix) method for Weka::Core::Instances
|
|
26
|
+
- Curve classes in Weka::Classifiers::Evaluation module
|
|
27
|
+
- Allow including additional modules on class building
|
|
28
|
+
- Rubocop config for project
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- Allow passing a hash to Weka::Core::Instances#add_instance
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
- Block argument in Weka::Core::Instances#initialize
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## [0.4.0] – 2016-12-22
|
|
38
|
+
### Added
|
|
39
|
+
- C45 converters
|
|
40
|
+
- Full support for string attributes
|
|
41
|
+
|
|
42
|
+
### Removed
|
|
43
|
+
- ActiveSupport as dependency
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## [0.3.0] – 2016-02-10
|
|
47
|
+
### Added
|
|
48
|
+
- Allow adding Instances with missing values
|
|
49
|
+
- Allow creating DenseInstances with missing values
|
|
50
|
+
- #merge method for Weka::Core:Instances
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## [0.2.0] – 2016-01-19
|
|
54
|
+
### Added
|
|
55
|
+
- Serialization/deserialization functionality
|
|
56
|
+
- #apply_filters method for Weka::Core::Instances
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## [0.1.0] – 2015-12-26
|
|
60
|
+
Initial release
|
|
61
|
+
|
|
62
|
+
[Unreleased]: https://github.com/paulgoetze/weka-jruby/compare/v0.6.0...HEAD
|
|
63
|
+
[0.6.0]: https://github.com/paulgoetze/weka-jruby/compare/v0.5.0...v0.6.0
|
|
64
|
+
[0.5.0]: https://github.com/paulgoetze/weka-jruby/compare/v0.4.0...v0.5.0
|
|
65
|
+
[0.4.0]: https://github.com/paulgoetze/weka-jruby/compare/v0.3.0...v0.4.0
|
|
66
|
+
[0.3.0]: https://github.com/paulgoetze/weka-jruby/compare/v0.2.0...v0.3.0
|
|
67
|
+
[0.2.0]: https://github.com/paulgoetze/weka-jruby/compare/v0.1.0...v0.2.0
|
|
68
|
+
[0.1.0]: https://github.com/paulgoetze/weka-jruby/compare/ce6a985017c28ea755290a9baba4d81acddc2d20...v0.1.0
|
data/README.md
CHANGED
|
@@ -39,8 +39,12 @@ detailed information about how to use weka with JRuby and some examplary code sn
|
|
|
39
39
|
|
|
40
40
|
## Development
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
1. Check out the repo with `git clone git@github.com:paulgoetze/weka-jruby.git`.
|
|
43
|
+
2. Set a local environment variable `export JARS_VENDOR=false`.
|
|
44
|
+
This will prevent
|
|
45
|
+
compiling the jars into your repo’s /lib directory and will load them from your local maven repository instead.
|
|
46
|
+
See the [jar-dependencies README](https://github.com/mkristian/jar-dependencies#for-development-you-do-not-need-to-vendor-the-jars-at-all) for more information.
|
|
47
|
+
3. Run `bin/setup` or `bundle install` to install the dependencies.
|
|
44
48
|
|
|
45
49
|
Then, run `rake spec` to run the tests. You can also run `bin/console` or `rake irb` for an interactive prompt that will allow you to experiment.
|
|
46
50
|
|
data/Rakefile
CHANGED
|
@@ -3,17 +3,7 @@ require 'rspec/core/rake_task'
|
|
|
3
3
|
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
|
5
5
|
|
|
6
|
-
task default: :
|
|
7
|
-
task install: :prepare
|
|
8
|
-
|
|
9
|
-
desc 'Install weka jars & dependencies'
|
|
10
|
-
task :prepare do
|
|
11
|
-
require 'lock_jar'
|
|
12
|
-
lib_path = File.expand_path('.', File.dirname(__FILE__))
|
|
13
|
-
jars_dir = File.join(lib_path, 'jars')
|
|
14
|
-
|
|
15
|
-
LockJar.install('Jarfile.lock', local_repo: jars_dir)
|
|
16
|
-
end
|
|
6
|
+
task default: :spec
|
|
17
7
|
|
|
18
8
|
desc 'Start an irb session with the gem loaded'
|
|
19
9
|
task :irb do
|
data/lib/weka.rb
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
require 'java'
|
|
2
|
-
require 'weka/jars'
|
|
3
2
|
require 'weka/version'
|
|
4
3
|
require 'weka/exceptions'
|
|
4
|
+
require Dir[File.join(File.dirname(__FILE__), '*_jars.rb')].first
|
|
5
5
|
|
|
6
6
|
module Weka
|
|
7
|
-
include Jars
|
|
8
|
-
|
|
9
7
|
class << self
|
|
10
8
|
def require_all(type)
|
|
11
9
|
files = Dir[File.expand_path("../weka/#{type}/**/*.rb", __FILE__)]
|
data/lib/weka/class_builder.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'weka/class_builder'
|
|
2
|
+
require 'weka/concerns'
|
|
2
3
|
|
|
3
4
|
module Weka
|
|
4
5
|
module Classifiers
|
|
@@ -6,6 +7,7 @@ module Weka
|
|
|
6
7
|
|
|
7
8
|
class Evaluation
|
|
8
9
|
include ClassBuilder
|
|
10
|
+
include Weka::Concerns::Persistent
|
|
9
11
|
|
|
10
12
|
# Use both nomenclatures f_measure and fmeasure for consistency
|
|
11
13
|
# due to jruby's auto method generation of 'fMeasure' to 'f_measure' and
|
|
@@ -19,7 +19,7 @@ module Weka
|
|
|
19
19
|
|
|
20
20
|
error = 'Class attribute is not assigned for Instances.'
|
|
21
21
|
hint = 'You can assign a class attribute with #class_attribute=.'
|
|
22
|
-
message = "#{error}
|
|
22
|
+
message = "#{error}\n#{hint}"
|
|
23
23
|
|
|
24
24
|
raise UnassignedClassError, message
|
|
25
25
|
end
|
|
@@ -29,27 +29,49 @@ module Weka
|
|
|
29
29
|
|
|
30
30
|
error = 'Classifier is not trained with Instances.'
|
|
31
31
|
hint = 'You can set the training instances with #train_with_instances.'
|
|
32
|
-
message = "#{error}
|
|
32
|
+
message = "#{error}\n#{hint}"
|
|
33
33
|
|
|
34
34
|
raise UnassignedTrainingInstancesError, message
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
def ensure_valid_instances_structure!(instances)
|
|
38
|
+
unless instances.is_a?(Weka::Core::Instances)
|
|
39
|
+
message = 'Instances has to be a Weka::Core::Instances object.'
|
|
40
|
+
raise ArgumentError, message
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
return if training_instances.nil?
|
|
44
|
+
return if instances.equal_headers(training_instances)
|
|
45
|
+
|
|
46
|
+
message = 'The passed instances need to have the same structure as ' \
|
|
47
|
+
'the classifier’s training instances.'
|
|
48
|
+
|
|
49
|
+
raise InvalidInstancesStructureError, message
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def ensure_instances_structure_available!
|
|
53
|
+
return unless instances_structure.nil?
|
|
54
|
+
|
|
55
|
+
error = 'Classifier does not have any instances structure info.'
|
|
56
|
+
hint = 'You probably tried to classify values with a ' \
|
|
57
|
+
'classifier that is untrained or doesn’t have an ' \
|
|
58
|
+
'instances_structure set. Please run ' \
|
|
59
|
+
'#train_with_instances, try serializing and ' \
|
|
60
|
+
'deserializing your classifier again in case you used a ' \
|
|
61
|
+
'deserialized classifier or set its instances_structure.'
|
|
62
|
+
message = "#{error}\n#{hint}"
|
|
63
|
+
|
|
64
|
+
raise MissingInstancesStructureError, message
|
|
65
|
+
end
|
|
36
66
|
end
|
|
37
67
|
|
|
38
68
|
module Transformers
|
|
39
69
|
private
|
|
40
70
|
|
|
41
71
|
def classifiable_instance_from(instance_or_values)
|
|
42
|
-
|
|
43
|
-
instances = Weka::Core::Instances.new(attributes: attributes)
|
|
72
|
+
ensure_instances_structure_available!
|
|
44
73
|
|
|
45
|
-
|
|
46
|
-
class_index = training_instances.class_index
|
|
47
|
-
instances.insert_attribute_at(class_attribute, class_index)
|
|
48
|
-
|
|
49
|
-
instances.class_index = training_instances.class_index
|
|
50
|
-
instances.add_instance(instance_or_values)
|
|
51
|
-
|
|
52
|
-
instance = instances.first
|
|
74
|
+
instance = instances_structure.instance_from(instance_or_values)
|
|
53
75
|
instance.set_class_missing
|
|
54
76
|
instance
|
|
55
77
|
end
|
|
@@ -60,16 +82,24 @@ module Weka
|
|
|
60
82
|
include Checks
|
|
61
83
|
|
|
62
84
|
attr_reader :training_instances
|
|
85
|
+
attr_reader :instances_structure
|
|
63
86
|
|
|
64
87
|
def train_with_instances(instances)
|
|
65
88
|
ensure_class_attribute_assigned!(instances)
|
|
66
89
|
|
|
67
90
|
@training_instances = instances
|
|
91
|
+
@instances_structure = instances.string_free_structure
|
|
92
|
+
|
|
68
93
|
build_classifier(instances)
|
|
69
94
|
|
|
70
95
|
self
|
|
71
96
|
end
|
|
72
97
|
|
|
98
|
+
def instances_structure=(instances)
|
|
99
|
+
ensure_valid_instances_structure!(instances)
|
|
100
|
+
@instances_structure = instances.string_free_structure
|
|
101
|
+
end
|
|
102
|
+
|
|
73
103
|
def cross_validate(folds: 3)
|
|
74
104
|
ensure_trained_with_instances!
|
|
75
105
|
|
|
@@ -101,8 +131,6 @@ module Weka
|
|
|
101
131
|
include Transformers
|
|
102
132
|
|
|
103
133
|
def classify(instance_or_values)
|
|
104
|
-
ensure_trained_with_instances!
|
|
105
|
-
|
|
106
134
|
instance = classifiable_instance_from(instance_or_values)
|
|
107
135
|
index = classify_instance(instance)
|
|
108
136
|
|
|
@@ -112,7 +140,7 @@ module Weka
|
|
|
112
140
|
private
|
|
113
141
|
|
|
114
142
|
def class_value_of_index(index)
|
|
115
|
-
|
|
143
|
+
instances_structure.class_attribute.value(index)
|
|
116
144
|
end
|
|
117
145
|
end
|
|
118
146
|
|
|
@@ -136,8 +164,6 @@ module Weka
|
|
|
136
164
|
include Transformers
|
|
137
165
|
|
|
138
166
|
def distribution_for(instance_or_values)
|
|
139
|
-
ensure_trained_with_instances!
|
|
140
|
-
|
|
141
167
|
instance = classifiable_instance_from(instance_or_values)
|
|
142
168
|
distributions = distribution_for_instance(instance)
|
|
143
169
|
|
|
@@ -147,7 +173,7 @@ module Weka
|
|
|
147
173
|
private
|
|
148
174
|
|
|
149
175
|
def class_distributions_from(distributions)
|
|
150
|
-
class_values =
|
|
176
|
+
class_values = instances_structure.class_attribute.values
|
|
151
177
|
|
|
152
178
|
distributions.each_with_object({}).with_index do |(distribution, result), index|
|
|
153
179
|
class_value = class_values[index]
|
|
@@ -27,21 +27,39 @@ module Weka
|
|
|
27
27
|
|
|
28
28
|
error = 'Clusterer is not trained with Instances.'
|
|
29
29
|
hint = 'You can set the training instances with #train_with_instances.'
|
|
30
|
-
message = "#{error}
|
|
30
|
+
message = "#{error}\n#{hint}"
|
|
31
31
|
|
|
32
32
|
raise UnassignedTrainingInstancesError, message
|
|
33
33
|
end
|
|
34
|
-
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
def ensure_valid_instances_structure!(instances)
|
|
36
|
+
unless instances.is_a?(Weka::Core::Instances)
|
|
37
|
+
message = 'Instances has to be a Weka::Core::Instances object.'
|
|
38
|
+
raise ArgumentError, message
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
return if training_instances.nil?
|
|
42
|
+
return if instances.equal_headers(training_instances)
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
instances = Weka::Core::Instances.new(attributes: attributes)
|
|
44
|
+
message = 'The passed instances need to have the same structure as ' \
|
|
45
|
+
'the clusterers training instances.'
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
raise InvalidInstancesStructureError, message
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def ensure_instances_structure_available!
|
|
51
|
+
return unless instances_structure.nil?
|
|
52
|
+
|
|
53
|
+
error = 'Clusterer does not have any instances structure info.'
|
|
54
|
+
hint = 'You probably tried to cluster values with a clusterer ' \
|
|
55
|
+
'that is untrained or doesn’t have an ' \
|
|
56
|
+
'instances_structure set. Please run ' \
|
|
57
|
+
'#train_with_instances, try serializing and ' \
|
|
58
|
+
'deserializing your clusterer again in case you used a ' \
|
|
59
|
+
'deserialized clusterer or set its instances_structure.'
|
|
60
|
+
message = "#{error}\n#{hint}"
|
|
61
|
+
|
|
62
|
+
raise MissingInstancesStructureError, message
|
|
45
63
|
end
|
|
46
64
|
end
|
|
47
65
|
|
|
@@ -49,14 +67,22 @@ module Weka
|
|
|
49
67
|
include Checks
|
|
50
68
|
|
|
51
69
|
attr_reader :training_instances
|
|
70
|
+
attr_reader :instances_structure
|
|
52
71
|
|
|
53
72
|
def train_with_instances(instances)
|
|
54
73
|
@training_instances = instances
|
|
74
|
+
@instances_structure = instances.string_free_structure
|
|
75
|
+
|
|
55
76
|
build_clusterer(instances)
|
|
56
77
|
|
|
57
78
|
self
|
|
58
79
|
end
|
|
59
80
|
|
|
81
|
+
def instances_structure=(instances)
|
|
82
|
+
ensure_valid_instances_structure!(instances)
|
|
83
|
+
@instances_structure = instances.string_free_structure
|
|
84
|
+
end
|
|
85
|
+
|
|
60
86
|
def evaluate(test_instances)
|
|
61
87
|
ensure_trained_with_instances!
|
|
62
88
|
|
|
@@ -85,12 +111,11 @@ module Weka
|
|
|
85
111
|
|
|
86
112
|
module Clusterable
|
|
87
113
|
include Checks
|
|
88
|
-
include Transformers
|
|
89
114
|
|
|
90
115
|
def cluster(instance_or_values)
|
|
91
|
-
|
|
116
|
+
ensure_instances_structure_available!
|
|
92
117
|
|
|
93
|
-
instance =
|
|
118
|
+
instance = instances_structure.instance_from(instance_or_values)
|
|
94
119
|
cluster_instance(instance)
|
|
95
120
|
end
|
|
96
121
|
end
|
|
@@ -112,12 +137,11 @@ module Weka
|
|
|
112
137
|
|
|
113
138
|
module Distributable
|
|
114
139
|
include Checks
|
|
115
|
-
include Transformers
|
|
116
140
|
|
|
117
141
|
def distribution_for(instance_or_values)
|
|
118
|
-
|
|
142
|
+
ensure_instances_structure_available!
|
|
119
143
|
|
|
120
|
-
instance =
|
|
144
|
+
instance = instances_structure.instance_from(instance_or_values)
|
|
121
145
|
distribution_for_instance(instance).to_a
|
|
122
146
|
end
|
|
123
147
|
end
|
data/lib/weka/core/instances.rb
CHANGED
|
@@ -47,6 +47,11 @@ module Weka
|
|
|
47
47
|
super(relation_name.to_s, attribute_list, 0)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
def copy
|
|
51
|
+
constructor = Instances.java_class.declared_constructor(Instances)
|
|
52
|
+
constructor.new_instance(self).to_java(Instances)
|
|
53
|
+
end
|
|
54
|
+
|
|
50
55
|
def instances
|
|
51
56
|
enumerate_instances.to_a
|
|
52
57
|
end
|
|
@@ -267,6 +272,33 @@ module Weka
|
|
|
267
272
|
Matrix[*instances.map(&:values)]
|
|
268
273
|
end
|
|
269
274
|
|
|
275
|
+
# Wrap the attribute values for the instance to be added with
|
|
276
|
+
# an Instance object, if needed. The Instance object is
|
|
277
|
+
# assigned with the given weight.
|
|
278
|
+
#
|
|
279
|
+
# @param [Instance, Array, Hash] instance_or_values either the
|
|
280
|
+
# instance object to be added or the attribute values for it.
|
|
281
|
+
# For the latter case, it accepts an array or a hash.
|
|
282
|
+
#
|
|
283
|
+
# @param [Float] weight the weight for the Instance to be added
|
|
284
|
+
#
|
|
285
|
+
# @return [Instance] the object that contains the given
|
|
286
|
+
# attribute values.
|
|
287
|
+
def instance_from(instance_or_values, weight: 1.0)
|
|
288
|
+
dataset = string_free_structure
|
|
289
|
+
|
|
290
|
+
if instance_or_values.is_a?(Java::WekaCore::Instance)
|
|
291
|
+
instance = instance_or_values
|
|
292
|
+
instance.weight = weight
|
|
293
|
+
else
|
|
294
|
+
data = instance_data(instance_or_values)
|
|
295
|
+
instance = DenseInstance.new(data, weight: weight)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
dataset.add(instance)
|
|
299
|
+
dataset.first
|
|
300
|
+
end
|
|
301
|
+
|
|
270
302
|
private
|
|
271
303
|
|
|
272
304
|
def add_attribute(attribute)
|
|
@@ -291,42 +323,18 @@ module Weka
|
|
|
291
323
|
end
|
|
292
324
|
end
|
|
293
325
|
|
|
294
|
-
# Wrap the attribute values for the instance to be added with
|
|
295
|
-
# an Instance object, if needed. The Instance object is
|
|
296
|
-
# assigned with the given weight.
|
|
297
|
-
#
|
|
298
|
-
# @param [Instance, Array, Hash] instance_or_values either the
|
|
299
|
-
# instance object to be added or the attribute values for it.
|
|
300
|
-
# For the latter case, it accepts an array or a hash.
|
|
301
|
-
#
|
|
302
|
-
# @param [Float] weight the weight for the Instance to be added
|
|
303
|
-
#
|
|
304
|
-
# @return [Instance] the object that contains the given
|
|
305
|
-
# attribute values.
|
|
306
|
-
def instance_from(instance_or_values, weight:)
|
|
307
|
-
if instance_or_values.is_a?(Java::WekaCore::Instance)
|
|
308
|
-
instance_or_values.weight = weight
|
|
309
|
-
instance_or_values
|
|
310
|
-
else
|
|
311
|
-
if instance_or_values.is_a?(Hash)
|
|
312
|
-
instance_or_values = attribute_values_from_hash(instance_or_values)
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
data = internal_values_of(instance_or_values)
|
|
316
|
-
|
|
317
|
-
if has_string_attribute?
|
|
318
|
-
data = check_string_attributes(data, instance_or_values)
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
DenseInstance.new(data, weight: weight)
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
|
|
325
326
|
def map_attribute_type(type)
|
|
326
327
|
return -1 unless Attribute::TYPES.include?(type.downcase.to_sym)
|
|
327
328
|
Attribute.const_get(type.upcase)
|
|
328
329
|
end
|
|
329
330
|
|
|
331
|
+
def instance_data(values)
|
|
332
|
+
values = attribute_values_from_hash(values) if values.is_a?(Hash)
|
|
333
|
+
data = internal_values_of(values)
|
|
334
|
+
data = check_string_attributes(data, values) if has_string_attribute?
|
|
335
|
+
data
|
|
336
|
+
end
|
|
337
|
+
|
|
330
338
|
# Convert a hash whose keys are attribute names and values are attribute
|
|
331
339
|
# values into an array containing attribute values in the order
|
|
332
340
|
# of the Instances attributes.
|
|
@@ -3,9 +3,47 @@ module Weka
|
|
|
3
3
|
java_import 'weka.core.SerializationHelper'
|
|
4
4
|
|
|
5
5
|
class SerializationHelper
|
|
6
|
+
STRUCTURE_FILE_EXTENSION = 'structure'.freeze
|
|
7
|
+
|
|
6
8
|
class << self
|
|
9
|
+
original_read = instance_method(:read)
|
|
10
|
+
original_write = instance_method(:write)
|
|
11
|
+
|
|
12
|
+
define_method(:read) do |filename|
|
|
13
|
+
object = original_read.bind(self).call(filename)
|
|
14
|
+
|
|
15
|
+
structure_filename = structure_file(filename)
|
|
16
|
+
structure_needed = object.respond_to?(:instances_structure)
|
|
17
|
+
structure_available = File.exist?(structure_filename)
|
|
18
|
+
|
|
19
|
+
if structure_needed && structure_available
|
|
20
|
+
structure = original_read.bind(self).call(structure_filename)
|
|
21
|
+
object.instances_structure = structure
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
object
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
define_method(:write) do |filename, object|
|
|
28
|
+
structure_needed = object.respond_to?(:instances_structure)
|
|
29
|
+
|
|
30
|
+
if structure_needed && object.instances_structure
|
|
31
|
+
structure_filename = structure_file(filename)
|
|
32
|
+
structure = object.instances_structure
|
|
33
|
+
original_write.bind(self).call(structure_filename, structure)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
original_write.bind(self).call(filename, object)
|
|
37
|
+
end
|
|
38
|
+
|
|
7
39
|
alias deserialize read
|
|
8
40
|
alias serialize write
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def structure_file(filename)
|
|
45
|
+
"#{filename}.#{STRUCTURE_FILE_EXTENSION}"
|
|
46
|
+
end
|
|
9
47
|
end
|
|
10
48
|
end
|
|
11
49
|
end
|
data/lib/weka/exceptions.rb
CHANGED
data/lib/weka/version.rb
CHANGED
data/weka.gemspec
CHANGED
|
@@ -23,10 +23,11 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
24
24
|
spec.require_paths = ['lib']
|
|
25
25
|
|
|
26
|
-
spec.add_runtime_dependency 'lock_jar', '~> 0.13'
|
|
27
|
-
|
|
28
26
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
|
29
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
30
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
31
29
|
spec.add_development_dependency 'shoulda-matchers', '~> 3.0'
|
|
30
|
+
|
|
31
|
+
spec.add_runtime_dependency 'jar-dependencies', '~> 0.3.11'
|
|
32
|
+
spec.requirements << 'jar nz.ac.waikato.cms.weka, weka-dev, 3.7.13'
|
|
32
33
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: weka
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: java
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Götze
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-12-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - "~>"
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0.13'
|
|
19
|
-
name: lock_jar
|
|
20
|
-
prerelease: false
|
|
21
|
-
type: :runtime
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.13'
|
|
27
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
requirement: !ruby/object:Gem::Requirement
|
|
29
15
|
requirements:
|
|
@@ -80,6 +66,20 @@ dependencies:
|
|
|
80
66
|
- - "~>"
|
|
81
67
|
- !ruby/object:Gem::Version
|
|
82
68
|
version: '3.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 0.3.11
|
|
75
|
+
name: jar-dependencies
|
|
76
|
+
prerelease: false
|
|
77
|
+
type: :runtime
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 0.3.11
|
|
83
83
|
description: A JRuby wrapper for the Weka library (http://www.cs.waikato.ac.nz/ml/weka/)
|
|
84
84
|
email:
|
|
85
85
|
- paul.christoph.goetze@gmail.com
|
|
@@ -93,10 +93,9 @@ files:
|
|
|
93
93
|
- ".rspec"
|
|
94
94
|
- ".rubocop.yml"
|
|
95
95
|
- ".travis.yml"
|
|
96
|
+
- CHANGELOG.md
|
|
96
97
|
- CODE_OF_CONDUCT.md
|
|
97
98
|
- Gemfile
|
|
98
|
-
- Jarfile
|
|
99
|
-
- Jarfile.lock
|
|
100
99
|
- MIT-LICENSE.txt
|
|
101
100
|
- README.md
|
|
102
101
|
- Rakefile
|
|
@@ -142,7 +141,6 @@ files:
|
|
|
142
141
|
- lib/weka/filters/unsupervised/attribute.rb
|
|
143
142
|
- lib/weka/filters/unsupervised/instance.rb
|
|
144
143
|
- lib/weka/filters/utils.rb
|
|
145
|
-
- lib/weka/jars.rb
|
|
146
144
|
- lib/weka/version.rb
|
|
147
145
|
- weka.gemspec
|
|
148
146
|
homepage: https://github.com/paulgoetze/weka-jruby
|
|
@@ -163,9 +161,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
163
161
|
- - ">="
|
|
164
162
|
- !ruby/object:Gem::Version
|
|
165
163
|
version: '0'
|
|
166
|
-
requirements:
|
|
164
|
+
requirements:
|
|
165
|
+
- jar nz.ac.waikato.cms.weka, weka-dev, 3.7.13
|
|
167
166
|
rubyforge_project:
|
|
168
|
-
rubygems_version: 2.6.
|
|
167
|
+
rubygems_version: 2.6.14
|
|
169
168
|
signing_key:
|
|
170
169
|
specification_version: 4
|
|
171
170
|
summary: Machine Learning & Data Mining with JRuby.
|
data/Jarfile
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
jar 'nz.ac.waikato.cms.weka:weka-dev:jar:3.7.13'
|
data/Jarfile.lock
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
version: 0.13.0
|
|
3
|
-
groups:
|
|
4
|
-
default:
|
|
5
|
-
dependencies:
|
|
6
|
-
- nz.ac.waikato.cms.weka.thirdparty:java-cup-11b-runtime:jar:2015.03.26
|
|
7
|
-
- nz.ac.waikato.cms.weka.thirdparty:java-cup-11b:jar:2015.03.26
|
|
8
|
-
- nz.ac.waikato.cms.weka:weka-dev:jar:3.7.13
|
|
9
|
-
- org.pentaho.pentaho-commons:pentaho-package-manager:jar:1.0.11
|
|
10
|
-
artifacts:
|
|
11
|
-
- jar:nz.ac.waikato.cms.weka:weka-dev:jar:3.7.13:
|
|
12
|
-
transitive:
|
|
13
|
-
nz.ac.waikato.cms.weka.thirdparty:java-cup-11b:jar:2015.03.26: {}
|
|
14
|
-
org.pentaho.pentaho-commons:pentaho-package-manager:jar:1.0.11: {}
|
|
15
|
-
nz.ac.waikato.cms.weka.thirdparty:java-cup-11b-runtime:jar:2015.03.26: {}
|
|
16
|
-
remote_repositories:
|
|
17
|
-
- http://repo1.maven.org/maven2/
|
data/lib/weka/jars.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module Weka
|
|
2
|
-
module Jars
|
|
3
|
-
def self.included(base)
|
|
4
|
-
base.class_eval do
|
|
5
|
-
require 'lock_jar'
|
|
6
|
-
|
|
7
|
-
lib_path = File.expand_path('../../', File.dirname(__FILE__))
|
|
8
|
-
lockfile = File.join(lib_path, 'Jarfile.lock')
|
|
9
|
-
jars_dir = File.join(lib_path, 'jars')
|
|
10
|
-
|
|
11
|
-
LockJar.install(lockfile, local_repo: jars_dir)
|
|
12
|
-
LockJar.load(lockfile, local_repo: jars_dir)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|