Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed conflicts, made gem 0.2.3

  • Loading branch information...
commit 80c1feefd24dcb9ff3ae1e64838f33edff42cd62 2 parents 17f0e52 + ec32d43
Ben J Woodcroft authored
View
7 History.txt
@@ -1,9 +1,14 @@
== Changes
-=== 0.2.2
+=== 0.2.3
* Added set_string_attributes_to_nominal for easy conversion of string attributes to nominal ones
+=== 0.2.2 (unofficial)
+
+* Handles boolean inputs, which are modelled as nominals
+* Handles spaces in nominals, which are replaced by underscores. Probably should be quoting these, but is good enough for me right now
+
=== 0.2.1 (unofficial)
* Handles missing data in output, encoded internally as nil values
View
2  Rakefile
@@ -3,7 +3,7 @@ require 'hoe'
#require './lib/rarff.rb'
gem_name = 'rarff'
-hoe = Hoe.new(gem_name,'0.2.2') do |p|
+hoe = Hoe.new(gem_name,'0.2.3') do |p|
p.author = "Andy Payne, Ben J Woodcroft"
p.email = "apayne .at. gmail.com, b.woodcroft@pgrad.unimelb.edu.au"
View
14 lib/rarff.rb
@@ -53,6 +53,9 @@ module Rarff
ATTRIBUTE_INTEGER = 'INTEGER'
ATTRIBUTE_STRING = 'STRING'
ATTRIBUTE_DATE = 'DATE'
+ # Model Boolean as a Nominal Attribute.
+ # Use {false, true} not {true, false} because then in visualisations in Weka
+ # true is to the right, which makes more intuitive sense
ATTRIBUTE_BOOLEAN = '{false, true}'
MISSING = '?'
@@ -60,7 +63,8 @@ module Rarff
################################################################################
class Attribute
- attr_accessor :name, :type
+ attr_accessor :name
+ attr_reader :type
def initialize(name='', type='')
@name = name
@@ -102,7 +106,7 @@ def add_nominal_value(str)
def to_arff
if @type_is_nominal == true
- ATTRIBUTE_MARKER + " #{@name} #{@type.join(',')}"
+ ATTRIBUTE_MARKER + " #{@name} #{@type.join(',').gsub(' ','_')}"
else
ATTRIBUTE_MARKER + " #{@name} #{@type}"
end
@@ -118,7 +122,8 @@ def to_s
class Relation
- attr_accessor :name, :attributes, :instances
+ attr_accessor :name, :attributes
+ attr_reader :instances
def initialize(name='')
@@ -243,7 +248,8 @@ def expand_sparse(str)
def to_arff(sparse=false)
RELATION_MARKER + " #{@name}\n" +
- @attributes.map{ |attr| attr.to_arff }.join("\n") +
+# @attributes.map{ |attr| attr.to_arff }.join("\n") +
+ @attributes.join("\n") +
"\n" +
DATA_MARKER + "\n" +
View
2  rarff.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{rarff}
- s.version = "0.2.2"
+ s.version = "0.2.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Andy Payne, Ben J Woodcroft"]
View
24 test/test_rarff.rb
@@ -101,7 +101,6 @@ def test_arff_creation
# assert_equal(0, rel.instances[3][12])
# # puts "\n\nARFF: (\n#{rel.to_arff}\n)"
# end
- #
def test_output_missing
arff_file_str = <<-END_OF_ARFF_FILE
@RELATION MyCoolRelation
@@ -220,6 +219,29 @@ def test_strings_as_nominal
# puts "rel.to_arff:\n(\n#{rel.to_arff}\n)\n"
assert_equal(arff_file_str, rel.to_arff, "test_strings_as_nominal")
end
+
+ def test_boolean_2
+ arff_file_str = <<-END_OF_ARFF_FILE
+@RELATION MyCoolRelation
+@ATTRIBUTE Attr0 NUMERIC
+@ATTRIBUTE subject STRING
+@ATTRIBUTE Attr2 {false,true}
+@DATA
+?, ?, ?
+20.9, ruby, true
+ END_OF_ARFF_FILE
+
+ arff_file_str.gsub!(/\n$/, '')
+
+ instances = [ [nil, nil, nil],
+ [20.9, 'ruby', true]]
+
+ rel = Rarff::Relation.new('MyCoolRelation')
+ rel.instances = instances
+ rel.attributes[1].name = 'subject'
+
+ assert_equal(arff_file_str, rel.to_arff, "missing data output failure")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.