`

Redland RDF语言工具套件

阅读更多

一套用来处理RDF语言文档的工具。

 

原文地址:

Redland RDF Libraries

这个套件有以下几个部分:

  1. RDF工具API,用C编写而成
  2. RDF外接语言套件,这里主要支持Perl, PHP, Python, Ruby
  3. RDF解析工具
  4. RDF查询工具

目前我只是进行了合理的使用和配置,并简单跑了一下DEMO,不过好像有些问题。

我的平台 写道
Ubutnu 8.04.2
Ruby 1.8.6
 

下载安装:

redland-1.0.8.tar.gz

tar ... 
./configure
make
sudo make install
redland-bindings-1.0.8.1.tar.gz
 
tar ...
./configure --with-ruby
make
sudo make install

不过我直接运行例子是有问题的。

原文例子 写道
http://librdf.org/docs/ruby.html
Testing the Redland Ruby interface

目录结构:

../data/dc.rdf

../ruby/example.rb

#!/usr/bin/env ruby
#
# example.rb - Redland example Ruby program
#
# Copyright (C) 2002-2004 David Beckett - http://www.dajobe.org/
# Copyright (C) 2002-2004 University of Bristol - http://www.bristol.ac.uk/
# 
# This package is Free Software or Open Source available under the
# following licenses (these are alternatives):
#   1. GNU Lesser General Public License (LGPL)
#   2. GNU General Public License (GPL)
#   3. Mozilla Public License (MPL)
# 
# See LICENSE.html or LICENSE.txt at the top of this package for the
# full license terms.
# 
#
# USAGE: ruby example.rb file:../data/dc.rdf raptor
# 
#

require 'rdf/redland'

uri_string=ARGV[0]
parser_name=ARGV[1]

#storage=Redland::TripleStore.new("hashes", "test", "new='no',hash-type='bdb',dir='.'")
#源代码在这里被我注释掉了,调试时有问题,改成了下列代码
storage=Redland::MemoryStore.new("test", "new='yes',hash-type='bdb',dir='.'")
raise "Failed to create RDF storage" if !storage


model=Redland::Model.new(storage)
if !model then
  raise "Failed to create RDF model"
end

parser=Redland::Parser.new(parser_name, "", nil)
if !parser then
  raise "Failed to create RDF parser"
end

uri=Redland::Uri.new(uri_string)
stream=parser.parse_as_stream(uri, uri)

count=0
while !stream.end?()
  statement=stream.current()
  model.add_statement(statement)
  puts "found statement: #{statement}"
  count=count+1
  stream.next()
end

puts "Parsing added #{count} statements"


puts "Printing all statements"
stream=model.as_stream()
while !stream.end?()
  statement=stream.current()
  puts "Statement: #{statement}"
  stream.next()
end

q = Redland::Query.new(" PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?a ?c WHERE { ?a dc:title ?c } ")
puts "Querying for dc:titles:"
results=q.execute(model)
while !results.finished?()
  puts "{"
  for k in 0..results.bindings_count()-1
    puts "  #{k}= #{results.binding_value(k)}"
  end
  puts "}"
  results.next()
end

results=q.execute(model)
size=results.to_string(Redland::Uri.new("http://www.w3.org/2001/sw/DataAccess/json-sparql/")).length()
puts "Serialized query results to JSON as a string size #{size} bytes"

puts "Writing model to test-out.rdf as rdf/xml"
# Use any rdf/xml parser that is available
serializer=Redland::Serializer.new()
serializer.set_namespace("dc", Redland::Uri.new("http://purl.org/dc/elements/1.1/"))
serializer.set_namespace("rdf", Redland::Uri.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
serializer.to_file("test-out.rdf", model)

size=model.to_string(name="ntriples", base_uri=Redland::Uri.new("http://example.org/base#")).length()
puts "Serialized to ntriples as a string size #{size} bytes"

puts "Done"
 

其实刚刚开始运行是不行的。我做了以下处理:

将/usr/local/lib 中的关于 librdf,librasqal,libraptor相关的link文件,转移到/usr/lib中。由于在运行中需要调用这些主件,所以需要放在一个可以看到的位置。要不然会报错。

 

 

 

分享到:
评论
1 楼 qianjigui 2009-05-24  
引用
On 09/28/06/09/06 11:46 +0200, Andre Meyer wrote:
>The general discussion is not Redland-specific, indeed. Your point wrt. OWL is
>interesting and that is what I am after - an ontology that describes my domain
>concepts (not the entire Semantic Web) and which allows me to use (interprete,
>infer, etc.) information using the knowledge that is specified by one or more
>ontologies.
>
>However, Redland does not support OWL, so I was wondering whether RDFS might
>help. Obviously, it does not. I also forgot to mention that I am looking for
>RDF/RDFS/OWL tools in Python ;-) If you know of anything useful beyond what has
>been mentioned so far, please let me know.
Sorry, I'm again not very useful ;-)

But your point that Redland does not support OWL but that it does support
RDFS, is not exactly true. Redland is only an RDF store.  Both OWL and RDFS
are RDF, but they are RDF vocabularies with a certain semantics.  This
semantics is not considered by Redland, neither for OWL nor for RDFS.

So Redland "supports" OWL in the sense that you can perfectly store and
retrieve OWL statements in it (because they are RDF statements), but it
doesn't interpret these statements in the special way that the OWL
semantics spefication mandates.

For what you want, you should be looking into OWL reasoners, which I have
no experience whatsoever with.  Or you could implement your own validation,
by querying the Redland RDF store and figuring out if the data conforms to
your validation rules.

hth,

-eyal

唉,RDF果然还是简单了,Redland不能很好的支持owl、RDFS。虽然在理论上可以转化,可惜简单的转化,Protege不认识。

相关推荐

Global site tag (gtag.js) - Google Analytics