currmap-sesame 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/lib/sesame.rb +42 -33
- data/spec/sesame_spec.rb +11 -7
- metadata +15 -3
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ begin
|
|
12
12
|
gem.authors = ["James N. V. Cash"]
|
13
13
|
gem.add_dependency 'nokogiri', ">= 0"
|
14
14
|
gem.add_development_dependency 'rspec', '>= 0'
|
15
|
+
gem.add_development_dependency 'parseconfig', '>= 0'
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
17
18
|
rescue LoadError
|
@@ -30,6 +31,8 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
30
31
|
spec.rcov = true
|
31
32
|
end
|
32
33
|
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
33
36
|
task :default => :spec
|
34
37
|
|
35
38
|
require 'rake/rdoctask'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/sesame.rb
CHANGED
@@ -8,60 +8,69 @@ module Sesame
|
|
8
8
|
class Server
|
9
9
|
attr_reader :uri, :repo
|
10
10
|
|
11
|
-
def initialize(host, port, sesamedir, repo, user, pass, options=
|
11
|
+
def initialize(host, port, sesamedir, repo, user, pass, options={})
|
12
12
|
@host = host
|
13
13
|
@port = port
|
14
14
|
@sesamedir = sesamedir
|
15
15
|
@repo = repo
|
16
16
|
@user = user
|
17
17
|
@pass = pass
|
18
|
-
@
|
18
|
+
@opt = Hash.new(false).merge options
|
19
19
|
@uri =
|
20
20
|
URI.parse("http://#{@host}:#{@port}/#{@sesamedir}/repositories")
|
21
21
|
end
|
22
|
-
|
23
|
-
def
|
24
|
-
|
25
|
-
query_params = params.collect { |k,v| "#{k}=#{URI.escape(v.to_s)}" }.
|
26
|
-
reverse.join '&'
|
27
|
-
req = Net::HTTP::Get.new("#{@uri.path}/#{@repo}?#{query_params}",
|
28
|
-
{'Accept' => 'application/sparql-results+xml' })
|
22
|
+
|
23
|
+
def process_query_xml(uri, &block)
|
24
|
+
req = Net::HTTP::Get.new(@uri.path + uri, { 'Accept' => 'application/sparql-results+xml'})
|
29
25
|
req.basic_auth @user, @pass
|
30
26
|
xml = Nokogiri::XML.parse(request(req).body)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
if !@opt[:return_xml]
|
28
|
+
res = yield xml
|
29
|
+
return res
|
30
|
+
else
|
31
|
+
return xml
|
35
32
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
def select(query_str, query_lang="sparql")
|
36
|
+
params = { "query" => query_str, "queryLn" => query_lang }
|
37
|
+
query_params =
|
38
|
+
params.collect { |k,v| "#{k}=#{URI.escape(v.to_s)}" }.reverse.join '&'
|
39
|
+
|
40
|
+
process_query_xml "/#{@repo}?#{query_params}" do |xml|
|
41
|
+
res = Hash.new
|
42
|
+
# Get variables from query
|
43
|
+
xml.xpath('//xmlns:head/xmlns:variable').each do |var|
|
44
|
+
res[var['name']] = Array.new
|
45
|
+
end
|
46
|
+
# Populate result hash by variable
|
47
|
+
xml.xpath('//xmlns:result/xmlns:binding').each do |binding|
|
48
|
+
res[binding['name']] << (binding / 'uri')[0].content
|
49
|
+
end
|
50
|
+
res # res should be the result of the block
|
39
51
|
end
|
40
|
-
return res
|
41
52
|
end
|
42
53
|
|
43
54
|
def list_repos
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
res
|
55
|
+
process_query_xml "" do |xml|
|
56
|
+
res = Array.new
|
57
|
+
xml.xpath('//xmlns:binding[@name="id"]/xmlns:literal').each do |repo|
|
58
|
+
res << repo.content
|
59
|
+
end
|
60
|
+
res # res should be the result of the block
|
50
61
|
end
|
51
|
-
return res
|
52
62
|
end
|
53
63
|
|
54
64
|
def list_namespaces repo
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
res
|
65
|
+
process_query_xml "/#{repo}/namespaces" do |xml|
|
66
|
+
res = Hash.new
|
67
|
+
xml.xpath('//xmlns:result').each do |result|
|
68
|
+
prefix = result.xpath('.//xmlns:binding[@name="prefix"]/xmlns:literal')[0].content
|
69
|
+
namespc = result.xpath('.//xmlns:binding[@name="namespace"]/xmlns:literal')[0].content
|
70
|
+
res[prefix] = namespc
|
71
|
+
end
|
72
|
+
res # res should be the result of the block
|
63
73
|
end
|
64
|
-
return res
|
65
74
|
end
|
66
75
|
|
67
76
|
def request(req)
|
data/spec/sesame_spec.rb
CHANGED
@@ -5,13 +5,17 @@ require 'parseconfig'
|
|
5
5
|
describe Sesame::Server do
|
6
6
|
|
7
7
|
before :all do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
begin
|
9
|
+
config = ParseConfig.new "#{File.dirname(__FILE__)}/tests-config"
|
10
|
+
@host = config.get_value('host')
|
11
|
+
@port = config.get_value('port').to_i
|
12
|
+
@sesame_dir = config.get_value('sesame_dir')
|
13
|
+
@repo = config.get_value('repo')
|
14
|
+
@user = config.get_value('username')
|
15
|
+
@pass = config.get_value('password')
|
16
|
+
rescue Errno::EACCES
|
17
|
+
puts "Unable to open #{File.dirname(__FILE__)}/tests-config"
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
before :each do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- James N. V. Cash
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,18 @@ dependencies:
|
|
41
41
|
version: "0"
|
42
42
|
type: :development
|
43
43
|
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: parseconfig
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
44
56
|
description: Establish an object-database mapping to an OpenRDF Sesame Triple Store database
|
45
57
|
email: james.cash@occasionallycogent.com
|
46
58
|
executables: []
|