| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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 |