pho 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +17 -0
- data/Rakefile +10 -2
- data/bin/talis_store +37 -92
- data/doc/rdoc/classes/Pho.html +11 -0
- data/doc/rdoc/classes/Pho/CommandLine.html +508 -0
- data/doc/rdoc/classes/Pho/DatatypeProperty.html +15 -15
- data/doc/rdoc/classes/Pho/Enrichment.html +1 -1
- data/doc/rdoc/classes/Pho/Enrichment/{ResourceEnricher.html → StoreEnricher.html} +158 -58
- 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 +94 -94
- data/doc/rdoc/classes/Pho/FieldWeighting.html +14 -14
- data/doc/rdoc/classes/Pho/FileManagement/AbstractFileManager.html +126 -91
- data/doc/rdoc/classes/Pho/FileManagement/FileManager.html +68 -62
- data/doc/rdoc/classes/Pho/FileManagement/RDFManager.html +22 -57
- data/doc/rdoc/classes/Pho/Job.html +68 -67
- data/doc/rdoc/classes/Pho/Jobs.html +62 -62
- data/doc/rdoc/classes/Pho/QueryProfile.html +64 -64
- data/doc/rdoc/classes/Pho/RDF.html +120 -0
- data/doc/rdoc/classes/Pho/RDF/Parser.html +277 -0
- data/doc/rdoc/classes/Pho/ResourceHash.html +1 -1
- data/doc/rdoc/classes/Pho/ResourceHash/Converter.html +48 -46
- data/doc/rdoc/classes/Pho/ResourceHash/SetAlgebra.html +15 -14
- data/doc/rdoc/classes/Pho/Snapshot.html +36 -36
- data/doc/rdoc/classes/Pho/Sparql.html +50 -0
- data/doc/rdoc/classes/Pho/Sparql/SparqlClient.html +147 -68
- data/doc/rdoc/classes/Pho/Sparql/SparqlHelper.html +195 -114
- data/doc/rdoc/classes/Pho/Status.html +26 -26
- data/doc/rdoc/classes/Pho/Store.html +271 -264
- data/doc/rdoc/classes/Pho/StoreSparqlClient.html +183 -0
- data/doc/rdoc/classes/Pho/Update.html +1 -0
- data/doc/rdoc/classes/Pho/Update/Changeset.html +69 -68
- data/doc/rdoc/classes/Pho/Update/ChangesetBuilder.html +24 -24
- data/doc/rdoc/classes/Pho/Update/Changesets.html +15 -14
- data/doc/rdoc/classes/Pho/Update/LiteralStatement.html +18 -18
- data/doc/rdoc/classes/Pho/Update/ResourceStatement.html +24 -24
- data/doc/rdoc/classes/Pho/Update/Statement.html +28 -27
- data/doc/rdoc/classes/String.html +1 -1
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +53 -1
- data/doc/rdoc/files/lib/pho/changeset_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/command_line_rb.html +101 -0
- data/doc/rdoc/files/lib/pho/converter_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/enrichment_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_management_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/file_manager_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 +108 -0
- data/doc/rdoc/files/lib/pho/sparql_rb.html +1 -1
- data/doc/rdoc/files/lib/pho/store_rb.html +8 -1
- data/doc/rdoc/files/lib/pho_rb.html +4 -2
- data/doc/rdoc/fr_class_index.html +6 -1
- data/doc/rdoc/fr_file_index.html +2 -0
- data/doc/rdoc/fr_method_index.html +192 -172
- data/examples/calais/bio.txt +7 -0
- data/examples/calais/dump.rb +17 -0
- data/examples/calais/enlighten.rb +23 -0
- data/examples/calais/output.rdf +25 -0
- data/examples/sinatra/viewer.rb +20 -0
- data/lib/pho.rb +4 -1
- data/lib/pho/changeset.rb +17 -1
- data/lib/pho/command_line.rb +166 -0
- data/lib/pho/converter.rb +8 -3
- data/lib/pho/enrichment.rb +93 -28
- data/lib/pho/file_management.rb +32 -19
- data/lib/pho/file_manager.rb +22 -26
- data/lib/pho/rdf.rb +74 -0
- data/lib/pho/rdf_collection.rb +2 -17
- data/lib/pho/sparql.rb +150 -38
- data/lib/pho/store.rb +28 -2
- data/tests/tc_contentbox.rb +41 -0
- data/tests/tc_enrichment.rb +41 -4
- data/tests/tc_file_manager.rb +97 -7
- data/tests/tc_rdf_collection.rb +25 -13
- data/tests/tc_rdf_parser.rb +37 -0
- data/tests/tc_sparql.rb +72 -2
- data/tests/tc_sparql_helper.rb +16 -0
- data/tests/ts_pho.rb +2 -1
- metadata +20 -3
data/lib/pho/store.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Pho
|
2
2
|
|
3
|
+
require 'pho/sparql'
|
4
|
+
|
3
5
|
#TODO:
|
4
6
|
#
|
5
7
|
# Conditional deletions
|
@@ -180,7 +182,7 @@ module Pho
|
|
180
182
|
u = self.build_uri("/services/sparql")
|
181
183
|
end
|
182
184
|
|
183
|
-
sparql_client =
|
185
|
+
sparql_client = StoreSparqlClient.new(@self, u, @client)
|
184
186
|
sparql_client.supports_rdf_json = true
|
185
187
|
sparql_client.supports_sparql_json = true
|
186
188
|
|
@@ -341,7 +343,12 @@ module Pho
|
|
341
343
|
response = @client.post(u, data, headers)
|
342
344
|
else
|
343
345
|
if !uri.start_with?(@storeuri)
|
344
|
-
uri
|
346
|
+
if uri.start_with?("/")
|
347
|
+
uri = build_uri("/items#{uri}")
|
348
|
+
else
|
349
|
+
uri = build_uri("/items/#{uri}")
|
350
|
+
end
|
351
|
+
|
345
352
|
end
|
346
353
|
response = @client.put(uri, data, headers)
|
347
354
|
end
|
@@ -472,4 +479,23 @@ module Pho
|
|
472
479
|
|
473
480
|
end
|
474
481
|
|
482
|
+
class StoreSparqlClient < Pho::Sparql::SparqlClient
|
483
|
+
|
484
|
+
def initialize(store, endpoint, client=HTTPClient.new() )
|
485
|
+
super(endpoint, client)
|
486
|
+
@store = store
|
487
|
+
end
|
488
|
+
|
489
|
+
#Override default behaviour to use the Stores Describe service instead
|
490
|
+
#when requesting CBDs
|
491
|
+
def describe_uri(uri, format="application/rdf+xml", type=:cbd)
|
492
|
+
if type == :cbd
|
493
|
+
return @store.describe(uri, format)
|
494
|
+
else
|
495
|
+
return super
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
end
|
500
|
+
|
475
501
|
end
|
data/tests/tc_contentbox.rb
CHANGED
@@ -24,6 +24,47 @@ class ContentboxTest < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_upload_item_to_uri_with_relative
|
28
|
+
mc = mock()
|
29
|
+
mc.expects(:set_auth)
|
30
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/1/2/3", "data", {"Content-Type" => "text/plain"})
|
31
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
32
|
+
f = StringIO.new("data")
|
33
|
+
resp = store.upload_item(f, "text/plain", "/1/2/3")
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_upload_item_to_uri_with_relative_file
|
38
|
+
mc = mock()
|
39
|
+
mc.expects(:set_auth)
|
40
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/a.txt", "data", {"Content-Type" => "text/plain"})
|
41
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
42
|
+
f = StringIO.new("data")
|
43
|
+
resp = store.upload_item(f, "text/plain", "/a.txt")
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_upload_item_to_uri_with_relative2
|
48
|
+
mc = mock()
|
49
|
+
mc.expects(:set_auth)
|
50
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/1/2/3", "data", {"Content-Type" => "text/plain"})
|
51
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
52
|
+
f = StringIO.new("data")
|
53
|
+
resp = store.upload_item(f, "text/plain", "1/2/3")
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_upload_item_to_uri_with_relative_file2
|
58
|
+
mc = mock()
|
59
|
+
mc.expects(:set_auth)
|
60
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/a.txt", "data", {"Content-Type" => "text/plain"})
|
61
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
62
|
+
f = StringIO.new("data")
|
63
|
+
resp = store.upload_item(f, "text/plain", "a.txt")
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
27
68
|
def test_delete
|
28
69
|
mc = mock()
|
29
70
|
mc.expects(:set_auth)
|
data/tests/tc_enrichment.rb
CHANGED
@@ -25,12 +25,31 @@ class EnrichmentTest < Test::Unit::TestCase
|
|
25
25
|
mc = mock()
|
26
26
|
mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
|
27
27
|
|
28
|
-
enricher = Pho::Enrichment::
|
28
|
+
enricher = Pho::Enrichment::StoreEnricher.new(mock_store, mc)
|
29
29
|
resp = enricher.merge(query)
|
30
30
|
assert_not_nil(resp)
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_merge_with_block()
|
35
|
+
|
36
|
+
query = "DESCRIBE <http://www.example.org>"
|
37
|
+
mock_store = mock()
|
38
|
+
mock_store.expects(:store_data).with(RDFXML).returns( HTTP::Message.new_response("OK") )
|
39
|
+
|
40
|
+
mc = mock()
|
41
|
+
mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
|
42
|
+
|
43
|
+
enricher = Pho::Enrichment::StoreEnricher.new(mock_store, mc)
|
44
|
+
resp = enricher.merge(query) do |resp, data|
|
45
|
+
assert_equal( 200, resp.status )
|
46
|
+
assert_equal( RDFXML, data)
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_not_nil(resp)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
34
53
|
def test_merge_with_failed_query()
|
35
54
|
|
36
55
|
query = "DESCRIBE <http://www.example.org>"
|
@@ -41,7 +60,7 @@ class EnrichmentTest < Test::Unit::TestCase
|
|
41
60
|
msg.status = 500
|
42
61
|
mc.expects(:query).with( query, "application/rdf+xml" ).returns( msg )
|
43
62
|
|
44
|
-
enricher = Pho::Enrichment::
|
63
|
+
enricher = Pho::Enrichment::StoreEnricher.new(mock_store, mc)
|
45
64
|
assert_raises RuntimeError do
|
46
65
|
results = enricher.merge(query)
|
47
66
|
end
|
@@ -59,7 +78,7 @@ class EnrichmentTest < Test::Unit::TestCase
|
|
59
78
|
mc = mock()
|
60
79
|
mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
|
61
80
|
|
62
|
-
enricher = Pho::Enrichment::
|
81
|
+
enricher = Pho::Enrichment::StoreEnricher.new(mock_store, mc)
|
63
82
|
resp = enricher.merge(query)
|
64
83
|
assert_equal(500, resp.status)
|
65
84
|
|
@@ -75,9 +94,27 @@ class EnrichmentTest < Test::Unit::TestCase
|
|
75
94
|
mock_store.expects(:sparql_client).returns(mc)
|
76
95
|
mock_store.expects(:store_data).with(RDFXML).returns( HTTP::Message.new_response("OK") )
|
77
96
|
|
78
|
-
resp = Pho::Enrichment::
|
97
|
+
resp = Pho::Enrichment::StoreEnricher.infer(mock_store, query)
|
79
98
|
assert_not_nil(resp)
|
80
99
|
|
81
100
|
end
|
101
|
+
|
102
|
+
def test_infer_with_block()
|
103
|
+
query = "CONSTRUCT { ?s ex:foo ?o } WHERE { ?s ex:bar ?o }"
|
104
|
+
|
105
|
+
mc = mock()
|
106
|
+
mc.expects(:query).with( query, "application/rdf+xml" ).returns( HTTP::Message.new_response(RDFXML) )
|
107
|
+
|
108
|
+
mock_store = mock()
|
109
|
+
mock_store.expects(:sparql_client).returns(mc)
|
110
|
+
mock_store.expects(:store_data).with(RDFXML).returns( HTTP::Message.new_response("OK") )
|
111
|
+
|
112
|
+
resp = Pho::Enrichment::StoreEnricher.infer(mock_store, query) do |resp, data|
|
113
|
+
assert_equal(200, resp.status)
|
114
|
+
assert_equal(RDFXML, data)
|
115
|
+
end
|
82
116
|
|
117
|
+
assert_not_nil(resp)
|
118
|
+
|
119
|
+
end
|
83
120
|
end
|
data/tests/tc_file_manager.rb
CHANGED
@@ -7,6 +7,8 @@ class FileManagerTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def setup()
|
9
9
|
Dir.mkdir("/tmp/pho") unless File.exists?("/tmp/pho")
|
10
|
+
Dir.mkdir("/tmp/pho/a") unless File.exists?("/tmp/pho/a")
|
11
|
+
Dir.mkdir("/tmp/pho/b") unless File.exists?("/tmp/pho/b")
|
10
12
|
7.times do |i|
|
11
13
|
file = File.new( File.join("/tmp/pho", "#{i}.css"), "w" )
|
12
14
|
file.write("CSS#{i}")
|
@@ -28,7 +30,24 @@ class FileManagerTest < Test::Unit::TestCase
|
|
28
30
|
file = File.new( File.join("/tmp/pho", "#{num}.fail"), "w" )
|
29
31
|
file.write("FAIL")
|
30
32
|
file.close()
|
31
|
-
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#/tmp/pho/a
|
36
|
+
2.times do |i|
|
37
|
+
num = i
|
38
|
+
file = File.new( File.join("/tmp/pho/a", "#{num}.txt"), "w" )
|
39
|
+
file.write("TXT#{num}")
|
40
|
+
file.close()
|
41
|
+
end
|
42
|
+
|
43
|
+
#/tmp/pho/b
|
44
|
+
1.times do |i|
|
45
|
+
num = i
|
46
|
+
file = File.new( File.join("/tmp/pho/b", "#{num}.txt"), "w" )
|
47
|
+
file.write("TXT#{num}")
|
48
|
+
file.close()
|
49
|
+
end
|
50
|
+
|
32
51
|
end
|
33
52
|
|
34
53
|
def teardown()
|
@@ -38,12 +57,15 @@ class FileManagerTest < Test::Unit::TestCase
|
|
38
57
|
Dir.glob("/tmp/pho/*.js") do |file|
|
39
58
|
File.delete(file)
|
40
59
|
end
|
41
|
-
Dir.glob("/tmp/pho
|
60
|
+
Dir.glob("/tmp/pho/**/*.ok") do |file|
|
42
61
|
File.delete(file)
|
43
62
|
end
|
44
|
-
Dir.glob("/tmp/pho
|
63
|
+
Dir.glob("/tmp/pho/**/*.fail") do |file|
|
45
64
|
File.delete(file)
|
46
|
-
end
|
65
|
+
end
|
66
|
+
Dir.glob("/tmp/pho/**/*.txt") do |file|
|
67
|
+
File.delete(file)
|
68
|
+
end
|
47
69
|
end
|
48
70
|
|
49
71
|
def test_new_files()
|
@@ -58,14 +80,31 @@ class FileManagerTest < Test::Unit::TestCase
|
|
58
80
|
assert_equal("/tmp/pho/9.js", newfiles[2])
|
59
81
|
|
60
82
|
end
|
83
|
+
|
84
|
+
def test_new_files_recursive()
|
85
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
86
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
87
|
+
|
88
|
+
newfiles = collection.new_files(:recurse)
|
89
|
+
newfiles.sort!
|
90
|
+
|
91
|
+
assert_equal(6, newfiles.size)
|
92
|
+
assert_equal("/tmp/pho/7.js", newfiles[0])
|
93
|
+
assert_equal("/tmp/pho/8.js", newfiles[1])
|
94
|
+
assert_equal("/tmp/pho/9.js", newfiles[2])
|
95
|
+
assert_equal("/tmp/pho/a/0.txt", newfiles[3])
|
96
|
+
assert_equal("/tmp/pho/a/1.txt", newfiles[4])
|
97
|
+
assert_equal("/tmp/pho/b/0.txt", newfiles[5])
|
98
|
+
|
99
|
+
end
|
61
100
|
|
62
101
|
def test_store()
|
63
102
|
mc = mock()
|
64
103
|
mc.expects(:set_auth)
|
65
104
|
#mc.stub_everything()
|
66
|
-
mc.expects(:
|
67
|
-
mc.expects(:
|
68
|
-
mc.expects(:
|
105
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/7.js", "JS7", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
106
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/8.js", "JS8", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
107
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/9.js", "JS9", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
69
108
|
|
70
109
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
71
110
|
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
@@ -76,6 +115,49 @@ class FileManagerTest < Test::Unit::TestCase
|
|
76
115
|
assert_equal(true, File.exists?("/tmp/pho/9.ok") )
|
77
116
|
|
78
117
|
end
|
118
|
+
|
119
|
+
def test_store_with_base()
|
120
|
+
mc = mock()
|
121
|
+
mc.expects(:set_auth)
|
122
|
+
#mc.stub_everything()
|
123
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/assets/7.js", "JS7", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
124
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/assets/8.js", "JS8", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
125
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/assets/9.js", "JS9", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
126
|
+
|
127
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
128
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho", "assets")
|
129
|
+
collection.store()
|
130
|
+
|
131
|
+
assert_equal(true, File.exists?("/tmp/pho/7.ok") )
|
132
|
+
assert_equal(true, File.exists?("/tmp/pho/8.ok") )
|
133
|
+
assert_equal(true, File.exists?("/tmp/pho/9.ok") )
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
def test_store_recursive()
|
139
|
+
mc = mock()
|
140
|
+
mc.expects(:set_auth)
|
141
|
+
#mc.stub_everything()
|
142
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/7.js", "JS7", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
143
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/8.js", "JS8", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
144
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/9.js", "JS9", {"Content-Type" => "application/javascript"}).returns( HTTP::Message.new_response("OK"))
|
145
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/a/0.txt", "TXT0", {"Content-Type" => "text/plain"}).returns( HTTP::Message.new_response("OK"))
|
146
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/a/1.txt", "TXT1", {"Content-Type" => "text/plain"}).returns( HTTP::Message.new_response("OK"))
|
147
|
+
mc.expects(:put).with("http://api.talis.com/stores/testing/items/b/0.txt", "TXT0", {"Content-Type" => "text/plain"}).returns( HTTP::Message.new_response("OK"))
|
148
|
+
|
149
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
150
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
151
|
+
collection.store(:recursive)
|
152
|
+
|
153
|
+
assert_equal(true, File.exists?("/tmp/pho/7.ok") )
|
154
|
+
assert_equal(true, File.exists?("/tmp/pho/8.ok") )
|
155
|
+
assert_equal(true, File.exists?("/tmp/pho/9.ok") )
|
156
|
+
assert_equal(true, File.exists?("/tmp/pho/a/0.ok") )
|
157
|
+
assert_equal(true, File.exists?("/tmp/pho/a/1.ok") )
|
158
|
+
assert_equal(true, File.exists?("/tmp/pho/b/0.ok") )
|
159
|
+
|
160
|
+
end
|
79
161
|
|
80
162
|
def test_list()
|
81
163
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
@@ -85,4 +167,12 @@ class FileManagerTest < Test::Unit::TestCase
|
|
85
167
|
assert_equal(10, files.size)
|
86
168
|
end
|
87
169
|
|
170
|
+
def test_list_recursive()
|
171
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
172
|
+
collection = Pho::FileManagement::FileManager.new(store, "/tmp/pho")
|
173
|
+
|
174
|
+
files = collection.list(:recurse)
|
175
|
+
assert_equal(13, files.size)
|
176
|
+
end
|
177
|
+
|
88
178
|
end
|
data/tests/tc_rdf_collection.rb
CHANGED
@@ -4,7 +4,6 @@ require 'test/unit'
|
|
4
4
|
require 'mocha'
|
5
5
|
|
6
6
|
#TODO factor out tests for AbstractFileManager
|
7
|
-
#TODO alter so we're testing the non-deprecated version of the Class
|
8
7
|
class RDFCollectionTest < Test::Unit::TestCase
|
9
8
|
|
10
9
|
def setup()
|
@@ -40,21 +39,36 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
40
39
|
|
41
40
|
def test_get_fail_file_for()
|
42
41
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
43
|
-
collection = Pho::
|
42
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
44
43
|
|
45
44
|
assert_equal("foo.fail", collection.get_fail_file_for("foo.rdf") )
|
46
45
|
end
|
47
|
-
|
46
|
+
|
47
|
+
def test_get_fail_file_for_with_ext_in_path()
|
48
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
49
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp/rdf")
|
50
|
+
|
51
|
+
assert_equal("/tmp/rdf/foo.fail", collection.get_fail_file_for("/tmp/rdf/foo.rdf") )
|
52
|
+
end
|
53
|
+
|
48
54
|
def test_get_ok_file_for()
|
49
55
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
50
|
-
collection = Pho::
|
56
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
51
57
|
|
52
58
|
assert_equal("foo.ok", collection.get_ok_file_for("foo.rdf") )
|
53
59
|
end
|
54
60
|
|
61
|
+
def test_get_ok_file_for_with_ext_in_path()
|
62
|
+
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
63
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp/js")
|
64
|
+
|
65
|
+
assert_equal("/tmp/js/foo.ok", collection.get_ok_file_for("/tmp/js/foo.js") )
|
66
|
+
end
|
67
|
+
|
68
|
+
|
55
69
|
def test_successes()
|
56
70
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
57
|
-
collection = Pho::
|
71
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
58
72
|
|
59
73
|
success = collection.successes()
|
60
74
|
success.sort!
|
@@ -68,7 +82,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
68
82
|
|
69
83
|
def test_failures()
|
70
84
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
71
|
-
collection = Pho::
|
85
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
72
86
|
|
73
87
|
fails = collection.failures()
|
74
88
|
fails.sort!
|
@@ -80,7 +94,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
80
94
|
|
81
95
|
def test_new_files()
|
82
96
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
83
|
-
collection = Pho::
|
97
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
84
98
|
|
85
99
|
newfiles = collection.new_files()
|
86
100
|
newfiles.sort!
|
@@ -99,7 +113,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
99
113
|
mc.expects(:post).with("http://api.talis.com/stores/testing/meta", "RDF9", {"Content-Type" => "application/rdf+xml"}).returns( HTTP::Message.new_response("OK"))
|
100
114
|
|
101
115
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
|
102
|
-
collection = Pho::
|
116
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
103
117
|
collection.store()
|
104
118
|
|
105
119
|
assert_equal(true, File.exists?("/tmp/7.ok") )
|
@@ -110,7 +124,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
110
124
|
|
111
125
|
def test_reset()
|
112
126
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
113
|
-
collection = Pho::
|
127
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
114
128
|
|
115
129
|
collection.reset()
|
116
130
|
newfiles = collection.new_files()
|
@@ -119,7 +133,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
119
133
|
|
120
134
|
def test_list()
|
121
135
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
122
|
-
collection = Pho::
|
136
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
123
137
|
|
124
138
|
files = collection.list()
|
125
139
|
assert_equal(10, files.size)
|
@@ -127,9 +141,7 @@ class RDFCollectionTest < Test::Unit::TestCase
|
|
127
141
|
|
128
142
|
def test_summary()
|
129
143
|
store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
|
130
|
-
collection = Pho::
|
131
|
-
|
132
|
-
collection.summary()
|
144
|
+
collection = Pho::FileManagement::RDFManager.new(store, "/tmp")
|
133
145
|
end
|
134
146
|
|
135
147
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'pho'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
class RdfParserTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
NTRIPLES = <<-EOL
|
10
|
+
<http://www.example.org> <http://www.example.org/ns/resource> <http://www.example.org/page>.
|
11
|
+
EOL
|
12
|
+
|
13
|
+
def setup()
|
14
|
+
Dir.mkdir("/tmp/pho") unless File.exists?("/tmp/pho")
|
15
|
+
@file = File.new( File.join("/tmp/pho", "test.nt"), "w" )
|
16
|
+
@file.write(NTRIPLES)
|
17
|
+
@file.close()
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown()
|
21
|
+
Dir.glob("/tmp/pho/*.nt") do |file|
|
22
|
+
File.delete(file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_parse_ntriples
|
27
|
+
data = Pho::RDF::Parser.parse_ntriples(@file)
|
28
|
+
assert_not_nil(data)
|
29
|
+
REXML::Document.new(data)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parse_ntriples_from_string
|
33
|
+
data = Pho::RDF::Parser.parse_ntriples_from_string(NTRIPLES, "http://www.example.org")
|
34
|
+
assert_not_nil(data)
|
35
|
+
REXML::Document.new(data)
|
36
|
+
end
|
37
|
+
end
|