rdfobjects-pho 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +15 -0
- data/lib/rdf_objects/pho/rdf_resource.rb +105 -0
- data/lib/rdf_objects/pho/store.rb +108 -0
- data/lib/rdf_objects/pho.rb +10 -0
- metadata +99 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2007 Ross Singer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
RDFObjects/Pho integration.
|
2
|
+
|
3
|
+
Interact with Talis Platform stores using RDFObjects objects.
|
4
|
+
|
5
|
+
Usage:
|
6
|
+
|
7
|
+
>> require 'rdf_objects/pho'
|
8
|
+
>> store = RDFObject::Store.new('http://api.talis.com/store/storename', 'username', 'password')
|
9
|
+
>> response = store.describe('http://example.org/1')
|
10
|
+
|
11
|
+
Responses have two new attributes: collection and resource. Collection will always be set, resource will only be set when applicable (describe, search, etc.)
|
12
|
+
|
13
|
+
You can also pass RDFObject::Resource, RDFObject::BlankNode and RDFObject::Collection objects to Store#store_object, and Store#augment. You can pass an RDFObject::ChangeSet to Store#submit_changeset.
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class RDFObject::Resource
|
2
|
+
def to_rss
|
3
|
+
namespaces, rdf_data = self.rss_item_block
|
4
|
+
unless namespaces["xmlns:rdf"]
|
5
|
+
if x = namespaces.index("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
6
|
+
namespaces.delete(x)
|
7
|
+
end
|
8
|
+
namespaces["xmlns:rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
9
|
+
end
|
10
|
+
namespaces["xmlns"] = "http://purl.org/rss/1.0/"
|
11
|
+
uri = self.uri.sub(/#.*$/,".rss")
|
12
|
+
rdf = "<rdf:RDF"
|
13
|
+
namespaces.each_pair {|key, value| rdf << " #{key}=\"#{value}\""}
|
14
|
+
rdf <<">"
|
15
|
+
rdf << "<channel rdf:about=\"#{uri}\"><title>#{self.uri}</title><link>#{self.uri}</link>"
|
16
|
+
rdf << "<description>#{self.uri}</description><items><rdf:Seq><rdf:li resource=\"#{self.uri}\" /></rdf:Seq></items>"
|
17
|
+
rdf << "</channel>"
|
18
|
+
rdf << rdf_data
|
19
|
+
rdf << "</rdf:RDF>"
|
20
|
+
rdf
|
21
|
+
end
|
22
|
+
|
23
|
+
def rss_item_block
|
24
|
+
rdf = "<item #{xml_subject_attribute}>"
|
25
|
+
rdf << "<title>Item</title>"
|
26
|
+
rdf << "<link>#{self.uri}</link>"
|
27
|
+
namespaces = {}
|
28
|
+
Curie.get_mappings.each_pair do |key, value|
|
29
|
+
if self.respond_to?(key.to_sym)
|
30
|
+
self.send(key.to_sym).each_pair do | predicate, objects |
|
31
|
+
[*objects].each do | object |
|
32
|
+
rdf << "<#{key}:#{predicate}"
|
33
|
+
namespaces["xmlns:#{key}"] = "#{Curie.parse("[#{key}:]")}"
|
34
|
+
if object.is_a?(RDFObject::ResourceReference) || object.is_a?(RDFObject::BlankNode)
|
35
|
+
rdf << " #{object.xml_object_attribute} />"
|
36
|
+
else
|
37
|
+
if object.language
|
38
|
+
rdf << " xml:lang=\"#{object.language}\""
|
39
|
+
end
|
40
|
+
if object.datatype
|
41
|
+
rdf << " rdf:datatype=\"#{object.datatype}\""
|
42
|
+
end
|
43
|
+
rdf << ">#{CGI.escapeHTML(object.to_s)}</#{key}:#{predicate}>"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rdf << "</item>"
|
50
|
+
[namespaces, rdf]
|
51
|
+
end
|
52
|
+
|
53
|
+
def empty_graph?
|
54
|
+
Curie.get_mappings.each do | prefix, uri |
|
55
|
+
if self.respond_to?(prefix.to_sym)
|
56
|
+
if uri == "http://schemas.talis.com/2005/dir/schema#"
|
57
|
+
self["http://schemas.talis.com/2005/dir/schema#"].each_pair do |property, value|
|
58
|
+
next if property == 'etag'
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
else
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class RDFObject::Collection
|
71
|
+
def to_rss
|
72
|
+
uuid = ::UUID.generate
|
73
|
+
uri = "info:uuid/#{uuid}"
|
74
|
+
namespaces = {}
|
75
|
+
rdf_data = ""
|
76
|
+
self.values.each do |item|
|
77
|
+
ns, rss_data = item.rss_item_block
|
78
|
+
namespaces.merge!(ns)
|
79
|
+
rdf_data << rss_data
|
80
|
+
end
|
81
|
+
|
82
|
+
unless namespaces["xmlns:rdf"]
|
83
|
+
if x = namespaces.index("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
84
|
+
namespaces.delete(x)
|
85
|
+
end
|
86
|
+
namespaces["xmlns:rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
87
|
+
end
|
88
|
+
namespaces["xmlns"] = "http://purl.org/rss/1.0/"
|
89
|
+
rdf = "<rdf:RDF"
|
90
|
+
namespaces.each_pair {|key, value| rdf << " #{key}=\"#{value}\""}
|
91
|
+
rdf <<">"
|
92
|
+
rdf << "<channel rdf:about=\"#{uri}\"><title>RDFObject Collection</title><link>#{uri}</link>"
|
93
|
+
rdf << "<description>RDFOject Collection</description><items><rdf:Seq>"
|
94
|
+
self.keys.each do |uri|
|
95
|
+
rdf << "<rdf:li resource=\"#{uri}\" />"
|
96
|
+
end
|
97
|
+
rdf << "</rdf:Seq></items>"
|
98
|
+
rdf << "</channel>"
|
99
|
+
|
100
|
+
|
101
|
+
rdf << rdf_data
|
102
|
+
rdf << "</rdf:RDF>"
|
103
|
+
rdf
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module RDFObject
|
2
|
+
module StoreResponse
|
3
|
+
attr_accessor :collection, :resource
|
4
|
+
def parse_response
|
5
|
+
@collection = ::RDFObject::Parser.parse(body.content) unless body.content.empty? or status_code >= 300
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.extended(o)
|
9
|
+
o.parse_response
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Store < Pho::Store
|
14
|
+
|
15
|
+
def augment(data)
|
16
|
+
d = case data.class.name
|
17
|
+
when "String" then data
|
18
|
+
when "RDFObject::Resource" then data.to_rss
|
19
|
+
when "RDFObject::Collection" then data.to_rss
|
20
|
+
else raise ArgumentError, "Argument 'data' must be an RSS 1.0 formatted string, RDFObject::Resource or RDFObject::Collection"
|
21
|
+
end
|
22
|
+
response = super(d)
|
23
|
+
response.extend ::RDFObject::StoreResponse
|
24
|
+
search_resource = response.collection.find_by_predicate_and_object("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://purl.org/rss/1.0/channel")
|
25
|
+
search_resource.keys.each do |uri|
|
26
|
+
if uri =~ /http:\/\/api\.talis\.com\/stores/
|
27
|
+
response.resource = search_resource[uri]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
return response
|
31
|
+
end
|
32
|
+
|
33
|
+
def describe(uri, format="text/plain", etags=nil, if_match=false)
|
34
|
+
response = super(uri, format, etags, if_match)
|
35
|
+
response.extend ::RDFObject::StoreResponse
|
36
|
+
response.resource = response.collection[uri]
|
37
|
+
return response
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_field_predicate_map(output=::Pho::ACCEPT_JSON)
|
41
|
+
u = build_uri("/config/fpmaps/1")
|
42
|
+
response = super(output)
|
43
|
+
response.extend ::RDFObject::StoreResponse
|
44
|
+
response.resource = response.collection[u]
|
45
|
+
return response
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_job(uri)
|
49
|
+
response = super(uri)
|
50
|
+
response.extend ::RDFObject::StoreResponse
|
51
|
+
response.resource = response.collection[uri]
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_jobs
|
55
|
+
response = super
|
56
|
+
response.extend ::RDFObject::StoreResponse
|
57
|
+
response
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_query_profile(output=::Pho::ACCEPT_JSON)
|
61
|
+
response = super(output)
|
62
|
+
response.extend ::RDFObject::StoreResponse
|
63
|
+
response
|
64
|
+
end
|
65
|
+
|
66
|
+
def search(query, params=nil)
|
67
|
+
response = super(query, params)
|
68
|
+
response.extend ::RDFObject::StoreResponse
|
69
|
+
search_resource = response.collection.find_by_predicate_and_object("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://purl.org/rss/1.0/channel")
|
70
|
+
search_resource.keys.each do |uri|
|
71
|
+
if uri =~ /http:\/\/api\.talis\.com\/stores/
|
72
|
+
response.resource = search_resource[uri]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
return response
|
76
|
+
end
|
77
|
+
|
78
|
+
def sparql_construct(query, format="application/rdf+xml", multisparql=false)
|
79
|
+
response = super(query, format, multisparql)
|
80
|
+
response.extend ::RDFObject::StoreResponse
|
81
|
+
response
|
82
|
+
end
|
83
|
+
|
84
|
+
def sparql_describe(query, format="application/rdf+xml", multisparql=false)
|
85
|
+
response = super(query, format, multisparql)
|
86
|
+
response.extend ::RDFObject::StoreResponse
|
87
|
+
response
|
88
|
+
end
|
89
|
+
|
90
|
+
def store_object(rdf_object, depth=0, graph_name=nil)
|
91
|
+
unless rdf_object.is_a?(RDFObject::Node) || rdf_object.is_a?(RDFObject::Collection)
|
92
|
+
raise ArgumentError, "Argument must be a RDFObject::Node or RDFObject::Collection"
|
93
|
+
end
|
94
|
+
store_data(rdf_object.to_xml(depth), graph_name)
|
95
|
+
end
|
96
|
+
|
97
|
+
def submit_changeset(rdf, versioned=false, graph_name=nil)
|
98
|
+
unless rdf.is_a?(String) or rdf.is_a?(RDFObject::ChangeSet)
|
99
|
+
raise ArgumentError, "Argument 'rdf' must be a String or RDFObject::ChangeSet"
|
100
|
+
end
|
101
|
+
data = case rdf.class.name
|
102
|
+
when "String" then rdf
|
103
|
+
else rdf.to_xml
|
104
|
+
end
|
105
|
+
super(data, versioned, graph_name)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdfobjects-pho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ross Singer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-17 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rdfobjects
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rdfobjects-changeset
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: A bridge to more easily use RDFObjects with Pho.
|
50
|
+
email: rossfsinger@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- README
|
58
|
+
files:
|
59
|
+
- LICENSE
|
60
|
+
- README
|
61
|
+
- lib/rdf_objects/pho.rb
|
62
|
+
- lib/rdf_objects/pho/rdf_resource.rb
|
63
|
+
- lib/rdf_objects/pho/store.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/rsinger/rdfobjects-pho
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: RDFObjects/Pho integration.
|
98
|
+
test_files: []
|
99
|
+
|