wf4ever-rosrs-client 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/wf4ever/rosrs/session.rb +66 -7
- data/test/test_abstract_interaction.rb +1 -1
- data/test/test_rosrs_session.rb +14 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -225,6 +225,20 @@ module ROSRS
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
+
def check_research_object(ro_uri)
|
229
|
+
code, reason = do_request_follow_redirect("GET", ro_uri,
|
230
|
+
:accept => "application/rdf+xml")
|
231
|
+
|
232
|
+
case code
|
233
|
+
when 200
|
234
|
+
true
|
235
|
+
when 404
|
236
|
+
false
|
237
|
+
else
|
238
|
+
error(code, "Error checking for RO #{ro_uri}: #{code} #{reason}")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
228
242
|
# ---------------------
|
229
243
|
# Resource manipulation
|
230
244
|
# ---------------------
|
@@ -468,16 +482,30 @@ module ROSRS
|
|
468
482
|
# Enumerate annnotation URIs associated with a resource
|
469
483
|
# (or all annotations for an RO)
|
470
484
|
#
|
471
|
-
# Returns an array of annotation
|
472
|
-
def
|
485
|
+
# Returns an array of annotation statements
|
486
|
+
def get_annotation_statements(ro_uri, resource_uri=nil)
|
473
487
|
manifesturi, manifest = get_manifest(ro_uri)
|
474
|
-
|
475
|
-
|
488
|
+
statements = []
|
489
|
+
|
490
|
+
resource_uri = RDF::URI.parse(ro_uri).join(RDF::URI.parse(resource_uri)) if ro_uri
|
491
|
+
|
492
|
+
manifest.query(:object => resource_uri) do |stmt|
|
476
493
|
if [RDF::AO.annotatesResource,RDF::RO.annotatesAggregatedResource].include?(stmt.predicate)
|
477
|
-
|
494
|
+
statements << stmt
|
478
495
|
end
|
479
496
|
end
|
480
|
-
|
497
|
+
statements
|
498
|
+
end
|
499
|
+
|
500
|
+
##
|
501
|
+
# Enumerate annnotation URIs associated with a resource
|
502
|
+
# (or all annotations for an RO)
|
503
|
+
#
|
504
|
+
# Returns an array of annotation URIs
|
505
|
+
def get_annotation_stub_uris(ro_uri, resource_uri=nil)
|
506
|
+
get_annotation_statements(ro_uri, resource_uri).map do |statement|
|
507
|
+
statement.subject
|
508
|
+
end
|
481
509
|
end
|
482
510
|
|
483
511
|
##
|
@@ -510,6 +538,37 @@ module ROSRS
|
|
510
538
|
body_uris.uniq
|
511
539
|
end
|
512
540
|
|
541
|
+
##
|
542
|
+
# Retrieve RDF graphs of all annnotations associated with a resource
|
543
|
+
# (or all annotations for an RO)
|
544
|
+
#
|
545
|
+
# Returns graph of merged annotations
|
546
|
+
def get_annotation_graphs(ro_uri, resource_uri=nil)
|
547
|
+
annotation_graphs = []
|
548
|
+
get_annotation_statements(ro_uri, resource_uri).each do |annotation_statement|
|
549
|
+
auri = annotation_statement.subject
|
550
|
+
resuri = annotation_statement.object
|
551
|
+
code, reason, headers, buri, bodytext = do_request_follow_redirect("GET", auri, {})
|
552
|
+
if code == 200
|
553
|
+
content_type = headers['content-type'].split(';', 2)[0].strip.downcase
|
554
|
+
if ANNOTATION_CONTENT_TYPES.include?(content_type)
|
555
|
+
bodyformat = ANNOTATION_CONTENT_TYPES[content_type]
|
556
|
+
annotation_graphs << {
|
557
|
+
:stub => auri,
|
558
|
+
:resource_uri => resuri,
|
559
|
+
:body_uri => buri,
|
560
|
+
:body => ROSRS::RDFGraph.new.load_data(bodytext, bodyformat)
|
561
|
+
}
|
562
|
+
else
|
563
|
+
warn("Warning: #{buri} has unrecognized content-type: #{content_type}")
|
564
|
+
end
|
565
|
+
else
|
566
|
+
error(code, "Failed to GET #{buri}: #{code} #{reason}")
|
567
|
+
end
|
568
|
+
end
|
569
|
+
annotation_graphs
|
570
|
+
end
|
571
|
+
|
513
572
|
##
|
514
573
|
# Build RDF graph of all annnotations associated with a resource
|
515
574
|
# (or all annotations for an RO)
|
@@ -669,4 +728,4 @@ module ROSRS
|
|
669
728
|
end
|
670
729
|
|
671
730
|
end
|
672
|
-
end
|
731
|
+
end
|
data/test/test_rosrs_session.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Test suite for ROSRS_Session
|
2
|
-
require 'helper'
|
2
|
+
require File.dirname(__FILE__) + '/helper'
|
3
3
|
|
4
4
|
|
5
5
|
class TestROSRSSession < Test::Unit::TestCase
|
@@ -23,6 +23,19 @@ class TestROSRSSession < Test::Unit::TestCase
|
|
23
23
|
def setup
|
24
24
|
@rouri = nil
|
25
25
|
@rosrs = ROSRS::Session.new(Config.rosrs_api_uri, Config.authorization)
|
26
|
+
|
27
|
+
if VERSION < "1.9.1"
|
28
|
+
StringIO.class_eval do
|
29
|
+
def readpartial(*args)
|
30
|
+
result = read(*args)
|
31
|
+
if result.nil?
|
32
|
+
raise EOFError
|
33
|
+
else
|
34
|
+
result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
26
39
|
end
|
27
40
|
|
28
41
|
def teardown
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wf4ever-rosrs-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -150,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
segments:
|
152
152
|
- 0
|
153
|
-
hash: -
|
153
|
+
hash: -726066348641982817
|
154
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
155
|
none: false
|
156
156
|
requirements:
|