Class/Module Index [+]

Quicksearch

Statsample::GGobi

Public Class Methods

out(dataset,opt={}) click to toggle source
# File lib/statsample/converters.rb, line 288
                        def out(dataset,opt={})
                                require 'ostruct'
                                default_opt = {:dataname => "Default", :description=>"", :missing=>"NA"}
                                default_opt.merge! opt
                                carrier=OpenStruct.new
                                carrier.categorials=[]
                                carrier.conversions={}
                                variables_def=dataset.fields.collect{|k|
                                        variable_definition(carrier,dataset[k],k)
                                }.join("\n")
                                
                                indexes=carrier.categorials.inject({}) {|s,c|
                                        s[dataset.fields.index(c)]=c
                                        s
                                }
                                records=""
                                dataset.each_array {|c|
                                        indexes.each{|ik,iv|
                                                c[ik]=carrier.conversions[iv][c[ik]]
                                        }
                                        records << "<record>#{values_definition(c, default_opt[:missing])}</record>\n"
                                }
                                
out=<?xml version="1.0"?><!DOCTYPE ggobidata SYSTEM "ggobi.dtd"><ggobidata count="1"><data name="#{default_opt[:dataname]}"><description>#{default_opt[:description]}</description><variables count="#{dataset.fields.size}">#{variables_def}</variables>    <records count="#{dataset.cases}" missingValue="#{default_opt[:missing]}">#{records}</records></data></ggobidata>

out

                        end
values_definition(c,missing) click to toggle source
# File lib/statsample/converters.rb, line 331
def values_definition(c,missing)
  c.collect{|v|
    if v.nil?
      "#{missing}"
    elsif v.is_a? Numeric
      "#{v}"
    else
      "#{v.gsub(/\s+/,"_")}"
    end
  }.join(" ")
end
variable_definition(carrier,v,name,nickname=nil) click to toggle source

Outputs a string for a variable definition v = vector name = name of the variable nickname = nickname

# File lib/statsample/converters.rb, line 346
def variable_definition(carrier,v,name,nickname=nil)
        nickname = (nickname.nil? ? "" : "nickname=\"#{nickname}\"" )
        if v.type==:nominal or v.data.find {|d|  d.is_a? String }
                carrier.categorials.push(name)
                carrier.conversions[name]={}
                factors=v.factors
                out ="<categoricalvariable name=\"#{name}\" #{nickname}>\n"
                out << "<levels count=\"#{factors.size}\">\n"
                out << (1..factors.size).to_a.collect{|i|
                        carrier.conversions[name][factors[i-1]]=i
                        "<level value=\"#{i}\">#{v.labeling(factors[i-1])}</level>"
                }.join("\n")
                out << "</levels>\n</categoricalvariable>\n"
                out
        elsif v.data.find {|d| d.is_a? Float}
                "<realvariable name=\"#{name}\" #{nickname} />"
        else
                "<integervariable name=\"#{name}\" #{nickname} />"
        end
end
write(dataset,filename,opt={}) click to toggle source
# File lib/statsample/converters.rb, line 283
def write(dataset,filename,opt={})
  File.open(filename,"w") {|fp|
    fp.write(self.out(dataset,opt))
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.