owlim-ruby 0.9.9 → 0.9.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +24 -1
- data/bin/owlim +8 -1
- data/gemspec.rb +1 -1
- data/lib/owlim.rb +55 -17
- metadata +4 -7
data/README.rdoc
CHANGED
@@ -75,6 +75,10 @@ If not specified, format will be guessed from the file name suffix for import.
|
|
75
75
|
|
76
76
|
=== Query commands
|
77
77
|
|
78
|
+
Show list of prefixes which are automatically added to SPARQL.
|
79
|
+
|
80
|
+
owlim prefix
|
81
|
+
|
78
82
|
SPARQL query against a repository.
|
79
83
|
|
80
84
|
owlim query repository "SPARQL" [format]
|
@@ -106,6 +110,8 @@ Result will be printed in a tabular text format by default.
|
|
106
110
|
owlim clear hoge
|
107
111
|
owlim drop hoge
|
108
112
|
|
113
|
+
owlim prefix
|
114
|
+
|
109
115
|
owlim query hoge 'select * where { ?s ?p ?o . } limit 1000'
|
110
116
|
owlim query hoge 'select * where { ?s ?p ?o . } limit 1000' json
|
111
117
|
owlim query hoge 'select * where { ?s ?p ?o . } limit 1000' xml
|
@@ -128,7 +134,7 @@ Create a server object. Argument is a URI of the OWLIM endpoint.
|
|
128
134
|
|
129
135
|
Show the endpoint URI.
|
130
136
|
|
131
|
-
puts owlim.
|
137
|
+
puts owlim.host
|
132
138
|
|
133
139
|
Show all repositories.
|
134
140
|
|
@@ -182,6 +188,23 @@ finds all relevant triples sharing the same subject.
|
|
182
188
|
|
183
189
|
owlim.find(repository, keyword) {|x| print x}
|
184
190
|
|
191
|
+
Show formatted SPARQL prefixes.
|
192
|
+
|
193
|
+
puts owlim.prefix
|
194
|
+
|
195
|
+
Access current SPARQL prefixes.
|
196
|
+
|
197
|
+
owlim.prefix_hash.each {|pfx, uri| puts "PREFIX #{pfx}: <#{uri}>"}
|
198
|
+
|
199
|
+
Add a SPARQL prefix.
|
200
|
+
|
201
|
+
owlim.prefix_hash["vcard"] = "http://www.w3.org/2006/vcard/ns#"
|
202
|
+
|
203
|
+
Delete a SPARQL prefix.
|
204
|
+
|
205
|
+
owlim.prefix_hash.delete("skos")
|
206
|
+
|
207
|
+
|
185
208
|
== Authors
|
186
209
|
|
187
210
|
* Toshiaki Katayama (DBCLS; ktym@dbcls.jp)
|
data/bin/owlim
CHANGED
@@ -57,6 +57,9 @@ Query commands:
|
|
57
57
|
* "json" for "application/sparql-result+json"
|
58
58
|
* "xml" for "application/sparql-result+xml".
|
59
59
|
|
60
|
+
# Show list of prefixes which are automatically added to SPARQL
|
61
|
+
> owlim prefix
|
62
|
+
|
60
63
|
# SPARQL query against a repository
|
61
64
|
> owlim query repository "SPARQL" [format]
|
62
65
|
|
@@ -95,6 +98,8 @@ Examples:
|
|
95
98
|
> owlim clear hoge
|
96
99
|
> owlim drop hoge
|
97
100
|
|
101
|
+
> owlim prefix
|
102
|
+
|
98
103
|
> owlim query hoge 'select * where { ?s ?p ?o . } limit 1000'
|
99
104
|
> owlim query hoge 'select * where { ?s ?p ?o . } limit 1000' json
|
100
105
|
> owlim query hoge 'select * where { ?s ?p ?o . } limit 1000' xml
|
@@ -115,9 +120,11 @@ arguments = ARGV
|
|
115
120
|
|
116
121
|
case command
|
117
122
|
when "host"
|
118
|
-
puts serv.
|
123
|
+
puts serv.host
|
119
124
|
when "list"
|
120
125
|
puts serv.list
|
126
|
+
when "prefix"
|
127
|
+
puts serv.prefix
|
121
128
|
when "size"
|
122
129
|
if repository
|
123
130
|
puts serv.size(repository)
|
data/gemspec.rb
CHANGED
data/lib/owlim.rb
CHANGED
@@ -4,27 +4,28 @@ require "uuid"
|
|
4
4
|
require "erb"
|
5
5
|
require "net/http"
|
6
6
|
require "cgi"
|
7
|
-
#require "yaml"
|
8
7
|
require "json"
|
9
8
|
require "rexml/document"
|
10
9
|
|
11
10
|
class OWLIM
|
12
11
|
|
12
|
+
attr :prefix_hash
|
13
|
+
|
13
14
|
def initialize(url)
|
14
|
-
|
15
|
+
@endpoint = url
|
16
|
+
uri = URI.parse(url)
|
17
|
+
|
18
|
+
@host = uri.host
|
19
|
+
@port = uri.port
|
20
|
+
@path = uri.path
|
21
|
+
|
22
|
+
@prefix_hash = prefix_default
|
23
|
+
|
15
24
|
Net::HTTP.version_1_2
|
16
25
|
end
|
17
26
|
|
18
|
-
def
|
19
|
-
|
20
|
-
@server = url
|
21
|
-
@uri = URI.parse(url)
|
22
|
-
@host = @uri.host
|
23
|
-
@port = @uri.port
|
24
|
-
@path = @uri.path
|
25
|
-
else
|
26
|
-
return @server
|
27
|
-
end
|
27
|
+
def host
|
28
|
+
return @endpoint
|
28
29
|
end
|
29
30
|
|
30
31
|
def list
|
@@ -36,7 +37,6 @@ class OWLIM
|
|
36
37
|
result = response.body
|
37
38
|
end
|
38
39
|
|
39
|
-
#hash = YAML.load(result)
|
40
40
|
hash = JSON.parse(result)
|
41
41
|
|
42
42
|
hash["results"]["bindings"].map {|b| b["id"]["value"]}
|
@@ -124,6 +124,8 @@ class OWLIM
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def drop(repository)
|
127
|
+
clear(repository)
|
128
|
+
|
127
129
|
rdftransaction = drop_repository(repository)
|
128
130
|
|
129
131
|
Net::HTTP.start(@host, @port) do |http|
|
@@ -133,6 +135,13 @@ class OWLIM
|
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
138
|
+
def prefix
|
139
|
+
ary = @prefix_hash.map { |key, value|
|
140
|
+
"PREFIX #{key}: <#{value}>"
|
141
|
+
}
|
142
|
+
return ary.join("\n")
|
143
|
+
end
|
144
|
+
|
136
145
|
def query(repository, sparql, opts={}, &block)
|
137
146
|
result = ""
|
138
147
|
|
@@ -144,18 +153,21 @@ class OWLIM
|
|
144
153
|
else # tabular text
|
145
154
|
format = "application/sparql-results+json"
|
146
155
|
end
|
156
|
+
|
157
|
+
sparql_str = CGI.escape(prefix + sparql)
|
147
158
|
|
148
159
|
Net::HTTP.start(@host, @port) do |http|
|
149
|
-
path = "#{@path}/repositories/#{repository}?query=#{
|
160
|
+
path = "#{@path}/repositories/#{repository}?query=#{sparql_str}"
|
150
161
|
http.get(path, {"Accept" => "#{format}"}) { |body|
|
151
|
-
if block and opts[:format]
|
162
|
+
if block and opts[:format] # xml or json
|
152
163
|
yield body
|
153
|
-
else
|
164
|
+
else # tabular text
|
154
165
|
result += body
|
155
166
|
end
|
156
167
|
}
|
157
168
|
end
|
158
169
|
|
170
|
+
# generate tabular text (not reached if opts[:format] is defined)
|
159
171
|
if table = format_json(result)
|
160
172
|
if block
|
161
173
|
yield table
|
@@ -172,6 +184,33 @@ class OWLIM
|
|
172
184
|
|
173
185
|
private
|
174
186
|
|
187
|
+
def prefix_default
|
188
|
+
@prefix_hash = {
|
189
|
+
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
190
|
+
"rdfs" => "http://www.w3.org/2000/01/rdf-schema#",
|
191
|
+
"owl" => "http://www.w3.org/2002/07/owl#",
|
192
|
+
"xsd" => "http://www.w3.org/2001/XMLSchema#",
|
193
|
+
"pext" => "http://proton.semanticweb.org/protonext#",
|
194
|
+
"psys" => "http://proton.semanticweb.org/protonsys#",
|
195
|
+
"xhtml" => "http://www.w3.org/1999/xhtml#",
|
196
|
+
"dc" => "http://purl.org/dc/elements/1.1/",
|
197
|
+
"dcterms" => "http://purl.org/dc/terms/",
|
198
|
+
"foaf" => "http://xmlns.com/foaf/0.1/",
|
199
|
+
"skos" => "http://www.w3.org/2004/02/skos/core#",
|
200
|
+
"void" => "http://rdfs.org/ns/void#",
|
201
|
+
"dbpedia" => "http://dbpedia.org/resource/",
|
202
|
+
"dbp" => "http://dbpedia.org/property/",
|
203
|
+
"dbo" => "http://dbpedia.org/ontology/",
|
204
|
+
"yago" => "http://dbpedia.org/class/yago/",
|
205
|
+
"fb" => "http://rdf.freebase.com/ns/",
|
206
|
+
"sioc" => "http://rdfs.org/sioc/ns#",
|
207
|
+
"geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
|
208
|
+
"geonames" => "http://www.geonames.org/ontology#",
|
209
|
+
"bibo" => "http://purl.org/ontology/bibo/",
|
210
|
+
"prism" => "http://prismstandard.org/namespaces/basic/2.1/",
|
211
|
+
}
|
212
|
+
end
|
213
|
+
|
175
214
|
def content_type(format)
|
176
215
|
case format
|
177
216
|
when "ttl", "turtle"
|
@@ -196,7 +235,6 @@ class OWLIM
|
|
196
235
|
|
197
236
|
def format_json(json)
|
198
237
|
begin
|
199
|
-
#hash = YAML.load(json)
|
200
238
|
hash = JSON.parse(json)
|
201
239
|
head = hash["head"]["vars"]
|
202
240
|
body = hash["results"]["bindings"]
|
metadata
CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 9
|
8
8
|
- 9
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.9.9.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Toshiaki Katayama
|
@@ -15,14 +16,13 @@ autorequire: owlim
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2012-
|
19
|
+
date: 2012-06-01 00:00:00 +09:00
|
19
20
|
default_executable: owlim
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: uuid
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
@@ -35,7 +35,6 @@ dependencies:
|
|
35
35
|
name: json
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
38
|
requirements:
|
40
39
|
- - ">="
|
41
40
|
- !ruby/object:Gem::Version
|
@@ -69,7 +68,6 @@ rdoc_options: []
|
|
69
68
|
require_paths:
|
70
69
|
- lib
|
71
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
71
|
requirements:
|
74
72
|
- - ">="
|
75
73
|
- !ruby/object:Gem::Version
|
@@ -77,7 +75,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
75
|
- 0
|
78
76
|
version: "0"
|
79
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
78
|
requirements:
|
82
79
|
- - ">="
|
83
80
|
- !ruby/object:Gem::Version
|
@@ -87,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
84
|
requirements: []
|
88
85
|
|
89
86
|
rubyforge_project: owlim-ruby
|
90
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.6
|
91
88
|
signing_key:
|
92
89
|
specification_version: 3
|
93
90
|
summary: OWLIM client library for Ruby
|