Debian Codegraph @

ruby/test.rb

raw symbols SCIP
1 #!/usr/bin/env ruby
2 #
3 # test.rb - Redland low-level test Ruby program
4 #
5 # Copyright (C) 2002-2004 David Beckett - http://www.dajobe.org/
6 # Copyright (C) 2002-2004 University of Bristol - http://www.bristol.ac.uk/
7 #
8 # This package is Free Software and part of Redland http://librdf.org/
9 #
10 # It is licensed under the following three licenses as alternatives:
11 # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 # 2. GNU General Public License (GPL) V2 or any newer version
13 # 3. Apache License, V2.0 or any newer version
14 #
15 # You may not use this file except in compliance with at least one of
16 # the above three licenses.
17 #
18 # See LICENSE.html or LICENSE.txt at the top of this package for the
19 # full license terms.
20 #
21 #
22 # USAGE: ruby example.rb file:../data/dc.rdf raptor
23 #
24 #
25
26 require 'redland'
27
28 uri_string=ARGV[0]
29 parser_name=ARGV[1]
30
31
32 world=Redland::librdf_new_world
33 Redland::librdf_world_open world
34
35 storage=Redland::librdf_new_storage world, "hashes", "test", "new='yes',hash-type='bdb',dir='.'"
36 raise "Failed to create RDF storage" if !storage
37
38
39 model=Redland::librdf_new_model world, storage, ""
40 if !model then
41 Redland::librdf_free_storage storage
42 raise "Failed to create RDF model"
43 end
44
45 parser=Redland::librdf_new_parser world, parser_name, "", nil
46 if !parser then
47 Redland::librdf_free_model model
48 Redland::librdf_free_storage storage
49 raise "Failed to create RDF parser"
50 end
51
52 uri=Redland::librdf_new_uri world, uri_string
53
54 stream=Redland::librdf_parser_parse_as_stream parser, uri, uri
55
56 count=0
57 while Redland::librdf_stream_end(stream) == 0
58 statement=Redland::librdf_stream_get_object stream
59 Redland::librdf_model_add_statement model, statement
60 puts "found statement: #{Redland::librdf_statement_to_string statement}"
61 count=count+1
62 Redland::librdf_stream_next stream
63 end
64
65 Redland::librdf_free_stream stream
66
67 puts "Parsing added #{count} statements"
68
69 Redland::librdf_free_parser parser
70
71
72 puts "Printing all statements"
73 stream=Redland::librdf_model_as_stream model
74 while Redland::librdf_stream_end(stream) == 0
75 statement=Redland::librdf_stream_get_object stream
76 puts "Statement: #{Redland::librdf_statement_to_string statement}"
77 Redland::librdf_stream_next stream
78 end
79
80 Redland::librdf_free_stream stream
81
82
83 Redland::librdf_free_model model
84 Redland::librdf_free_storage storage
85
86 Redland::librdf_free_world world