rarff 0.2.0 → 0.2.2

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.
@@ -0,0 +1,21 @@
1
+ %1. Title: Snippet of Balance Scale Weight & Distance Database
2
+ %
3
+ %2. Second heading:
4
+
5
+ @relation balance-scale
6
+ @attribute left-weight real
7
+ %3. Attribute-interleaved comment
8
+ @attribute left-distance real
9
+ @attribute right-weight real
10
+ @attribute right-distance real
11
+ @attribute class { L, B, R}
12
+ %4. attribute-data comment
13
+ @data
14
+ 1,1,3,4,R
15
+ %5. data-interleaved comment
16
+ 1,1,3,5,R
17
+ %
18
+ %6. trailing comment
19
+ %
20
+ %7. blank lines are kept
21
+ % 8. leading spaces are kept
@@ -0,0 +1,11 @@
1
+ 1. Title: Snippet of Balance Scale Weight & Distance Database,1
2
+ ,2
3
+ 2. Second heading:,3
4
+ 3. Attribute-interleaved comment,7
5
+ 4. attribute-data comment,12
6
+ 5. data-interleaved comment,15
7
+ ,17
8
+ 6. trailing comment,18
9
+ ,19
10
+ 7. blank lines are kept,20
11
+ 8. leading spaces are kept,21
@@ -1,12 +1,13 @@
1
1
  # See the README file for more information.
2
2
 
3
3
  require 'test/unit'
4
- require 'rarff'
4
+ require '../lib/rarff'
5
+ require 'csv'
5
6
 
6
7
  class TestArffLib < Test::Unit::TestCase
7
8
 
8
- # Test creation of an arff file string.
9
- def test_arff_creation
9
+ # Test creation of an arff file string.
10
+ def test_arff_creation
10
11
 
11
12
  arff_file_str = <<-END_OF_ARFF_FILE
12
13
  @RELATION MyCoolRelation
@@ -20,89 +21,101 @@ class TestArffLib < Test::Unit::TestCase
20
21
  20.9, ruby, 46, rocks, "2005-10-23 12:12:12"
21
22
  20.9, ruby, 46, rocks, "2001-02-19 12:12:12"
22
23
  68.1, stuff, 728, 'is cool', "1974-02-10 12:12:12"
23
- END_OF_ARFF_FILE
24
+ END_OF_ARFF_FILE
24
25
 
25
- arff_file_str.gsub!(/\n$/, '')
26
+ arff_file_str.gsub!(/\n$/, '')
26
27
 
27
- instances = [ [1.4, 'foo bar', 5, 'baz', "1900-08-08 12:12:12"],
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"]]
28
+ instances = [[1.4, 'foo bar', 5, 'baz', "1900-08-08 12:12:12"],
29
+ [20.9, 'ruby', 46, 'rocks', "2005-10-23 12:12:12"],
30
+ [20.9, 'ruby', 46, 'rocks', "2001-02-19 12:12:12"],
31
+ [68.1, 'stuff', 728, 'is cool', "1974-02-10 12:12:12"]]
31
32
 
32
- rel = Rarff::Relation.new('MyCoolRelation')
33
- rel.instances = instances
34
- rel.attributes[1].name = 'subject'
35
- rel.attributes[4].name = 'birthday'
36
- rel.attributes[4].type = 'DATE "yyyy-MM-dd HH:mm:ss"'
33
+ rel = Rarff::Relation.new('MyCoolRelation')
34
+ rel.instances = instances
35
+ rel.attributes[1].name = 'subject'
36
+ rel.attributes[4].name = 'birthday'
37
+ rel.attributes[4].type = 'DATE "yyyy-MM-dd HH:mm:ss"'
37
38
 
38
- # puts "rel.to_arff:\n(\n#{rel.to_arff}\n)\n"
39
- assert_equal(rel.to_arff, arff_file_str, "Arff creation test failed.")
40
- end
39
+ # puts "rel.to_arff:\n(\n#{rel.to_arff}\n)\n"
40
+ assert_equal(rel.to_arff, arff_file_str, "Arff creation test failed.")
41
+ end
41
42
 
42
- # Test creation of a sparse arff file string.
43
- def test_sparse_arff_creation
44
43
 
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
44
+ # Test parsing of an arff file.
45
+ def test_arff_parse
46
+ in_file = './test_arff.arff'
47
+ rel = Rarff::Relation.new
48
+ rel.parse(File.open(in_file).read)
75
49
 
50
+ assert_equal(rel.instances[2][1], 3.2)
51
+ assert_equal(rel.instances[7][4], 'Iris-setosa')
52
+ end
76
53
 
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)
82
-
83
- assert_equal(rel.instances[2][1], 3.2)
84
- assert_equal(rel.instances[7][4], 'Iris-setosa')
85
- end
86
-
87
-
88
- # Test parsing of sparse ARFF format
89
- def test_sparse_arff_parse
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
104
- end
105
54
 
