metade-activerdf_reddy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,29 @@
1
+ == activerdf_reddy
2
+
3
+ An ActiveRDF adapter that uses Reddy (http://github.com/tommorris/reddy) for parsing RDF-XML.
4
+
5
+ * http://github.com/metade/activerdf_reddy
6
+
7
+ == LICENSE:
8
+
9
+ The MIT License
10
+
11
+ Copyright (c) 2008 Patrick Sinclair
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in
21
+ all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ task :default => [:spec]
4
+ task :spec do
5
+ sh "spec --colour spec"
6
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "activerdf_reddy"
3
+ s.version = "0.0.1"
4
+ s.date = "2008-10-22"
5
+ s.summary = "ActiveRDF RDFLite Reddy adapter"
6
+ s.email = "metade@gmail.com"
7
+ s.homepage = "http://github.com/metade/activerdf_reddy"
8
+ s.description = "An ActiveRDF RDFLite adapter based on Reddy, a Ruby RDF library"
9
+ s.has_rdoc = true
10
+ s.authors = ['Patrick Sinclair']
11
+ s.files = ["README", "Rakefile", "activerdf_reddy.gemspec", "lib/activerdf_reddy.rb"]
12
+ s.test_files = ["spec/activerdf_reddy_spec.rb"]
13
+ #s.rdoc_options = ["--main", "README.txt"]
14
+ #s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
15
+ s.add_dependency("reddy")
16
+ s.add_dependency("activerdf")
17
+ s.add_dependency("activerdf_rdflite")
18
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'active_rdf'
3
+ require 'reddy'
4
+
5
+ class ReddyAdapter < RDFLite
6
+ attr_reader :namespaces
7
+ ConnectionPool.register_adapter(:reddy, self)
8
+
9
+ def initialize(params = {})
10
+ super
11
+ @namespaces = {}
12
+ end
13
+
14
+ def fetch(uri)
15
+ # check if uri starts with http://
16
+ return unless uri.match(/http:\/\/(.*)/)
17
+
18
+ $activerdflog.debug "fetching from #{uri}"
19
+
20
+ url = URI.parse(uri)
21
+ found = false
22
+ until found
23
+ host, port = url.host, url.port if url.host && url.port
24
+ path = url.query.nil? ? url.path : "#{url.path}?#{url.query}"
25
+ req = Net::HTTP::Get.new(path, 'Accept' => 'application/rdf+xml')
26
+ res = Net::HTTP.start(host, port) {|http| http.request(req) }
27
+ res.header['location'] ? url = URI.parse(res.header['location']) : found = true
28
+ end
29
+
30
+ # TODO: make this generic
31
+ parser = Reddy::RdfXmlParser.new(res.body, uri)
32
+ triples = parser.graph.triples.map { |t| t.to_ntriples }
33
+ parser.xml.root.namespace.each { |n| @namespaces[n.prefix] = n.href }
34
+
35
+ context = RDFS::Resource.new(uri)
36
+ add_ntriples(triples, context)
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'lib/activerdf_reddy'
2
+
3
+ describe ReddyAdapter do
4
+ before(:each) do
5
+ @adapter = ReddyAdapter.new
6
+ end
7
+
8
+ it "should create a new reddy adapter" do
9
+ @adapter.should_not be_nil
10
+ end
11
+
12
+ describe 'fetching Programmes Ontology' do
13
+ before(:each) do
14
+ @adapter.fetch('http://purl.org/ontology/po/')
15
+ end
16
+
17
+ it "should have added some triples" do
18
+ @adapter.should have_at_least(1).items
19
+ end
20
+
21
+ it "should have set the namespaces" do
22
+ @adapter.namespaces['rdf'].should == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
23
+ @adapter.namespaces['rdfs'].should == 'http://www.w3.org/2000/01/rdf-schema#'
24
+ @adapter.namespaces['dc'].should == 'http://purl.org/dc/elements/1.1/'
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metade-activerdf_reddy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Sinclair
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-22 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: reddy
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: activerdf
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerdf_rdflite
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ description: An ActiveRDF RDFLite adapter based on Reddy, a Ruby RDF library
43
+ email: metade@gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files: []
49
+
50
+ files:
51
+ - README
52
+ - Rakefile
53
+ - activerdf_reddy.gemspec
54
+ - lib/activerdf_reddy.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/metade/activerdf_reddy
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.2.0
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: ActiveRDF RDFLite Reddy adapter
81
+ test_files:
82
+ - spec/activerdf_reddy_spec.rb