Class: PubliSci::Writers::CSV

Inherits:
Base
  • Object
show all
Defined in:
lib/publisci/writers/csv.rb

Instance Method Summary collapse

Methods inherited from Base

#codes, #dataSet, #dimensions, #handle_input, #measures, #observations, #repo_to_ruby, #turtle_to_ruby

Methods included from Analyzer

#check_integrity, #dirty?, #recommend_range, #recommend_range_strings

Methods included from RDFParser

#add_node, #bnode_value, #encode_value, #get_ary, #get_hashes, #is_complex?, #is_uri?, #load_string, #observation_hash, #sanitize, #sanitize_hash, #strip_prefixes, #strip_uri, #to_literal, #to_resource, #turtle_indent

Methods included from Query

#execute, #execute_from_file, #property_names, #property_values, #row_names, #vocabulary

Instance Method Details

#build_csv(data, components = nil) ⇒ Object


4
5
6
7
8
9
10
11
12
# File 'lib/publisci/writers/csv.rb', line 4

def build_csv(data,components=nil)
  unless components
    components = data.values.map(&:keys).uniq
  end
  str = components.join(',') + "\n"
  data.map {|d| str << Hash[d[1]].values.join(',') + "\n" }
  str[-1]=""
  str
end

#from_store(repo, dataSet = nil, variable_out = nil, verbose = false) ⇒ Object


25
26
27
28
# File 'lib/publisci/writers/csv.rb', line 25

def from_store(repo,dataSet=nil, variable_out=nil, verbose=false)
  data = observations(repo,dataSet,true)
  build_csv(data)
end

#from_turtle(turtle_file, verbose = false) ⇒ Object


14
15
16
17
18
19
20
21
22
23
# File 'lib/publisci/writers/csv.rb', line 14

def from_turtle(turtle_file, verbose=false)
  puts "loading #{turtle_file}" if verbose
  repo = RDF::Repository.load(turtle_file)
  puts "loaded #{repo.size} statements into temporary repo" if verbose

  dims = dimensions(repo)
  meas = measures(repo)
  data = observations(repo)
  build_csv(data, (dims | meas))
end