55
+ # Test parsing of sparse ARFF format
56
+ def test_sparse_arff_parse
57
+ in_file = './test_sparse_arff.arff'
58
+ rel = Rarff::Relation.new
59
+ rel.parse(File.open(in_file).read)
106
60
 
61
+ assert_equal(rel.instances[0].size, 13)
62
+ assert_equal(rel.instances[0][1], 0)
63
+ assert_equal(rel.instances[0][3], 7)
64
+ assert_equal(rel.instances[1][1], 2.4)
65
+ assert_equal(rel.instances[1][2], 0)
66
+ assert_equal(rel.instances[1][12], 19)
67
+ assert_equal(rel.instances[2][6], 6)
68
+ assert_equal(rel.instances[3][12], 0)
69
+ # puts "\n\nARFF: (\n#{rel.to_arff}\n)"
70
+ end
107
71
 
72
+ def test_case_insensitivity
73
+ in_file = './test_case_arff.arff'
74
+ rel = Rarff::Relation.new
75
+ rel.parse(File.open(in_file).read)
76
+
77
+ assert_equal(5, rel.attributes.count, "Incorrect number of attributes found")
78
+
79
+ end
80
+
81
+ def test_attributes_keep_their_names
82
+ in_file = './test_case_arff.arff'
83
+ rel = Rarff::Relation.new
84
+ rel.parse(File.open(in_file).read)
85
+
86
+ assert_equal('left-weight', rel.attributes[0].name, "first attribute not as expected")
87
+ assert_equal('class', rel.attributes[4].name, "last attribute not as expected")
88
+
89
+ end
90
+
91
+ def test_all_comments_stored
92
+ in_file = './test_comments_arff.arff'
93
+ in_comments_csv = './test_comments_raw.csv'
94
+
95
+ comments = []
96
+
97
+ CSV.foreach(in_comments_csv) do |row|
98
+ comments << Rarff::Comment.new(row[0].to_s,row[1].to_i)
99
+ end
100
+
101
+ rel = Rarff::Relation.new
102
+ in_file_contents = File.open(in_file).read
103
+ rel.parse(in_file_contents)
104
+
105
+ assert_equal(comments.length, rel.comments.length, "Some comments not stored or extra comments stored")
106
+ assert_equal(comments, rel.comments, "Comments / lines differ")
107
+ end
108
+
109
+ def test_input_to_output_match
110
+ #todo
111
+ #in_file = './test_comments_arff.arff'
112
+ #rel = Rarff::Relation.new
113
+ #
114
+ #in_file_contents = File.open(in_file).read
115
+ #rel.parse(in_file_contents)
116
+ #
117
+ #assert_equal(rel.to_arff, in_file_contents, "Arff input and output don't match'.")
118
+
119
+ end
120
+ end
108
121
 
metadata CHANGED
@@ -1,57 +1,54 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rarff
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Andy Payne
8
- autorequire:
9
+ autorequire: rarff
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2008-11-22 00:00:00 -06:00
13
- default_executable:
12
+ date: 2013-01-23 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
- description: RARFF is a library for handling Weka ARFF files
14
+ description:
17
15
  email: apayne@gmail.com
18
16
  executables: []
19
-
20
17
  extensions: []
21
-
22
- extra_rdoc_files: []
23
-
24
- files:
25
- - README
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
26
21
  - lib/rarff.rb
27
22
  - tests/test_arff.arff
23
+ - tests/test_case_arff.arff
24
+ - tests/test_comments_arff.arff
25
+ - tests/test_comments_raw.csv
28
26
  - tests/test_sparse_arff.arff
29
27
  - tests/ts_rarff.rb
30
- has_rdoc: false
31
- homepage: http://rubyforge.org/projects/rarff/
28
+ - README.md
29
+ homepage: https://github.com/andypayne/rarff
30
+ licenses: []
32
31
  post_install_message:
33
32
  rdoc_options: []
34
-
35
- require_paths:
33
+ require_paths:
36
34
  - 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:
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
49
47
  requirements: []
50
-
51
48
  rubyforge_project:
52
- rubygems_version: 1.2.0
49
+ rubygems_version: 1.8.24
53
50
  signing_key:
54
- specification_version: 2
55
- summary: RARFF is a library for handling Weka ARFF files
56
- test_files: []
57
-
51
+ specification_version: 3
52
+ summary: Library for handling Weka ARFF files
53
+ test_files:
54
+ - tests/ts_rarff.rb