require 'uri'

# RubyRDF / RDF Parser. Based on code contributed from
# RDF4R RDF Parser, Copyright © 2002 Brandt Kurowski (brandt@kurowski.net)
# packaged as part of RubyRDF, see http://www.w3.org/2001/12/rubyrdf/intro.html
# All Rights Reserved. This work is distributed under the W3C® Software 
# License [1] in the hope that it will be useful, but WITHOUT ANY 
# WARRANTY; without even the implied warranty of MERCHANTABILITY or 
# FITNESS FOR A PARTICULAR PURPOSE. 
# [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231



module RDF4R

	module Driver

		class SimpleData

			attr_accessor :consumer

			def parse(uri, data)
				@consumer.start_model
				subject = @consumer.resource(uri)
				data.each do |key, values|
					predicate = @consumer.resource(key)
					values.each do |value|
						if value =~ /^<(.*)>$/	
							begin
								obj_uri = URI.parse($1)
								object = @consumer.resource(obj_uri)
							rescue
								object = @consumer.literal(value)
							end
						else
							object = @consumer.literal(value)
						end
						@consumer.statement(subject, predicate, object)
					end
				end
				@consumer.end_model
			end

			def SimpleData.process(uri, data, consumer)
				p = SimpleData.new
				p.consumer = consumer 
				p.parse(uri, data)
				return p.consumer.models
			end

		end

  end

end

