~ubuntu-branches/ubuntu/breezy/redland-bindings/breezy

« back to all changes in this revision

Viewing changes to ruby/example.rb

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2005-06-21 12:56:49 UTC
  • mfrom: (1.1.1 upstream) (0.1.2 sarge)
  • Revision ID: james.westby@ubuntu.com-20050621125649-1uwxez1hdyzw6vzd
Tags: 1.0.2.1-1ubuntu1
* Resynchronise with Debian.

* Fix FTBFS: Add python2.4-dev Build-Dep.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# example.rb - Redland example Ruby program
4
4
#
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 $
6
6
#
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/
10
10
22
22
23
23
#
24
24
 
25
 
require 'redland'
 
25
require 'rdf/redland'
26
26
 
27
27
uri_string=ARGV[0]
28
28
parser_name=ARGV[1]
29
29
 
30
 
 
31
 
world=Redland::librdf_new_world
32
 
Redland::librdf_world_open world
33
 
 
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
36
32
 
37
33
 
38
 
model=Redland::librdf_new_model world, storage, ""
 
34
model=Redland::Model.new(storage)
39
35
if !model then
40
 
  Redland::librdf_free_storage storage
41
36
  raise "Failed to create RDF model"
42
37
end
43
38
 
44
 
parser=Redland::librdf_new_parser world, parser_name, "", nil
 
39
parser=Redland::Parser.new(parser_name, "", nil)
45
40
if !parser then
46
 
  Redland::librdf_free_model model
47
 
  Redland::librdf_free_storage storage
48
41
  raise "Failed to create RDF parser"
49
42
end
50
43
 
51
 
uri=Redland::librdf_new_uri world, uri_string
52
 
 
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)
54
46
 
55
47
count=0
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}"
 
48
while !stream.end?()
 
49
  statement=stream.current()
 
50
  model.add_statement(statement)
 
51
  puts "found statement: #{statement}"
60
52
  count=count+1
61
 
  Redland::librdf_stream_next stream
 
53
  stream.next()
62
54
end
63
55
 
64
 
Redland::librdf_free_stream stream
65
 
 
66
56
puts "Parsing added #{count} statements"
67
57
 
68
 
Redland::librdf_free_parser parser
69
 
 
70
58
 
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()
 
61
while !stream.end?()
 
62
  statement=stream.current()
 
63
  puts "Statement: #{statement}"
 
64
  stream.next()
77
65
end
78
 
 
79
 
Redland::librdf_free_stream stream
80
 
 
81
 
 
82
 
Redland::librdf_free_model model
83
 
Redland::librdf_free_storage storage
84
 
 
85
 
Redland::librdf_free_world world
86