Ruby Code Active RDF
Ruby Code require 'rdf/redland' require 'active_rdf'
class GoParser
attr_reader :uri_string, :parser_name, :storage attr_writer :uri_string, :parser_name, :storage
def initialize(uri_string, parser_name, storage) @uri_string = uri_string @parser_name = parser_name @storage = storage end
def parse() store=Redland::TripleStore.new("hashes", "go_rdf", "new='yes',hash-type='bdb',dir=@storage") raise "Failed to create RDF storage" if !storage
model=Redland::Model.new(@storage) if !model then raise "Failed to create RDF model" end
parser=Redland::Parser.new(@parser_name, "", nil) if !parser then raise "Failed to create RDF parser" end
uri=Redland::Uri.new(@uri_string) stream=parser.parse_as_stream(uri, uri)
count=0 while !stream.end?() statement=stream.current() model.add_statement(statement) puts "found statement: #{statement}" count=count+1 stream.next() end
puts "Parsing added #{count} statements"
puts "Printing all statements" stream=model.as_stream() while !stream.end?() statement=stream.current() puts "Statement: #{statement}" stream.next() end end
def load() @connection = NodeFactory.connection({ :adapter => :redland }) end
end