rarff 0.1.0 → 0.2.0
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.
- data/README +16 -4
- data/lib/rarff.rb +8 -4
- data/tests/ts_rarff.rb +62 -28
- metadata +49 -37
data/README
CHANGED
@@ -7,18 +7,18 @@ Rarff is a Ruby library for dealing with Attribute-Relation File Format (ARFF) f
|
|
7
7
|
|
8
8
|
== License
|
9
9
|
|
10
|
-
Copyright (c)
|
10
|
+
Copyright (c) 2008 Andy Payne
|
11
11
|
All rights reserved.
|
12
12
|
|
13
13
|
Redistribution and use in source and binary forms, with or without
|
14
14
|
modification, are permitted provided that the following conditions are met:
|
15
15
|
|
16
|
-
|
16
|
+
* Redistributions of source code must retain the above copyright notice,
|
17
17
|
this list of conditions and the following disclaimer.
|
18
|
-
|
18
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
19
19
|
this list of conditions and the following disclaimer in the
|
20
20
|
documentation and/or other materials provided with the distribution.
|
21
|
-
|
21
|
+
* Neither the name of the COPYRIGHT OWNER nor the names of its contributors
|
22
22
|
may be used to endorse or promote products derived from this software
|
23
23
|
without specific prior written permission.
|
24
24
|
|
@@ -34,6 +34,11 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
34
34
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
35
|
|
36
36
|
|
37
|
+
== Changes
|
38
|
+
|
39
|
+
* Sparse ARFF files (thanks to Tom Adams)
|
40
|
+
|
41
|
+
|
37
42
|
== Todo
|
38
43
|
|
39
44
|
* Spaces or quotes in nominal types
|
@@ -63,6 +68,13 @@ Links to documentation:
|
|
63
68
|
* http://www.cs.waikato.ac.nz/~ml/weka/arff.html
|
64
69
|
* http://weka.sourceforge.net/wekadoc/index.php/en:ARFF_%283.4.6%29
|
65
70
|
|
71
|
+
== Contact Information
|
72
|
+
|
73
|
+
Andy Payne
|
74
|
+
Website: http://andy-payne.com/
|
75
|
+
Email: apayne .at. gmail.com
|
76
|
+
Twitter: http://twitter.com/andypayne
|
77
|
+
RARFF website: http://rubyforge.org/projects/rarff/
|
66
78
|
|
67
79
|
|
68
80
|
|
data/lib/rarff.rb
CHANGED
@@ -199,7 +199,7 @@ class Relation
|
|
199
199
|
end
|
200
200
|
|
201
201
|
|
202
|
-
def to_arff
|
202
|
+
def to_arff(sparse=false)
|
203
203
|
RELATION_MARKER + " #{@name}\n" +
|
204
204
|
@attributes.map{ |attr| attr.to_arff }.join("\n") +
|
205
205
|
"\n" +
|
@@ -216,9 +216,13 @@ class Relation
|
|
216
216
|
elsif @attributes[i].type =~ /^#{ATTRIBUTE_DATE}/i ## Hack comparison. Ugh.
|
217
217
|
col = '"' + col + '"'
|
218
218
|
end
|
219
|
-
col
|
220
|
-
|
221
|
-
|
219
|
+
if @attributes[i].type =~ /^#{ATTRIBUTE_NUMERIC}$/i and col == 0
|
220
|
+
nil
|
221
|
+
else
|
222
|
+
sparse ? "#{i} #{col}" : col
|
223
|
+
end
|
224
|
+
}.select{|c|not c.nil?}.join(', ')
|
225
|
+
}.join("\n").gsub(/^/, sparse ? '{' : '').gsub(/$/, sparse ? '}' : '')
|
222
226
|
end
|
223
227
|
|
224
228
|
|
data/tests/ts_rarff.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rarff'
|
|
5
5
|
|
6
6
|
class TestArffLib < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
8
|
+
# Test creation of an arff file string.
|
9
9
|
def test_arff_creation
|
10
10
|
|
11
11
|
arff_file_str = <<-END_OF_ARFF_FILE
|
@@ -25,9 +25,9 @@ END_OF_ARFF_FILE
|
|
25
25
|
arff_file_str.gsub!(/\n$/, '')
|
26
26
|
|
27
27
|
instances = [ [1.4, 'foo bar', 5, 'baz', "1900-08-08 12:12:12"],
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
[20.9, 'ruby', 46, 'rocks', "2005-10-23 12:12:12"],
|
29
|
+
[20.9, 'ruby', 46, 'rocks', "2001-02-19 12:12:12"],
|
30
|
+
[68.1, 'stuff', 728, 'is cool', "1974-02-10 12:12:12"]]
|
31
31
|
|
32
32
|
rel = Rarff::Relation.new('MyCoolRelation')
|
33
33
|
rel.instances = instances
|
@@ -35,38 +35,72 @@ END_OF_ARFF_FILE
|
|
35
35
|
rel.attributes[4].name = 'birthday'
|
36
36
|
rel.attributes[4].type = 'DATE "yyyy-MM-dd HH:mm:ss"'
|
37
37
|
|
38
|
-
#
|
38
|
+
# puts "rel.to_arff:\n(\n#{rel.to_arff}\n)\n"
|
39
39
|
assert_equal(rel.to_arff, arff_file_str, "Arff creation test failed.")
|
40
40
|
end
|
41
41
|
|
42
|
+
# Test creation of a sparse arff file string.
|
43
|
+
def test_sparse_arff_creation
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
arff_file_str = <<-END_OF_ARFF_FILE
|
46
|
+
@RELATION MyCoolRelation
|
47
|
+
@ATTRIBUTE Attr0 NUMERIC
|
48
|
+
@ATTRIBUTE subject STRING
|
49
|
+
@ATTRIBUTE Attr2 NUMERIC
|
50
|
+
@ATTRIBUTE Attr3 STRING
|
51
|
+
@ATTRIBUTE birthday DATE "yyyy-MM-dd HH:mm:ss"
|
52
|
+
@DATA
|
53
|
+
{0 1.4, 1 'foo bar', 3 baz, 4 "1900-08-08 12:12:12"}
|
54
|
+
{0 20.9, 1 ruby, 2 46, 3 rocks, 4 "2005-10-23 12:12:12"}
|
55
|
+
{1 ruby, 2 46, 3 rocks, 4 "2001-02-19 12:12:12"}
|
56
|
+
{0 68.1, 1 stuff, 3 'is cool', 4 "1974-02-10 12:12:12"}
|
57
|
+
END_OF_ARFF_FILE
|
58
|
+
|
59
|
+
arff_file_str.gsub!(/\n$/, '')
|
60
|
+
|
61
|
+
instances = [ [1.4, 'foo bar', 0, 'baz', "1900-08-08 12:12:12"],
|
62
|
+
[20.9, 'ruby', 46, 'rocks', "2005-10-23 12:12:12"],
|
63
|
+
[0.0, 'ruby', 46, 'rocks', "2001-02-19 12:12:12"],
|
64
|
+
[68.1, 'stuff', 0, 'is cool', "1974-02-10 12:12:12"]]
|
65
|
+
|
66
|
+
rel = Rarff::Relation.new('MyCoolRelation')
|
67
|
+
rel.instances = instances
|
68
|
+
rel.attributes[1].name = 'subject'
|
69
|
+
rel.attributes[4].name = 'birthday'
|
70
|
+
rel.attributes[4].type = 'DATE "yyyy-MM-dd HH:mm:ss"'
|
71
|
+
|
72
|
+
# puts "rel.to_arff(true):\n(\n#{rel.to_arff(true)}\n)\n"
|
73
|
+
assert_equal(rel.to_arff(true), arff_file_str, "Arff creation test failed.")
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Test parsing of an arff file.
|
78
|
+
def test_arff_parse
|
79
|
+
in_file = './test_arff.arff'
|
80
|
+
rel = Rarff::Relation.new
|
81
|
+
rel.parse(File.open(in_file).read)
|
48
82
|
|
49
|
-
|
50
|
-
|
51
|
-
|
83
|
+
assert_equal(rel.instances[2][1], 3.2)
|
84
|
+
assert_equal(rel.instances[7][4], 'Iris-setosa')
|
85
|
+
end
|
52
86
|
|
53
87
|
|
54
|
-
|
88
|
+
# Test parsing of sparse ARFF format
|
55
89
|
def test_sparse_arff_parse
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
#
|
69
|
-
|
90
|
+
in_file = './test_sparse_arff.arff'
|
91
|
+
rel = Rarff::Relation.new
|
92
|
+
rel.parse(File.open(in_file).read)
|
93
|
+
|
94
|
+
assert_equal(rel.instances[0].size, 13)
|
95
|
+
assert_equal(rel.instances[0][1], 0)
|
96
|
+
assert_equal(rel.instances[0][3], 7)
|
97
|
+
assert_equal(rel.instances[1][1], 2.4)
|
98
|
+
assert_equal(rel.instances[1][2], 0)
|
99
|
+
assert_equal(rel.instances[1][12], 19)
|
100
|
+
assert_equal(rel.instances[2][6], 6)
|
101
|
+
assert_equal(rel.instances[3][12], 0)
|
102
|
+
# puts "\n\nARFF: (\n#{rel.to_arff}\n)"
|
103
|
+
end
|
70
104
|
end
|
71
105
|
|
72
106
|
|
metadata
CHANGED
@@ -1,45 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.11
|
3
|
-
specification_version: 1
|
4
2
|
name: rarff
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-09-18 00:00:00 -05:00
|
8
|
-
summary: Library for handling Weka ARFF files
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: apayne@gmail.com
|
12
|
-
homepage: TODO
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire: rarff
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
-
|
22
|
-
- ">"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.0.0
|
25
|
-
version:
|
4
|
+
version: 0.2.0
|
26
5
|
platform: ruby
|
27
|
-
signing_key:
|
28
|
-
cert_chain:
|
29
6
|
authors:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
- README
|
7
|
+
- Andy Payne
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-22 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: RARFF is a library for handling Weka ARFF files
|
17
|
+
email: apayne@gmail.com
|
42
18
|
executables: []
|
19
|
+
|
43
20
|
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- lib/rarff.rb
|
27
|
+
- tests/test_arff.arff
|
28
|
+
- tests/test_sparse_arff.arff
|
29
|
+
- tests/ts_rarff.rb
|
30
|
+
has_rdoc: false
|
31
|
+
homepage: http://rubyforge.org/projects/rarff/
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
44
49
|
requirements: []
|
45
|
-
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: RARFF is a library for handling Weka ARFF files
|
56
|
+
test_files: []
|
57
|
+
|