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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值