[redland-dev] two newbie questions
Steven Jenkins
steven.jenkins at ieee.org
Sat Sep 9 05:21:52 UTC 2006
I'm experimenting with RDF and Redland using the Ruby bindings. I've
got a simple OWL file (created with Protege) that I can parse with the
following script:
---------------- snip ----------------
#!/usr/bin/env ruby
require 'rdf/redland'
include Redland
MYNS =
Namespace.new("http://www.owl-ontologies.com/Ontology1157776442.owl#")
model = Model.new
parser = Parser.new
parser.parse_into_model(model, "file:#{ARGV.shift}")
subj = nil
pred = MYNS['publication_number']
obj = nil
model.find(subj, pred, obj).each do |s|
puts "statement: #{s}"
puts "subject: #{s.subject}"
puts "predicate: #{s.predicate}"
#puts "object: #{s.object}"
puts
end
---------------- snip ----------------
When I run it, I see the following output (modulo line folding):
---------------- snip ----------------
statement:
{[http://www.owl-ontologies.com/Ontology1157776442.owl#document_003],
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number],
"D003^^<http://www.w3.org/2001/XMLSchema#string>"}
subject: [http://www.owl-ontologies.com/Ontology1157776442.owl#document_003]
predicate:
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number]
statement:
{[http://www.owl-ontologies.com/Ontology1157776442.owl#document_001],
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number],
"D001^^<http://www.w3.org/2001/XMLSchema#string>"}
subject: [http://www.owl-ontologies.com/Ontology1157776442.owl#document_001]
predicate:
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number]
statement:
{[http://www.owl-ontologies.com/Ontology1157776442.owl#document_002],
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number],
"D002^^<http://www.w3.org/2001/XMLSchema#string>"}
subject: [http://www.owl-ontologies.com/Ontology1157776442.owl#document_002]
predicate:
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number]
---------------- snip ----------------
That's exactly what I expect. I'm having two problems, however. The
first is that I can't find an expression to assign to obj so that
find() finds only a single statement. I've tried various ways of
constructing a typed literal, but they all result in no match. I
encountered the second problem trying to diagnose the first. If I
uncomment the line to print s.object, Ruby raises an exception as follows:
---------------- snip ----------------
statement:
{[http://www.owl-ontologies.com/Ontology1157776442.owl#document_003],
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number],
"D003^^<http://www.w3.org/2001/XMLSchema#string>"}
subject: [http://www.owl-ontologies.com/Ontology1157776442.owl#document_003]
predicate:
[http://www.owl-ontologies.com/Ontology1157776442.owl#publication_number]
/usr/lib/ruby/1.8/rdf/redland/node.rb:242:in `from_node': undefined
method `Uri' for Redland::Literal:Class (NoMethodError)
from /usr/lib/ruby/1.8/rdf/redland/statement.rb:96:in `object'
from ./rt:22
from ./rt:18
---------------- snip ----------------
Platform is Gentoo Linux, redland 1.0.4, redland 1.0.4.1, raptor
1.4.12, Ruby 1.8.4. Any suggestions welcome.
Steve
More information about the redland-dev
mailing list