pho 0.6.2 → 0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +12 -0
- data/Rakefile +1 -1
- data/bin/talis_store +98 -24
- data/doc/rdoc/classes/Pho.html +15 -0
- data/doc/rdoc/classes/Pho/CommandLine.html +353 -91
- data/doc/rdoc/classes/Pho/DatatypeProperty.html +12 -12
- data/doc/rdoc/classes/Pho/Enrichment/StoreEnricher.html +29 -29
- data/doc/rdoc/classes/Pho/Etags.html +36 -36
- data/doc/rdoc/classes/Pho/Facet/Results.html +19 -19
- data/doc/rdoc/classes/Pho/Facet/Term.html +6 -6
- data/doc/rdoc/classes/Pho/FieldPredicateMap.html +105 -106
- data/doc/rdoc/classes/Pho/FieldWeighting.html +12 -12
- data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +31 -8
- data/doc/rdoc/classes/Pho/Job.html +64 -64
- data/doc/rdoc/classes/Pho/Jobs.html +60 -60
- data/doc/rdoc/classes/Pho/QueryProfile.html +60 -60
- data/doc/rdoc/classes/Pho/RDF/Parser.html +28 -26
- data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +36 -36
- data/doc/rdoc/classes/Pho/ResourceHash/SetAlgebra.html +12 -12
- data/doc/rdoc/classes/Pho/Snapshot.html +35 -35
- data/doc/rdoc/classes/Pho/Status.html +26 -26
- data/doc/rdoc/classes/Pho/Store.html +289 -245
- data/doc/rdoc/classes/Pho/StoreSparqlClient.html +14 -14
- data/doc/rdoc/classes/String.html +1 -1
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +35 -1
- data/doc/rdoc/files/lib/pho/command_line_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/converter_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/field_predicate_map_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/rdf_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/store_rb.html +1 -1
- data/doc/rdoc/files/lib/pho_rb.html +2 -1
- data/doc/rdoc/fr_class_index.html +3 -0
- data/doc/rdoc/fr_file_index.html +1 -0
- data/doc/rdoc/fr_method_index.html +153 -141
- data/lib/pho.rb +3 -0
- data/lib/pho/command_line.rb +139 -14
- data/lib/pho/field_predicate_map.rb +1 -2
- data/lib/pho/oai.rb +58 -0
- data/lib/pho/rdf.rb +2 -0
- data/lib/pho/rdf_collection.rb +16 -4
- data/lib/pho/store.rb +23 -5
- data/tests/tc_command_line.rb +229 -0
- data/tests/tc_field_predicate_map.rb +5 -1
- data/tests/tc_metabox.rb +29 -1
- data/tests/tc_oai.rb +31 -0
- data/tests/tc_rdf_collection.rb +80 -15
- data/tests/ts_pho.rb +3 -1
- metadata +5 -2
data/lib/pho.rb
CHANGED
@@ -24,6 +24,7 @@ require 'pho/command_line'
|
|
24
24
|
#Following depend on redland
|
25
25
|
require 'pho/converter'
|
26
26
|
require 'pho/rdf'
|
27
|
+
require 'pho/oai'
|
27
28
|
|
28
29
|
if RUBY_VERSION < "1.8.7"
|
29
30
|
class String
|
@@ -39,6 +40,8 @@ module Pho
|
|
39
40
|
ACCEPT_JSON = { "Accept" => "application/json" }.freeze
|
40
41
|
|
41
42
|
RDF_XML = {"Content-Type"=>"application/rdf+xml"}.freeze
|
43
|
+
TURTLE = {"Content-Type"=>"text/turtle"}.freeze
|
44
|
+
NTRIPLES = {"Content-Type"=>"text/plain"}.freeze
|
42
45
|
|
43
46
|
class Namespaces
|
44
47
|
|
data/lib/pho/command_line.rb
CHANGED
@@ -3,20 +3,56 @@ module Pho
|
|
3
3
|
#Class that implements the command-line behaviour
|
4
4
|
class CommandLine
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(opts, env, store=nil)
|
7
|
+
@opts = opts
|
8
|
+
@env = env
|
9
|
+
|
10
|
+
if username() == nil
|
11
|
+
raise "no <username>"
|
12
|
+
end
|
13
|
+
if password() == nil
|
14
|
+
raise "no <password>"
|
15
|
+
end
|
16
|
+
if storename() == nil && store == nil
|
17
|
+
raise "no <store>"
|
18
|
+
end
|
19
|
+
|
20
|
+
@store = Pho::Store.new(storename(), username(), password()) if store == nil
|
21
|
+
@store = store if store != nil
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def username()
|
26
|
+
return @opts["username"] if @opts["username"]
|
27
|
+
return @env["TALIS_USER"] if @env["TALIS_USER"]
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def password()
|
32
|
+
return @opts["password"] if @opts["password"]
|
33
|
+
return @env["TALIS_PASS"] if @env["TALIS_PASS"]
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def storename()
|
38
|
+
store = nil
|
39
|
+
store = @env["TALIS_STORE"] if @env["TALIS_STORE"]
|
40
|
+
store = @opts["store"] if @opts["store"]
|
41
|
+
if store != nil && !store.start_with?("http")
|
42
|
+
store = "http://api.talis.com/stores/#{store}"
|
43
|
+
end
|
44
|
+
return store
|
9
45
|
end
|
10
46
|
|
11
47
|
def status()
|
12
48
|
status = Pho::Status.read_from_store(@store)
|
13
|
-
puts "Store
|
49
|
+
puts "Status of Store #{@store.storeuri}:\nReadable: #{status.readable?}\nWritable: #{status.writeable?}"
|
14
50
|
end
|
15
51
|
|
16
52
|
def backup()
|
17
|
-
puts "Submitting Snapshot Job"
|
53
|
+
puts "Submitting Snapshot Job to Store #{@store.storeuri}"
|
18
54
|
resp = Pho::Jobs.submit_snapshot(@store, "Reindex", Time.now)
|
19
|
-
puts "Monitoring Job"
|
55
|
+
puts "Monitoring Snapshot Job: #{resp.header["Location"].first}"
|
20
56
|
job = Pho::Jobs.wait_for_submitted(resp, @store) do |job, message, time|
|
21
57
|
puts "#{time} #{message}"
|
22
58
|
end
|
@@ -29,9 +65,9 @@ module Pho
|
|
29
65
|
end
|
30
66
|
|
31
67
|
def snapshot()
|
32
|
-
puts "Submitting Snapshot Job"
|
68
|
+
puts "Submitting Snapshot Job to Store #{@store.storeuri}"
|
33
69
|
resp = Pho::Jobs.submit_snapshot(@store, "Reindex", Time.now)
|
34
|
-
puts "Monitoring Job"
|
70
|
+
puts "Monitoring Snapshot Job #{resp.header["Location"].first}"
|
35
71
|
job = Pho::Jobs.wait_for_submitted(resp, @store) do |job, message, time|
|
36
72
|
puts "#{time} #{message}"
|
37
73
|
end
|
@@ -39,7 +75,7 @@ module Pho
|
|
39
75
|
end
|
40
76
|
|
41
77
|
def reindex()
|
42
|
-
puts "Submitting Reindex Job"
|
78
|
+
puts "Submitting Reindex Job to Store #{@store.storeuri}"
|
43
79
|
resp = Pho::Jobs.submit_reindex(@store, "Reindex", Time.now)
|
44
80
|
if resp.status == 201
|
45
81
|
puts "Monitoring Reindex Job: #{resp.header["Location"].first}"
|
@@ -51,9 +87,9 @@ module Pho
|
|
51
87
|
end
|
52
88
|
|
53
89
|
def reset()
|
54
|
-
puts "Resetting Store"
|
90
|
+
puts "Resetting Store #{@store.storeuri}"
|
55
91
|
resp = Pho::Jobs.submit_reset(@store, "Reset", Time.now)
|
56
|
-
puts "Monitoring Reset Job:"
|
92
|
+
puts "Monitoring Reset Job: #{resp.header["Location"].first}"
|
57
93
|
job = Pho::Jobs.wait_for_submitted(resp, @store) do |job, message, time|
|
58
94
|
puts "#{time} #{message}"
|
59
95
|
end
|
@@ -63,12 +99,13 @@ module Pho
|
|
63
99
|
def restore()
|
64
100
|
url = @opts["url"]
|
65
101
|
if url == nil
|
66
|
-
puts "
|
102
|
+
puts "Restoring #{@store.storeuri} from latest snapshot"
|
67
103
|
snapshot = Pho::Snapshot.read_from_store(@store)
|
68
104
|
url = snapshot.url
|
69
105
|
end
|
70
106
|
puts "Restoring from #{url}"
|
71
107
|
resp = Pho::Jobs.submit_restore(@store, url, "Reset", Time.now)
|
108
|
+
puts "Monitoring Restore Job: #{resp.header["Location"].first}"
|
72
109
|
job = Pho::Jobs.wait_for_submitted(resp, @store) do |job, message, time|
|
73
110
|
puts "#{time} #{message}"
|
74
111
|
end
|
@@ -105,7 +142,9 @@ module Pho
|
|
105
142
|
puts "Storing local file: #{@opts["file"]}"
|
106
143
|
f = File.new( @opts["file"] )
|
107
144
|
if File.extname( @opts["file"] ) == ".nt"
|
108
|
-
|
145
|
+
resp = @store.store_file( f, nil, "text/plain" )
|
146
|
+
elsif File.extname( @opts["file"] ) == ".ttl"
|
147
|
+
resp = @store.store_file( f, nil, "text/turtle" )
|
109
148
|
else
|
110
149
|
resp = @store.store_file( f )
|
111
150
|
end
|
@@ -133,7 +172,7 @@ module Pho
|
|
133
172
|
if @opts["file"]
|
134
173
|
f = File.new( @opts["file"] )
|
135
174
|
uri = File.basename( @opts["file"] )
|
136
|
-
uri = "#{opts["base"]}/#{uri}" if @opts["base"]
|
175
|
+
uri = "#{@opts["base"]}/#{uri}" if @opts["base"]
|
137
176
|
mime = MIME::Types.type_for( @opts["file"] )[0].to_s
|
138
177
|
puts "Uploading file: #{ @opts["file"] } to /items/#{ uri } as #{mime}"
|
139
178
|
resp = @store.upload_item( f , mime , uri )
|
@@ -160,7 +199,93 @@ module Pho
|
|
160
199
|
end
|
161
200
|
end
|
162
201
|
end
|
202
|
+
|
203
|
+
def fpmap(out=$stdout)
|
204
|
+
|
205
|
+
if @opts["raw"]
|
206
|
+
resp = @store.get_field_predicate_map(Pho::ACCEPT_RDF)
|
207
|
+
if resp.status != 200
|
208
|
+
out.puts "Unable to read Field Predicate Map from store. Response code was #{resp.status}"
|
209
|
+
else
|
210
|
+
out.puts resp.content
|
211
|
+
end
|
212
|
+
else
|
213
|
+
fpmap = Pho::FieldPredicateMap.read_from_store(@store)
|
214
|
+
mappings = fpmap.datatype_properties.sort { |x,y| x.name <=> y.name }
|
215
|
+
mappings.each do |mapping|
|
216
|
+
analyzer = mapping.analyzer
|
217
|
+
if analyzer != nil
|
218
|
+
Pho::Analyzers.constants.each do |c|
|
219
|
+
if analyzer == Pho::Analyzers.const_get(c)
|
220
|
+
analyzer = c
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
out.puts "#{mapping.name} -> #{mapping.property_uri}" if analyzer == nil
|
225
|
+
out.puts "#{mapping.name} -> #{mapping.property_uri} (#{mapping.analyzer})" if analyzer != nil
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
def queryprofile(out=$stdout)
|
233
|
+
|
234
|
+
if @opts["raw"]
|
235
|
+
resp = @store.get_query_profile(Pho::ACCEPT_RDF)
|
236
|
+
if resp.status != 200
|
237
|
+
out.puts "Unable to read Query Profile from store. Response code was #{resp.status}"
|
238
|
+
else
|
239
|
+
out.puts resp.content
|
240
|
+
end
|
241
|
+
else
|
242
|
+
queryprofile = Pho::QueryProfile.read_from_store(@store)
|
243
|
+
field_weights = queryprofile.field_weights()
|
244
|
+
field_weights = field_weights.sort { |x,y| x.name <=> y.name }
|
245
|
+
field_weights.each do |weighting|
|
246
|
+
out.puts "#{weighting.name} -> #{weighting.weight}"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
def add_mapping(out=$stdout)
|
253
|
+
fpmap = Pho::FieldPredicateMap.read_from_store(@store)
|
254
|
+
mapping = Pho::FieldPredicateMap.create_mapping(@store, @opts["predicate"], @opts["field"], @opts["analyzer"])
|
255
|
+
|
256
|
+
removed = fpmap.remove_by_name(@opts["field"])
|
257
|
+
if removed != nil
|
258
|
+
out.puts("Replacing mapping for #{@opts["field"]}")
|
259
|
+
end
|
260
|
+
fpmap << mapping
|
261
|
+
resp = fpmap.upload(@store)
|
262
|
+
if resp.status != 200
|
263
|
+
out.puts "Unable to update FieldPredicate map in store. Response code was #{resp.status}"
|
264
|
+
else
|
265
|
+
out.puts "FieldPredicate map successfully updated"
|
266
|
+
end
|
267
|
+
end
|
163
268
|
|
269
|
+
def add_weight(out=$stdout)
|
270
|
+
qp = Pho::QueryProfile.read_from_store(@store)
|
271
|
+
weight = Pho::QueryProfile.create_weighting(@store, @opts["field"], @opts["weight"])
|
272
|
+
|
273
|
+
removed = qp.remove_by_name( @opts["field"] )
|
274
|
+
if removed != nil
|
275
|
+
out.puts("Replacing weighting for #{@opts["field"]}")
|
276
|
+
end
|
277
|
+
qp << weight
|
278
|
+
resp = qp.upload(@store)
|
279
|
+
if resp.status != 200
|
280
|
+
out.puts "Unable to update QueryProfile in store. Response code was #{resp.status}"
|
281
|
+
else
|
282
|
+
out.puts "QueryProfile successfully updated"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
#TODO remove_mapping
|
287
|
+
|
288
|
+
#End CommandLine
|
164
289
|
end
|
165
290
|
|
166
291
|
end
|
data/lib/pho/oai.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Pho
|
2
|
+
|
3
|
+
#OAI-PMH Support
|
4
|
+
module OAI
|
5
|
+
|
6
|
+
class Record
|
7
|
+
|
8
|
+
attr_reader :identifier
|
9
|
+
attr_reader :timestamp
|
10
|
+
|
11
|
+
def initialize(identifier, timestamp)
|
12
|
+
@identifier = identifier
|
13
|
+
@timestamp = timestamp
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
#Collection of records
|
19
|
+
class Records
|
20
|
+
|
21
|
+
attr_reader :responseDate, :from, :to, :records, :token
|
22
|
+
|
23
|
+
def initialize(responseDate, token, from, to, records=[])
|
24
|
+
@responseDate = responseDate
|
25
|
+
@token = token
|
26
|
+
@from = from
|
27
|
+
@to = to
|
28
|
+
@records = records
|
29
|
+
end
|
30
|
+
|
31
|
+
def Records.parse(response)
|
32
|
+
doc = REXML::Document.new(response)
|
33
|
+
records = []
|
34
|
+
REXML::XPath.each( doc.root, "//oai:header", {"oai" => "http://www.openarchives.org/OAI/2.0/"} ) do |header|
|
35
|
+
uri = header.get_elements("identifier")[0].text
|
36
|
+
datestamp = header.get_elements("datestamp")[0].text
|
37
|
+
records << Record.new(uri, datestamp)
|
38
|
+
end
|
39
|
+
#FIXME
|
40
|
+
return Records.new(nil, nil, nil, nil, records)
|
41
|
+
end
|
42
|
+
|
43
|
+
#List records from a store
|
44
|
+
#TODO support for from/to dates
|
45
|
+
#TODO support for resumption tokens
|
46
|
+
def Records.read_from_store(store)
|
47
|
+
resp = store.list_records
|
48
|
+
if resp.status != 200
|
49
|
+
raise "Unable to list records"
|
50
|
+
end
|
51
|
+
return parse(resp.content)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/pho/rdf.rb
CHANGED
@@ -51,6 +51,7 @@ module Pho
|
|
51
51
|
# store:: the store to receive the data
|
52
52
|
# base_uri:: base uri against which the data is parsed
|
53
53
|
# graph_name:: uri of graph in store
|
54
|
+
# TODO: can now be submitted as turtle
|
54
55
|
def Parser.store_ntriples(file, store, base_uri=nil, graph_name=nil)
|
55
56
|
data = Parser.parse_ntriples(file, base_uri)
|
56
57
|
return store.store_data(data, graph_name)
|
@@ -62,6 +63,7 @@ module Pho
|
|
62
63
|
# store:: the store to receive the data
|
63
64
|
# base_uri:: base uri against which the data is parsed
|
64
65
|
# graph_name:: uri of graph in store
|
66
|
+
# TODO: can now be submitted as turtle
|
65
67
|
def Parser.store_ntriples_from_string(string, store, base_uri, graph_name=nil)
|
66
68
|
data = Parser.parse_ntriples_from_string(string, base_uri)
|
67
69
|
return store.store_data(data, graph_name)
|
data/lib/pho/rdf_collection.rb
CHANGED
@@ -9,21 +9,33 @@ module Pho
|
|
9
9
|
class RDFManager < AbstractFileManager
|
10
10
|
|
11
11
|
RDF = "rdf".freeze
|
12
|
+
TTL = "ttl".freeze
|
13
|
+
NT = "nt".freeze
|
12
14
|
|
13
|
-
|
15
|
+
ALL_RDF = [RDF, TTL, NT]
|
16
|
+
|
17
|
+
def initialize(store, dir, rdf_suffixes=ALL_RDF, ok_suffix=OK, fail_suffix=FAIL, sleep=1)
|
14
18
|
super(store, dir, ok_suffix, fail_suffix, sleep)
|
15
|
-
@
|
19
|
+
@rdf_suffixes = rdf_suffixes
|
16
20
|
end
|
17
21
|
|
18
22
|
#List files being managed
|
19
23
|
def list(recursive=false)
|
20
|
-
return Dir.glob( File.join(@dir, "
|
24
|
+
return Dir.glob( File.join(@dir, "*.\{#{ @rdf_suffixes.join(",") }\}") )
|
21
25
|
end
|
22
26
|
|
23
27
|
protected
|
24
28
|
|
25
29
|
def store_file(file, filename)
|
26
|
-
|
30
|
+
ext = File.extname(filename)
|
31
|
+
if ext == ".ttl"
|
32
|
+
response = @store.store_file(file, nil, "text/turtle")
|
33
|
+
elsif ext == ".nt"
|
34
|
+
response = @store.store_file(file, nil, "text/turtle")
|
35
|
+
else
|
36
|
+
response = @store.store_file(file)
|
37
|
+
end
|
38
|
+
|
27
39
|
if (response.status < 300 )
|
28
40
|
File.open(get_ok_file_for(filename), "w") do |file|
|
29
41
|
file.print( "OK" )
|
data/lib/pho/store.rb
CHANGED
@@ -78,7 +78,8 @@ module Pho
|
|
78
78
|
|
79
79
|
# data:: a String containing the data to store
|
80
80
|
# graph_name:: name of a private graph in which to store the data. E.g. "1" or "private". Resolves to /meta/graphs/graph_name
|
81
|
-
|
81
|
+
# format:: mimetype of RDF serialization
|
82
|
+
def store_data(data, graph_name=nil, format="application/rdf+xml")
|
82
83
|
u = nil
|
83
84
|
if graph_name == nil
|
84
85
|
u = build_uri("/meta")
|
@@ -86,17 +87,24 @@ module Pho
|
|
86
87
|
u = build_uri("/meta/graphs/#{graph_name}")
|
87
88
|
end
|
88
89
|
|
89
|
-
|
90
|
+
if format == "text/plain"
|
91
|
+
format = "text/turtle"
|
92
|
+
end
|
93
|
+
|
94
|
+
content_type = {"Content-Type"=> format }
|
95
|
+
response = @client.post(u, data, content_type )
|
90
96
|
return response
|
91
97
|
end
|
92
98
|
|
93
99
|
# Store the contents of a File (or any IO stream) in the Metabox associated with this store
|
94
100
|
# The client does not support streaming submissions of data, so the stream will be fully read before data is submitted to the platform
|
95
|
-
# file:: an IO object
|
96
|
-
|
101
|
+
# file:: an IO object
|
102
|
+
# graph_name:: name of a private graph in which to store teh data. E.g. "1" or "private". Resolves to /meta/graphs/graph_name
|
103
|
+
# format:: mimetype of RDF serialization
|
104
|
+
def store_file(file, graph_name=nil, format="application/rdf+xml")
|
97
105
|
data = file.read()
|
98
106
|
file.close()
|
99
|
-
return store_data(data)
|
107
|
+
return store_data(data, graph_name, format)
|
100
108
|
end
|
101
109
|
|
102
110
|
# Retrieve RDF data from the specified URL and store it in the Store Metabox
|
@@ -431,6 +439,16 @@ module Pho
|
|
431
439
|
return response
|
432
440
|
end
|
433
441
|
|
442
|
+
#############
|
443
|
+
# OAI
|
444
|
+
#############
|
445
|
+
|
446
|
+
def list_records
|
447
|
+
u = build_uri("/services/oai-pmh")
|
448
|
+
response = @client.get(u, {"verb" => "ListRecords", "metadataPrefix" => "oai_dc"})
|
449
|
+
return response
|
450
|
+
end
|
451
|
+
|
434
452
|
#############
|
435
453
|
# CONFIG
|
436
454
|
#############
|
@@ -0,0 +1,229 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'pho'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class CommandLineTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
TEST_FPMAP = <<-EOL
|
9
|
+
{
|
10
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1#description" : {
|
11
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#property" : [ { "value" : "http:\/\/purl.org\/dc\/elements\/1.1\/description", "type" : "uri" } ],
|
12
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "description", "type" : "literal" } ]
|
13
|
+
},
|
14
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1" : {
|
15
|
+
"http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" : [ { "value" : "default field\/predicate map", "type" : "literal" } ],
|
16
|
+
"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type" : [ { "value" : "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#FieldPredicateMap", "type" : "uri" } ],
|
17
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#mappedDatatypeProperty" : [
|
18
|
+
{ "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1#name", "type" : "uri" },
|
19
|
+
{ "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1#title", "type" : "uri" },
|
20
|
+
{ "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1#description", "type" : "uri" }
|
21
|
+
]
|
22
|
+
},
|
23
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1#title" : {
|
24
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#property" : [ { "value" : "http:\/\/purl.org\/dc\/elements\/1.1\/title", "type" : "uri" } ],
|
25
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "title", "type" : "literal" } ]
|
26
|
+
},
|
27
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/fpmaps\/1#name" : {
|
28
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#property" : [ { "value" : "http:\/\/xmlns.com\/foaf\/0.1\/name", "type" : "uri" } ],
|
29
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "name", "type" : "literal" } ]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
EOL
|
33
|
+
|
34
|
+
TEST_QP = <<-EOL
|
35
|
+
{
|
36
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1" : {
|
37
|
+
"http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" : [ { "value" : "default query profile", "type" : "literal" } ],
|
38
|
+
"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type" : [ { "value" : "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#QueryProfile", "type" : "uri" } ],
|
39
|
+
"http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#fieldWeight" : [
|
40
|
+
{ "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#name", "type" : "uri" },
|
41
|
+
{ "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#nick", "type" : "uri" }
|
42
|
+
]
|
43
|
+
},
|
44
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#nick" : {
|
45
|
+
"http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#weight" : [ { "value" : "1.0", "type" : "literal" } ],
|
46
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "nick", "type" : "literal" } ]
|
47
|
+
},
|
48
|
+
"http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#name" : {
|
49
|
+
"http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#weight" : [ { "value" : "2.0", "type" : "literal" } ],
|
50
|
+
"http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "name", "type" : "literal" } ]
|
51
|
+
}
|
52
|
+
}
|
53
|
+
EOL
|
54
|
+
|
55
|
+
def setup
|
56
|
+
@opts = {}
|
57
|
+
@opts["username"] = "tester"
|
58
|
+
@opts["password"] = "pass"
|
59
|
+
@opts["store"] = "testing"
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def teardown
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_fpmap()
|
67
|
+
mc = mock()
|
68
|
+
mc.expects(:build_uri).returns( "http://api.talis.com/stores/testing/config/fpmaps/1" )
|
69
|
+
mc.expects(:get_field_predicate_map).returns( HTTP::Message.new_response(TEST_FPMAP) )
|
70
|
+
|
71
|
+
s = StringIO.new()
|
72
|
+
cmdline = Pho::CommandLine.new(@opts, {}, mc)
|
73
|
+
cmdline.fpmap(s)
|
74
|
+
|
75
|
+
lines = s.string().split("\n")
|
76
|
+
assert_equal("description -> http://purl.org/dc/elements/1.1/description", lines[0])
|
77
|
+
assert_equal("name -> http://xmlns.com/foaf/0.1/name", lines[1])
|
78
|
+
assert_equal("title -> http://purl.org/dc/elements/1.1/title", lines[2])
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_fpmap_raw()
|
82
|
+
mc = mock()
|
83
|
+
mc.expects(:get_field_predicate_map).returns( HTTP::Message.new_response(TEST_FPMAP) )
|
84
|
+
|
85
|
+
s = StringIO.new()
|
86
|
+
@opts["raw"] = ""
|
87
|
+
cmdline = Pho::CommandLine.new(@opts, {}, mc)
|
88
|
+
cmdline.fpmap(s)
|
89
|
+
assert_equal(TEST_FPMAP, s.string)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_queryprofile_raw()
|
93
|
+
mc = mock()
|
94
|
+
mc.expects(:get_query_profile).returns( HTTP::Message.new_response(TEST_QP) )
|
95
|
+
|
96
|
+
s = StringIO.new()
|
97
|
+
@opts["raw"] = ""
|
98
|
+
cmdline = Pho::CommandLine.new(@opts, {}, mc )
|
99
|
+
cmdline.queryprofile(s)
|
100
|
+
assert_equal(TEST_QP, s.string)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_queryprofile()
|
104
|
+
mc = mock()
|
105
|
+
mc.expects(:build_uri).returns( "http://api.talis.com/stores/testing/config/queryprofiles/1" )
|
106
|
+
mc.expects(:get_query_profile).returns( HTTP::Message.new_response(TEST_QP) )
|
107
|
+
|
108
|
+
s = StringIO.new()
|
109
|
+
cmdline = Pho::CommandLine.new(@opts, {}, mc)
|
110
|
+
cmdline.queryprofile(s)
|
111
|
+
|
112
|
+
lines = s.string().split("\n")
|
113
|
+
assert_equal("name -> 2.0", lines[0])
|
114
|
+
assert_equal("nick -> 1.0", lines[1])
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_username()
|
118
|
+
opts = {}
|
119
|
+
env = {}
|
120
|
+
|
121
|
+
assert_raise RuntimeError do
|
122
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
123
|
end
|
124
|
+
|
125
|
+
opts["username"] = "tester"
|
126
|
+
opts["password"] = "pass"
|
127
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
128
|
+
assert_equal("tester", cmdline.username)
|
129
|
+
|
130
|
+
opts = {}
|
131
|
+
opts["password"] = "pass"
|
132
|
+
env["TALIS_USER"] = "tester"
|
133
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
134
|
+
assert_equal("tester", cmdline.username)
|
135
|
+
|
136
|
+
opts["username"] = "override"
|
137
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
138
|
+
assert_equal("override", cmdline.username)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_password()
|
142
|
+
opts = {}
|
143
|
+
env = {}
|
144
|
+
|
145
|
+
opts["username"] = "tester"
|
146
|
+
assert_raise RuntimeError do
|
147
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
148
|
+
end
|
149
|
+
|
150
|
+
opts["password"] = "pass"
|
151
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
152
|
+
assert_equal("pass", cmdline.password)
|
153
|
+
|
154
|
+
opts = {}
|
155
|
+
opts["username"] = "tester"
|
156
|
+
env["TALIS_PASS"] = "pass"
|
157
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
158
|
+
assert_equal("pass", cmdline.password)
|
159
|
+
|
160
|
+
opts["password"] = "override"
|
161
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
162
|
+
assert_equal("override", cmdline.password)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_store()
|
166
|
+
opts = {}
|
167
|
+
env = {}
|
168
|
+
opts["username"] = "tester"
|
169
|
+
opts["password"] = "pass"
|
170
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
171
|
+
assert_equal(nil, cmdline.storename)
|
172
|
+
|
173
|
+
opts["store"] = "http://api.talis.com/stores/testing"
|
174
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
175
|
+
assert_equal("http://api.talis.com/stores/testing", cmdline.storename)
|
176
|
+
|
177
|
+
opts["store"] = "testing"
|
178
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
179
|
+
assert_equal("http://api.talis.com/stores/testing", cmdline.storename)
|
180
|
+
|
181
|
+
opts = {}
|
182
|
+
opts["username"] = "tester"
|
183
|
+
opts["password"] = "pass"
|
184
|
+
env["TALIS_STORE"] = "http://api.talis.com/stores/testing"
|
185
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
186
|
+
assert_equal("http://api.talis.com/stores/testing", cmdline.storename)
|
187
|
+
|
188
|
+
env["TALIS_STORE"] = "testing"
|
189
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
190
|
+
assert_equal("http://api.talis.com/stores/testing", cmdline.storename)
|
191
|
+
|
192
|
+
opts["store"] = "override"
|
193
|
+
cmdline = Pho::CommandLine.new(opts, env, mock())
|
194
|
+
assert_equal("http://api.talis.com/stores/override", cmdline.storename)
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_add_mapping()
|
199
|
+
mc = mock()
|
200
|
+
mc.expects(:build_uri).with("/config/fpmaps/1").returns( "http://api.talis.com/stores/testing/config/fpmaps/1" )
|
201
|
+
mc.expects(:get_field_predicate_map).returns( HTTP::Message.new_response(TEST_FPMAP) )
|
202
|
+
mc.expects(:build_uri).with("/config/fpmaps/1#test").returns( "http://api.talis.com/stores/testing/config/fpmaps/1#test" )
|
203
|
+
mc.expects(:put_field_predicate_map).returns( HTTP::Message.new_response("") )
|
204
|
+
|
205
|
+
@opts["field"] = "test"
|
206
|
+
@opts["predicate"] = "http://www.example.org/test"
|
207
|
+
|
208
|
+
s = StringIO.new()
|
209
|
+
cmdline = Pho::CommandLine.new(@opts, {}, mc)
|
210
|
+
cmdline.add_mapping(s)
|
211
|
+
assert_equal("FieldPredicate map successfully updated\n", s.string)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_add_weight()
|
215
|
+
mc = mock()
|
216
|
+
mc.expects(:build_uri).with("/config/queryprofiles/1").returns( "http://api.talis.com/stores/testing/config/queryprofiles/1")
|
217
|
+
mc.expects(:get_query_profile).returns( HTTP::Message.new_response(TEST_QP) )
|
218
|
+
mc.expects(:build_uri).with("/config/queryprofiles/1#test").returns("http://api.talis.com/stores/testing/config/queryprofiles/1#test" )
|
219
|
+
mc.expects(:put_query_profile).returns( HTTP::Message.new_response("") )
|
220
|
+
|
221
|
+
@opts["field"] = "test"
|
222
|
+
@opts["weight"] = "10.0"
|
223
|
+
|
224
|
+
s = StringIO.new()
|
225
|
+
cmdline = Pho::CommandLine.new(@opts, {}, mc)
|
226
|
+
cmdline.add_weight(s)
|
227
|
+
assert_equal("QueryProfile successfully updated\n", s.string)
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|