Skip to content

Commit

Permalink
fixed conflicts, made gem 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben J Woodcroft committed Feb 18, 2009
2 parents 17f0e52 + ec32d43 commit 80c1fee
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
7 changes: 6 additions & 1 deletion History.txt
@@ -1,9 +1,14 @@
== Changes == Changes


=== 0.2.2 === 0.2.3


* Added set_string_attributes_to_nominal for easy conversion of string attributes to nominal ones * 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) === 0.2.1 (unofficial)


* Handles missing data in output, encoded internally as nil values * Handles missing data in output, encoded internally as nil values
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -3,7 +3,7 @@ require 'hoe'
#require './lib/rarff.rb' #require './lib/rarff.rb'


gem_name = 'rarff' 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.author = "Andy Payne, Ben J Woodcroft"
p.email = "apayne .at. gmail.com, b.woodcroft@pgrad.unimelb.edu.au" p.email = "apayne .at. gmail.com, b.woodcroft@pgrad.unimelb.edu.au"
Expand Down
14 changes: 10 additions & 4 deletions lib/rarff.rb
Expand Up @@ -53,14 +53,18 @@ module Rarff
ATTRIBUTE_INTEGER = 'INTEGER' ATTRIBUTE_INTEGER = 'INTEGER'
ATTRIBUTE_STRING = 'STRING' ATTRIBUTE_STRING = 'STRING'
ATTRIBUTE_DATE = 'DATE' 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}' ATTRIBUTE_BOOLEAN = '{false, true}'


MISSING = '?' MISSING = '?'


################################################################################ ################################################################################


class Attribute class Attribute
attr_accessor :name, :type attr_accessor :name
attr_reader :type


def initialize(name='', type='') def initialize(name='', type='')
@name = name @name = name
Expand Down Expand Up @@ -102,7 +106,7 @@ def add_nominal_value(str)


def to_arff def to_arff
if @type_is_nominal == true if @type_is_nominal == true
ATTRIBUTE_MARKER + " #{@name} #{@type.join(',')}" ATTRIBUTE_MARKER + " #{@name} #{@type.join(',').gsub(' ','_')}"
else else
ATTRIBUTE_MARKER + " #{@name} #{@type}" ATTRIBUTE_MARKER + " #{@name} #{@type}"
end end
Expand All @@ -118,7 +122,8 @@ def to_s




class Relation class Relation
attr_accessor :name, :attributes, :instances attr_accessor :name, :attributes
attr_reader :instances




def initialize(name='') def initialize(name='')
Expand Down Expand Up @@ -243,7 +248,8 @@ def expand_sparse(str)


def to_arff(sparse=false) def to_arff(sparse=false)
RELATION_MARKER + " #{@name}\n" + RELATION_MARKER + " #{@name}\n" +
@attributes.map{ |attr| attr.to_arff }.join("\n") + # @attributes.map{ |attr| attr.to_arff }.join("\n") +
@attributes.join("\n") +
"\n" + "\n" +
DATA_MARKER + "\n" + DATA_MARKER + "\n" +


Expand Down
2 changes: 1 addition & 1 deletion rarff.gemspec
Expand Up @@ -2,7 +2,7 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{rarff} 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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Andy Payne, Ben J Woodcroft"] s.authors = ["Andy Payne, Ben J Woodcroft"]
Expand Down
24 changes: 23 additions & 1 deletion test/test_rarff.rb
Expand Up @@ -101,7 +101,6 @@ def test_arff_creation
# assert_equal(0, rel.instances[3][12]) # assert_equal(0, rel.instances[3][12])
# # puts "\n\nARFF: (\n#{rel.to_arff}\n)" # # puts "\n\nARFF: (\n#{rel.to_arff}\n)"
# end # end
#
def test_output_missing def test_output_missing
arff_file_str = <<-END_OF_ARFF_FILE arff_file_str = <<-END_OF_ARFF_FILE
@RELATION MyCoolRelation @RELATION MyCoolRelation
Expand Down Expand Up @@ -220,6 +219,29 @@ def test_strings_as_nominal
# puts "rel.to_arff:\n(\n#{rel.to_arff}\n)\n" # puts "rel.to_arff:\n(\n#{rel.to_arff}\n)\n"
assert_equal(arff_file_str, rel.to_arff, "test_strings_as_nominal") assert_equal(arff_file_str, rel.to_arff, "test_strings_as_nominal")
end 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 end




Expand Down

0 comments on commit 80c1fee

Please sign in to comment.