rdf-marmotta 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +23 -0
- data/lib/rdf/marmotta.rb +79 -0
- data/rdf-marmotta.gemspec +27 -0
- data/spec/marmotta_spec.rb +124 -0
- data/spec/spec_helper.rb +15 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca8d084b6dd3a1127eace872b52c7b6ca941b766
|
4
|
+
data.tar.gz: 22b92c906a5e092328e735fa60b8b00f3963b7c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a15e863ab6c6af68a43c7ff133fa608bfe45159ebdbb7d82665b2a5e4a346483e05c504275314d79dc9a84f9c58efe928cae6e28708ac8cd05d6d3733739adc8
|
7
|
+
data.tar.gz: 309eba551ec09d8b647476d3d9daf0615afca7ccc663633a08189b6e6dd4f07f1219234bcbcd611456da2defbf80ba52dca8792c8a32abbb1f2203184b0006d8
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
RDF::Marmotta
|
2
|
+
=============
|
3
|
+
|
4
|
+
A Ruby RDF::Repository implementation for Apache Marmotta.
|
5
|
+
|
6
|
+
Installing & Using
|
7
|
+
------------------
|
8
|
+
|
9
|
+
Add `gem rdf-marmotta` to `Gemfile` and run:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
To use, `require rdf/marmotta` and initialize a repository with
|
16
|
+
`RDF::Marmotta.new('http://path.to/marmotta_base')`.
|
17
|
+
|
18
|
+
NOTE: WIP
|
19
|
+
---------
|
20
|
+
|
21
|
+
This software implements simple RDF::Repository functionality, but is
|
22
|
+
likely riddled with problems and non-performant. Don't point it at a
|
23
|
+
datastore you care about.
|
data/lib/rdf/marmotta.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'rdf/rdfxml'
|
3
|
+
require 'sparql/client'
|
4
|
+
require 'enumerator'
|
5
|
+
|
6
|
+
module RDF
|
7
|
+
class Marmotta < ::RDF::Repository
|
8
|
+
|
9
|
+
attr_accessor :endpoints
|
10
|
+
|
11
|
+
DEFAULT_OPTIONS = {
|
12
|
+
:sparql => 'sparql/select',
|
13
|
+
:sparql_update => 'sparql/update',
|
14
|
+
:ldpath => 'ldpath'
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(base_url, options = {})
|
18
|
+
@endpoints = DEFAULT_OPTIONS
|
19
|
+
@endpoints.merge!(options)
|
20
|
+
@endpoints.each do |k, v|
|
21
|
+
@endpoints[k] = URI(base_url.to_s + v.to_s) unless v.is_a? ::URI
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_client
|
26
|
+
@query_client ||= Client.new(endpoints[:sparql])
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_client
|
30
|
+
@update_client ||= Client.new(endpoints[:sparql_update])
|
31
|
+
end
|
32
|
+
|
33
|
+
# @see RDF::Enumerable#each.
|
34
|
+
def each(&block)
|
35
|
+
query_client.construct([:s, :p, :o]).where([:s, :p, :o]).each_statement(&block)
|
36
|
+
end
|
37
|
+
|
38
|
+
# @see RDF::Mutable#insert_statement
|
39
|
+
def insert_statement(statement)
|
40
|
+
insert_statements([statement])
|
41
|
+
end
|
42
|
+
|
43
|
+
def insert_statements(statements)
|
44
|
+
update_client.insert_data(statements)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @see RDF::Mutable#delete_statement
|
48
|
+
def delete_statement(statement)
|
49
|
+
delete_statements([statement])
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_statements(statements)
|
53
|
+
constant = statements.all? do |value|
|
54
|
+
!value.respond_to?(:each_statement) && begin
|
55
|
+
statement = RDF::Statement.from(value)
|
56
|
+
statement.constant? && !statement.has_blank_nodes?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if constant
|
61
|
+
update_client.delete_data(statements)
|
62
|
+
else
|
63
|
+
update_client.delete_insert(statements)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def clear
|
68
|
+
update_client.query("DELETE { ?s ?p ?o } WHERE { ?s ?p ?o }")
|
69
|
+
end
|
70
|
+
|
71
|
+
class Client < SPARQL::Client
|
72
|
+
def initialize(url, options = {}, &block)
|
73
|
+
options[:method] ||= :get
|
74
|
+
options[:protocol] ||= '1.1'
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rdf-marmotta"
|
6
|
+
s.version = '0.0.4'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Tom Johnson"]
|
9
|
+
s.homepage = 'https://github.com/dpla/rdf-marmotta'
|
10
|
+
s.email = 'tom@dp.la'
|
11
|
+
s.summary = %q{RDF::Repository layer for Apache Marmotta.}
|
12
|
+
s.description = %q{RDF::Repository layer for Apache Marmotta.}
|
13
|
+
s.license = "undeclared"
|
14
|
+
s.required_ruby_version = '>= 1.9.3'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
|
19
|
+
s.add_dependency('rdf', '~> 1.1')
|
20
|
+
s.add_dependency('nokogiri')
|
21
|
+
s.add_dependency('rdf-rdfxml', '~> 1.1')
|
22
|
+
s.add_dependency('sparql-client', '~> 1.1')
|
23
|
+
s.add_development_dependency('rspec')
|
24
|
+
s.add_development_dependency('rspec-its')
|
25
|
+
s.add_development_dependency('rdf-spec')
|
26
|
+
s.add_development_dependency('pry')
|
27
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
$:.unshift File.dirname(__FILE__) + "/../lib/"
|
4
|
+
|
5
|
+
require 'rdf'
|
6
|
+
require 'rdf/spec/repository'
|
7
|
+
require 'rdf/marmotta'
|
8
|
+
|
9
|
+
describe RDF::Marmotta do
|
10
|
+
|
11
|
+
let(:base_url) { 'http://localhost:8080/marmotta/' }
|
12
|
+
let(:opts) { {} }
|
13
|
+
let(:statement) { RDF::Statement(RDF::URI('http://api.dp.la/example/item/1234'), RDF::DC.title, 'Moomin') }
|
14
|
+
let(:statements) {
|
15
|
+
nodes = [RDF::Node.new, RDF::Node.new, RDF::Node.new]
|
16
|
+
[
|
17
|
+
RDF::Statement(RDF::URI('http://dbpedia.org/resource/Moomin'), RDF::URI('http://dbpedia.org/ontology/author'), RDF::URI('http://dbpedia.org/resource/Tove_Jansson')),
|
18
|
+
RDF::Statement(RDF::URI('http://dbpedia.org/resource/Moomin'), RDF::URI('http://dbpedia.org/ontology/country'), RDF::URI('http://dbpedia.org/resource/Finland')),
|
19
|
+
RDF::Statement(RDF::URI('http://dbpedia.org/resource/Moomin'), RDF::URI('http://dbpedia.org/ontology/country'), RDF::URI('http://dbpedia.org/resource/Finland')),
|
20
|
+
RDF::Statement(RDF::URI('http://dbpedia.org/resource/Moomin'), RDF::URI('http://dbpedia.org/ontology/illustrator'), RDF::URI('http://dbpedia.org/resource/Tove_Jansson')),
|
21
|
+
RDF::Statement(RDF::URI('http://dbpedia.org/resource/Moomin'), RDF::URI('http://dbpedia.org/ontology/abstract'), RDF::Literal.new("Muminki (szw. Mumintroll, fiń. Muumi) – fikcyjne istoty o antropomorficznej budowie ciała (nieco podobne do hipopotamów, ale dwunożne), zamieszkujące pewną dolinę gdzieś w Finlandii, bohaterowie cyklu dziewięciu książek fińskiej (piszącej po szwedzku) pisarki Tove Jansson. Są one odmianą trolli. Pierwsza książka o Muminkach, Małe trolle i duża powódź, została opublikowana przez Tove Jansson w 1945 (pierwsza wersja powstała już zimą 1939 roku).Wszystkie książki o Muminkach odniosły sukces: zostały przełożone na ponad trzydzieści języków. Muminki doczekały się też swojej wersji teatralnej, filmowej (między innymi serial zrealizowany w Polsce w Studio Małych Form Filmowych Se-ma-for), radiowej, telewizyjnej i komiksowej. Świat, w którym żyją Muminki, pełen jest rozmaitych stworzeń – żyją w nim Paszczaki, Hatifnatowie, Mimble – każde z nich ma swój punkt widzenia na świat, swój charakter i temperament.W Tampere, trzecim co do wielkości fińskim mieście, mieści się Muzeum „Dolina Muminków”. Natomiast w Naantali, miejscowości położonej niedaleko Turku, powstał park rozrywki \"Dolina Muminków\".", :language => 'pl')),
|
22
|
+
RDF::Statement(RDF::URI('http://dbpedia.org/resource/Moomin'), RDF::DC.relation, nodes[0]),
|
23
|
+
RDF::Statement(nodes[0], RDF::DC.title, "Comet in Moominland"),
|
24
|
+
RDF::Statement(nodes[0], RDF::DC.subject, nodes[1]),
|
25
|
+
RDF::Statement(nodes[1], RDF::SKOS.prefLabel, 'Moomin Valley'),
|
26
|
+
RDF::Statement(nodes[0], RDF::DC.subject, nodes[2]),
|
27
|
+
RDF::Statement(nodes[2], RDF::SKOS.prefLabel, 'Astronomical Events (apocryphal)')
|
28
|
+
]
|
29
|
+
}
|
30
|
+
|
31
|
+
subject { RDF::Marmotta.new(base_url, opts) }
|
32
|
+
|
33
|
+
after do
|
34
|
+
subject.clear
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'initializing' do
|
38
|
+
describe 'webservice endpoints' do
|
39
|
+
it 'has sparql endpoint' do
|
40
|
+
expect(subject.query_client).to be_a SPARQL::Client
|
41
|
+
expect(subject.update_client).to be_a SPARQL::Client
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# We probably want to pursue skolemization and/or talk to Marmotta
|
48
|
+
# folks about how they currently/should handle bnodes.
|
49
|
+
describe 'bnode handling' do
|
50
|
+
|
51
|
+
let(:node_triple) { RDF::Statement(RDF::Node.new, RDF::DC.title, 'Moomin') }
|
52
|
+
|
53
|
+
xit 'deletes only the relevant bnode' do
|
54
|
+
subject << node_triple
|
55
|
+
subject << [RDF::Node.new, RDF::DC.title, 'Moomin']
|
56
|
+
subject << [RDF::Node.new, RDF::DC.title, 'Moomin']
|
57
|
+
subject.delete_statement(node_triple)
|
58
|
+
expect(subject.count).to eq 2 # returns 0
|
59
|
+
end
|
60
|
+
|
61
|
+
xit 'identifies triples with bnodes as existing' do
|
62
|
+
subject << node_triple
|
63
|
+
expect(subject).to have_triple node_triple # returns false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'inserting' do
|
68
|
+
before do
|
69
|
+
subject << statement
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'writes values' do
|
73
|
+
expect(subject.count).to eq 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'writes correct values' do
|
77
|
+
expect(subject).to have_triple statement
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# This tests an issue that may be an upstream Marmotta problem
|
82
|
+
xit 'handles large inserts (marmotta)' do
|
83
|
+
expect { subject.insert_statements(statements) }.not_to raise_error
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# This tests an issue that may be an upstream RDF.rb problem
|
88
|
+
xit 'handles large inserts (rdf.rb)' do
|
89
|
+
expect { subject << statements }.not_to raise_error
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'deleting' do
|
94
|
+
|
95
|
+
it 'delete triples' do
|
96
|
+
subject.delete(statement)
|
97
|
+
expect(subject.count).to eq 0
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# This tests an issue that may be an upstream Marmotta problem.
|
102
|
+
# It may be the same issue as above. Could be same issue as above,
|
103
|
+
# or at least related.
|
104
|
+
xit 'deletes triples even when some are not in store' do
|
105
|
+
statement.object = RDF::Literal('Moominpapa')
|
106
|
+
subject << statement
|
107
|
+
subject.delete_statements(statements)
|
108
|
+
expect(subject.count).to eq 0
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
# describe 'Repository' do
|
114
|
+
# before do
|
115
|
+
# @repository = subject
|
116
|
+
# end
|
117
|
+
|
118
|
+
# after do
|
119
|
+
# @repository.clear
|
120
|
+
# end
|
121
|
+
|
122
|
+
# include RDF_Repository
|
123
|
+
# end
|
124
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.color = true
|
8
|
+
config.tty = true
|
9
|
+
|
10
|
+
# Uncomment the following line to get errors and backtrace for deprecation warnings
|
11
|
+
# config.raise_errors_for_deprecations!
|
12
|
+
|
13
|
+
# Use the specified formatter
|
14
|
+
config.formatter = :progress
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-marmotta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Johnson
|
@@ -127,7 +127,13 @@ email: tom@dp.la
|
|
127
127
|
executables: []
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
|
-
files:
|
130
|
+
files:
|
131
|
+
- Gemfile
|
132
|
+
- README.md
|
133
|
+
- lib/rdf/marmotta.rb
|
134
|
+
- rdf-marmotta.gemspec
|
135
|
+
- spec/marmotta_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
131
137
|
homepage: https://github.com/dpla/rdf-marmotta
|
132
138
|
licenses:
|
133
139
|
- undeclared
|