Sha256: c3e2b0e54bcc011167877ed5ca4d0824d78627008c10ee0b37d546947defd09c

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

# require_relative '../../lib/r2rdf/data_cube.rb'
# require_relative '../../lib/r2rdf/generators/csv.rb'
require_relative '../../lib/bio-publisci.rb'

# require 'rdf/turtle'
require 'tempfile'

describe PubliSci::Readers::CSV do

	def create_graph(turtle_string)
		f = Tempfile.new('graph')
		f.write(turtle_string)
		f.close
		graph = RDF::Graph.load(f.path, :format => :ttl)
		f.unlink
		graph
	end

	before(:each) do
		@generator = PubliSci::Readers::CSV.new
	end

	context 'with reference CSV' do
		it "should generate correct output for reference file" do
			turtle_string = @generator.generate_n3(File.dirname(__FILE__) + '/../csv/bacon.csv','bacon',{dimensions:["producer","pricerange"], label_column:0})
			ref = IO.read(File.dirname(__FILE__) + '/../turtle/bacon')
			turtle_string.should == ref
		end
	end

	it "selects first column as a coded dimension and creates measures from the rest by default" do
		turtle_string = @generator.generate_n3(File.dirname(__FILE__) + '/../csv/bacon.csv','bacon')
		graph = create_graph(turtle_string)
		qb = RDF::Vocabulary.new("http://purl.org/linked-data/cube#")

		dims = RDF::Query.execute(graph){ pattern [:dataset, qb.dimension, :dimension] }
		dims.size.should == 1
		dims.first[:dimension].to_s.should == "http://onto.strinz.me/properties/producer"

		measures = RDF::Query.execute(graph){ pattern [:dataset, qb.measure, :measure] }
		measures.map{|s| s[:measure].to_s.split('/').last}.should == ["pricerange", "chunkiness", "deliciousness"]
	end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
publisci-0.1.2 spec/generators/csv_spec.rb
bio-publisci-0.1.0 spec/generators/csv_spec.rb