3
3
# example.rb - Redland example Ruby program
5
# $Id: example.rb,v 1.9 2004/05/30 00:46:43 cmdjb Exp $
5
# $Id: example.rb,v 1.11 2004/11/04 15:55:01 cmdjb Exp $
7
# Copyright (C) 2002 David Beckett - http://purl.org/net/dajobe/
7
# Copyright (C) 2002-2004 David Beckett - http://purl.org/net/dajobe/
8
8
# Institute for Learning and Research Technology - http://www.ilrt.org/
9
9
# University of Bristol - http://www.bristol.ac.uk/
28
28
parser_name=ARGV[1]
31
world=Redland::librdf_new_world
32
Redland::librdf_world_open world
34
storage=Redland::librdf_new_storage world, "hashes", "test", "new='yes',hash-type='bdb',dir='.'"
30
storage=Redland::TripleStore.new("hashes", "test", "new='yes',hash-type='bdb',dir='.'")
35
31
raise "Failed to create RDF storage" if !storage
38
model=Redland::librdf_new_model world, storage, ""
34
model=Redland::Model.new(storage)
40
Redland::librdf_free_storage storage
41
36
raise "Failed to create RDF model"
44
parser=Redland::librdf_new_parser world, parser_name, "", nil
39
parser=Redland::Parser.new(parser_name, "", nil)
46
Redland::librdf_free_model model
47
Redland::librdf_free_storage storage
48
41
raise "Failed to create RDF parser"
51
uri=Redland::librdf_new_uri world, uri_string
53
stream=Redland::librdf_parser_parse_as_stream parser, uri, uri
44
uri=Redland::Uri.new(uri_string)
45
stream=parser.parse_as_stream(uri, uri)
56
while Redland::librdf_stream_end(stream) == 0
57
statement=Redland::librdf_stream_get_object stream
58
Redland::librdf_model_add_statement model, statement
59
puts "found statement: #{Redland::librdf_statement_to_string statement}"
49
statement=stream.current()
50
model.add_statement(statement)
51
puts "found statement: #{statement}"
61
Redland::librdf_stream_next stream
64
Redland::librdf_free_stream stream
66
56
puts "Parsing added #{count} statements"
68
Redland::librdf_free_parser parser
71
59
puts "Printing all statements"
72
stream=Redland::librdf_model_as_stream model
73
while Redland::librdf_stream_end(stream) == 0
74
statement=Redland::librdf_stream_get_object stream
75
puts "Statement: #{Redland::librdf_statement_to_string statement}"
76
Redland::librdf_stream_next stream
60
stream=model.as_stream()
62
statement=stream.current()
63
puts "Statement: #{statement}"
79
Redland::librdf_free_stream stream
82
Redland::librdf_free_model model
83
Redland::librdf_free_storage storage
85
Redland::librdf_free_world world