ld4l-works_rdf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +25 -0
- data/.travis.yml +14 -0
- data/CHANGES.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +170 -0
- data/Rakefile +2 -0
- data/ld4l-works_rdf.gemspec +42 -0
- data/lib/ld4l/works_rdf.rb +131 -0
- data/lib/ld4l/works_rdf/configuration.rb +41 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_identifier.rb +17 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_instance.rb +23 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_organization.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_person.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_place.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_provider.rb +18 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_title.rb +18 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_work.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibo/bibo_book.rb +19 -0
- data/lib/ld4l/works_rdf/models/bibo/bibo_document.rb +14 -0
- data/lib/ld4l/works_rdf/models/bibo/vivo_authorship.rb +15 -0
- data/lib/ld4l/works_rdf/models/bibo/vivo_book.rb +18 -0
- data/lib/ld4l/works_rdf/models/generic_work.rb +13 -0
- data/lib/ld4l/works_rdf/models/schema/oclc_schema_book.rb +16 -0
- data/lib/ld4l/works_rdf/models/schema/schema_book.rb +23 -0
- data/lib/ld4l/works_rdf/models/schema/schema_person.rb +17 -0
- data/lib/ld4l/works_rdf/models/schema/schema_publisher.rb +15 -0
- data/lib/ld4l/works_rdf/models/work_metadata.rb +212 -0
- data/lib/ld4l/works_rdf/services/attempt_generic_metadata_extraction.rb +41 -0
- data/lib/ld4l/works_rdf/services/conversion_services/get_rdfxml_from_marcxml.rb +44 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.ErrorCodes.xqy +56 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXML-2-MADSRDF.xqy +1702 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXML-2-RecordInfoRDF.xqy +216 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXMLBIB-2-BIBFRAME.xqy +140 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXMLBIB-BFUtils.xqy +3287 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-2-BIBFRAME-Shared.xqy +4112 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-Default-2-BF.xqy +61 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-NotatedMusic-2-BF.xqy +105 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-ExhibitJSON.xqy +119 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-JSON.xqy +193 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-Ntriples.xqy +276 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXMLnested-2-flat.xqy +380 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/ml.xqy +239 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/saxon.xqy +134 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba.xqy +359 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba2-0.xqy +249 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba3-0.xqy +362 -0
- data/lib/ld4l/works_rdf/services/conversion_services/saxon/saxon9he.jar +0 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_marcxml_uri.rb +43 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_oclc_uri.rb +25 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_solr_query.rb +29 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_vivo_uri.rb +25 -0
- data/lib/ld4l/works_rdf/services/get_model_from_uri.rb +62 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_bibframe_models.rb +60 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_bibo_model.rb +42 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_generic_model.rb +41 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_oclc_model.rb +42 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb +67 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_vivo_model.rb +45 -0
- data/lib/ld4l/works_rdf/services/metadata_services/set_error_in_metadata.rb +27 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_bibframe_models_from_repository.rb +46 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_generic_model_from_repository.rb +30 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_oclc_model_from_repository.rb +27 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_vivo_model_from_repository.rb +27 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_marcxml_from_uri.rb +35 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_rdfxml_from_uri.rb +37 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_solr_results_from_solr_query.rb +35 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_turtle_from_uri.rb +37 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/response_header.rb +51 -0
- data/lib/ld4l/works_rdf/services/repository_services/populate_graph_from_rdfxml.rb +22 -0
- data/lib/ld4l/works_rdf/services/repository_services/populate_graph_from_turtle.rb +21 -0
- data/lib/ld4l/works_rdf/services/repository_services/populate_repository_from_graph.rb +25 -0
- data/lib/ld4l/works_rdf/version.rb +5 -0
- data/lib/ld4l/works_rdf/vocab/bf.rb +29 -0
- data/lib/ld4l/works_rdf/vocab/bgn.rb +5 -0
- data/lib/ld4l/works_rdf/vocab/bibo.rb +10 -0
- data/lib/ld4l/works_rdf/vocab/library.rb +6 -0
- data/lib/ld4l/works_rdf/vocab/vitro.rb +5 -0
- data/lib/ld4l/works_rdf/vocab/vivo.rb +11 -0
- data/spec/ld4l/works_rdf/configuration_spec.rb +166 -0
- data/spec/ld4l/works_rdf/models/books/vivo_book_rdf_spec.rb +267 -0
- data/spec/ld4l/works_rdf/services/get_metadata_from_uri_spec.rb +39 -0
- data/spec/ld4l/works_rdf/services/get_model_from_uri_spec.rb +34 -0
- data/spec/ld4l/works_rdf_spec.rb +53 -0
- data/spec/spec_helper.rb +26 -0
- metadata +321 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class PopulateRepositoryFromGraph
|
4
|
+
|
5
|
+
##
|
6
|
+
# Create an RDF::Repository populated from an RDF::Graph.
|
7
|
+
#
|
8
|
+
# @param [RDF::Graph] instance of RDF::Graph
|
9
|
+
#
|
10
|
+
# @returns a populated instance of repository holding triples from the passed in graph
|
11
|
+
def self.call( graph )
|
12
|
+
raise ArgumentError, 'graph argument must an instance of RDF::Graph' unless
|
13
|
+
graph.kind_of?(RDF::Graph)
|
14
|
+
|
15
|
+
repo_name = SecureRandom.uuid.to_sym
|
16
|
+
# r = RDF::Repository.new
|
17
|
+
r = ActiveTriples::Repositories.add_repository repo_name, RDF::Repository.new
|
18
|
+
r << graph
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RDFVocabularies
|
2
|
+
class BF < RDF::Vocabulary("http://bibframe.org/vocab/")
|
3
|
+
term :Work
|
4
|
+
term :Instance
|
5
|
+
term :Identifier
|
6
|
+
term :Organization
|
7
|
+
term :Place
|
8
|
+
term :Provider
|
9
|
+
term :Title
|
10
|
+
|
11
|
+
property :identifierScheme
|
12
|
+
property :identifierValue
|
13
|
+
property :instanceOf
|
14
|
+
property :instanceTitle
|
15
|
+
property :systemNumber
|
16
|
+
property :publication
|
17
|
+
property :providerStatement
|
18
|
+
property :copyrightDate
|
19
|
+
property :edition
|
20
|
+
property :label
|
21
|
+
property :providerDate
|
22
|
+
property :providerName
|
23
|
+
property :providerPlace
|
24
|
+
property :titleStatement
|
25
|
+
property :titleValue
|
26
|
+
property :subtitle
|
27
|
+
property :creator
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::WorksRDF' do
|
4
|
+
|
5
|
+
describe '#configuration' do
|
6
|
+
describe "base_uri" do
|
7
|
+
context "when base_uri is not configured" do
|
8
|
+
before do
|
9
|
+
class DummyWork < LD4L::WorksRDF::VivoBook
|
10
|
+
configure :type => RDFVocabularies::VIVO.Book, :base_uri => LD4L::WorksRDF.configuration.base_uri, :repository => :default
|
11
|
+
end
|
12
|
+
end
|
13
|
+
after do
|
14
|
+
Object.send(:remove_const, "DummyWork") if Object
|
15
|
+
end
|
16
|
+
it "should generate a Person URI using the default base_uri" do
|
17
|
+
expect(DummyWork.new('1').rdf_subject.to_s).to eq "http://localhost/1"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when uri ends with slash" do
|
22
|
+
before do
|
23
|
+
LD4L::WorksRDF.configure do |config|
|
24
|
+
config.base_uri = "http://localhost/test_slash/"
|
25
|
+
end
|
26
|
+
class DummyWork < LD4L::WorksRDF::VivoBook
|
27
|
+
configure :type => RDFVocabularies::VIVO.Book, :base_uri => LD4L::WorksRDF.configuration.base_uri, :repository => :default
|
28
|
+
end
|
29
|
+
end
|
30
|
+
after do
|
31
|
+
Object.send(:remove_const, "DummyWork") if Object
|
32
|
+
LD4L::WorksRDF.reset
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should generate a Person URI using the configured base_uri" do
|
36
|
+
expect(DummyWork.new('1').rdf_subject.to_s).to eq "http://localhost/test_slash/1"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when uri does not end with slash" do
|
41
|
+
before do
|
42
|
+
LD4L::WorksRDF.configure do |config|
|
43
|
+
config.base_uri = "http://localhost/test_no_slash"
|
44
|
+
end
|
45
|
+
class DummyWork < LD4L::WorksRDF::VivoBook
|
46
|
+
configure :type => RDFVocabularies::VIVO.Book, :base_uri => LD4L::WorksRDF.configuration.base_uri, :repository => :default
|
47
|
+
end
|
48
|
+
end
|
49
|
+
after do
|
50
|
+
Object.send(:remove_const, "DummyWork") if Object
|
51
|
+
LD4L::WorksRDF.reset
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should generate a Person URI using the configured base_uri" do
|
55
|
+
expect(DummyWork.new('1').rdf_subject.to_s).to eq "http://localhost/test_no_slash/1"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return value of configured base_uri" do
|
60
|
+
LD4L::WorksRDF.configure do |config|
|
61
|
+
config.base_uri = "http://localhost/test_config/"
|
62
|
+
end
|
63
|
+
expect(LD4L::WorksRDF.configuration.base_uri).to eq "http://localhost/test_config/"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return default base_uri when base_uri is reset" do
|
67
|
+
LD4L::WorksRDF.configure do |config|
|
68
|
+
config.base_uri = "http://localhost/test_config/"
|
69
|
+
end
|
70
|
+
expect(LD4L::WorksRDF.configuration.base_uri).to eq "http://localhost/test_config/"
|
71
|
+
LD4L::WorksRDF.configuration.reset_base_uri
|
72
|
+
expect(LD4L::WorksRDF.configuration.base_uri).to eq "http://localhost/"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return default base_uri when all configs are reset" do
|
76
|
+
LD4L::WorksRDF.configure do |config|
|
77
|
+
config.base_uri = "http://localhost/test_config/"
|
78
|
+
end
|
79
|
+
expect(LD4L::WorksRDF.configuration.base_uri).to eq "http://localhost/test_config/"
|
80
|
+
LD4L::WorksRDF.reset
|
81
|
+
expect(LD4L::WorksRDF.configuration.base_uri).to eq "http://localhost/"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "localname_minter" do
|
86
|
+
context "when minter is nil" do
|
87
|
+
it "should use default minter in minter gem" do
|
88
|
+
localname = ActiveTriples::LocalName::Minter.generate_local_name(
|
89
|
+
LD4L::WorksRDF::VivoBook, 10, {:prefix=>'default_'},
|
90
|
+
LD4L::WorksRDF.configuration.localname_minter )
|
91
|
+
expect(localname).to be_kind_of String
|
92
|
+
expect(localname.size).to eq 44
|
93
|
+
expect(localname).to match /default_[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when minter is configured" do
|
98
|
+
before do
|
99
|
+
LD4L::WorksRDF.configure do |config|
|
100
|
+
config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
|
101
|
+
end
|
102
|
+
class DummyWork < LD4L::WorksRDF::VivoBook
|
103
|
+
configure :type => RDFVocabularies::VIVO.Book, :base_uri => LD4L::WorksRDF.configuration.base_uri, :repository => :default
|
104
|
+
end
|
105
|
+
end
|
106
|
+
after do
|
107
|
+
Object.send(:remove_const, "DummyWork") if Object
|
108
|
+
LD4L::WorksRDF.reset
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should generate an Person URI using the configured localname_minter" do
|
112
|
+
localname = ActiveTriples::LocalName::Minter.generate_local_name(
|
113
|
+
LD4L::WorksRDF::VivoBook, 10,
|
114
|
+
LD4L::WorksRDF::VivoBook.localname_prefix,
|
115
|
+
&LD4L::WorksRDF.configuration.localname_minter )
|
116
|
+
expect(localname).to be_kind_of String
|
117
|
+
expect(localname.size).to eq 49
|
118
|
+
expect(localname).to match /w_configured_[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
describe "LD4L::WorksRDF::Configuration" do
|
126
|
+
describe "#base_uri" do
|
127
|
+
it "should default to localhost" do
|
128
|
+
expect(LD4L::WorksRDF::Configuration.new.base_uri).to eq "http://localhost/"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should be settable" do
|
132
|
+
config = LD4L::WorksRDF::Configuration.new
|
133
|
+
config.base_uri = "http://localhost/test"
|
134
|
+
expect(config.base_uri).to eq "http://localhost/test"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should be re-settable" do
|
138
|
+
config = LD4L::WorksRDF::Configuration.new
|
139
|
+
config.base_uri = "http://localhost/test/again"
|
140
|
+
expect(config.base_uri).to eq "http://localhost/test/again"
|
141
|
+
config.reset_base_uri
|
142
|
+
expect(config.base_uri).to eq "http://localhost/"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#localname_minter" do
|
147
|
+
it "should default to nil" do
|
148
|
+
expect(LD4L::WorksRDF::Configuration.new.localname_minter).to eq nil
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should be settable" do
|
152
|
+
config = LD4L::WorksRDF::Configuration.new
|
153
|
+
config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
|
154
|
+
expect(config.localname_minter).to be_kind_of Proc
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should be re-settable" do
|
158
|
+
config = LD4L::WorksRDF::Configuration.new
|
159
|
+
config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
|
160
|
+
expect(config.localname_minter).to be_kind_of Proc
|
161
|
+
config.reset_localname_minter
|
162
|
+
expect(config.localname_minter).to eq nil
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LD4L::WorksRDF::VivoBook' do
|
4
|
+
# it_behaves_like 'an ActiveTriple::Resource'
|
5
|
+
|
6
|
+
subject { LD4L::WorksRDF::VivoBook.new } # new virtual collection without a subject
|
7
|
+
|
8
|
+
describe 'rdf_subject' do
|
9
|
+
it "should be a blank node if we haven't set it" do
|
10
|
+
expect(subject.rdf_subject.node?).to be true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be settable when it has not been set yet" do
|
14
|
+
subject.set_subject! RDF::URI('http://example.org/moomin')
|
15
|
+
expect(subject.rdf_subject).to eq RDF::URI('http://example.org/moomin')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should append to base URI when setting to non-URI subject" do
|
19
|
+
subject.set_subject! '123'
|
20
|
+
expect(subject.rdf_subject).to eq RDF::URI("#{LD4L::WorksRDF::VivoBook.base_uri}123")
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'when changing subject' do
|
24
|
+
before do
|
25
|
+
subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland'))
|
26
|
+
subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject)
|
27
|
+
subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land')
|
28
|
+
subject.set_subject! RDF::URI('http://example.org/moomin')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should update graph subjects' do
|
32
|
+
expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should update graph objects' do
|
36
|
+
expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should leave other uris alone' do
|
40
|
+
expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'created with URI subject' do
|
45
|
+
before do
|
46
|
+
subject.set_subject! RDF::URI('http://example.org/moomin')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should not be settable' do
|
50
|
+
expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }.to raise_error
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# -------------------------------------------------
|
57
|
+
# START -- Test attributes specific to this model
|
58
|
+
# -------------------------------------------------
|
59
|
+
|
60
|
+
describe 'type' do
|
61
|
+
it "should be an RDFVocabularies::BIBO.Book" do
|
62
|
+
expect(subject.type.first.value).to eq RDFVocabularies::VIVO.Book.value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#localname_prefix' do
|
67
|
+
it "should return default prefix" do
|
68
|
+
prefix = LD4L::WorksRDF::VivoBook.localname_prefix
|
69
|
+
expect(prefix).to eq "w"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# -----------------------------------------------
|
74
|
+
# END -- Test attributes specific to this model
|
75
|
+
# -----------------------------------------------
|
76
|
+
|
77
|
+
|
78
|
+
describe "#persisted?" do
|
79
|
+
context 'with a repository' do
|
80
|
+
before do
|
81
|
+
# Create inmemory repository
|
82
|
+
repository = RDF::Repository.new
|
83
|
+
allow(subject).to receive(:repository).and_return(repository)
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when the object is new" do
|
87
|
+
it "should return false" do
|
88
|
+
expect(subject).not_to be_persisted
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when it is saved" do
|
93
|
+
before do
|
94
|
+
subject.persist!
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return true" do
|
98
|
+
expect(subject).to be_persisted
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#persist!" do
|
105
|
+
context "when the repository is set" do
|
106
|
+
context "and the item is not a blank node" do
|
107
|
+
|
108
|
+
subject {LD4L::WorksRDF::VivoBook.new("123")}
|
109
|
+
let(:result) { subject.persist! }
|
110
|
+
|
111
|
+
before do
|
112
|
+
# Create inmemory repository
|
113
|
+
@repo = RDF::Repository.new
|
114
|
+
ActiveTriples::Repositories.repositories[:default] = @repo
|
115
|
+
subject.place_of_publication = "NY"
|
116
|
+
result
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return true" do
|
120
|
+
expect(result).to eq true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should persist to the repository" do
|
124
|
+
expect(@repo.statements.first).to eq subject.statements.first
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should delete from the repository" do
|
128
|
+
subject.reload
|
129
|
+
expect(subject.place_of_publication.first).to eq "NY"
|
130
|
+
subject.place_of_publication = []
|
131
|
+
expect(subject.place_of_publication).to eq []
|
132
|
+
subject.persist!
|
133
|
+
subject.reload
|
134
|
+
expect(@repo.statements.to_a.length).to eq 1 # Only the type statement
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#destroy!' do
|
141
|
+
before do
|
142
|
+
subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE')
|
143
|
+
end
|
144
|
+
|
145
|
+
subject { LD4L::WorksRDF::VivoBook.new('456')}
|
146
|
+
|
147
|
+
it 'should return true' do
|
148
|
+
expect(subject.destroy!).to be true
|
149
|
+
expect(subject.destroy).to be true
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should delete the graph' do
|
153
|
+
subject.destroy
|
154
|
+
expect(subject).to be_empty
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#type' do
|
159
|
+
it 'should return the type configured on the parent class' do
|
160
|
+
expected_result = LD4L::WorksRDF::VivoBook.type.kind_of?(Array) ? LD4L::WorksRDF::VivoBook.type : [LD4L::WorksRDF::VivoBook.type]
|
161
|
+
expect(subject.type).to eq expected_result
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should set the type' do
|
165
|
+
subject.type = RDF::URI('http://example.org/AnotherClass')
|
166
|
+
expect(subject.type).to eq [RDF::URI('http://example.org/AnotherClass')]
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should be the type in the graph' do
|
170
|
+
subject.query(:subject => subject.rdf_subject, :predicate => RDF.type).statements do |s|
|
171
|
+
expect(s.object).to eq RDF::URI('http://example.org/AnotherClass')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#rdf_label' do
|
177
|
+
subject {LD4L::WorksRDF::VivoBook.new("123")}
|
178
|
+
|
179
|
+
it 'should return an array of label values' do
|
180
|
+
expect(subject.rdf_label).to be_kind_of Array
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should return the default label as URI when no title property exists' do
|
184
|
+
expect(subject.rdf_label).to eq ["#{LD4L::WorksRDF::VivoBook.base_uri}123"]
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should prioritize configured label values' do
|
188
|
+
custom_label = RDF::URI('http://example.org/custom_label')
|
189
|
+
subject.class.configure :rdf_label => custom_label
|
190
|
+
subject << RDF::Statement(subject.rdf_subject, custom_label, RDF::Literal('New Label'))
|
191
|
+
expect(subject.rdf_label).to eq ['New Label']
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'big complex graphs' do
|
196
|
+
before do
|
197
|
+
class DummyPerson < ActiveTriples::Resource
|
198
|
+
configure :type => RDF::URI('http://example.org/Person')
|
199
|
+
property :foafname, :predicate => RDF::FOAF.name
|
200
|
+
property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
|
201
|
+
property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
|
202
|
+
end
|
203
|
+
|
204
|
+
class DummyDocument < ActiveTriples::Resource
|
205
|
+
configure :type => RDF::URI('http://example.org/Document')
|
206
|
+
property :title, :predicate => RDF::DC.title
|
207
|
+
property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson'
|
208
|
+
end
|
209
|
+
|
210
|
+
LD4L::WorksRDF::VivoBook.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument
|
211
|
+
end
|
212
|
+
|
213
|
+
subject { LD4L::WorksRDF::VivoBook.new }
|
214
|
+
|
215
|
+
let (:document1) do
|
216
|
+
d = DummyDocument.new
|
217
|
+
d.title = 'Document One'
|
218
|
+
d
|
219
|
+
end
|
220
|
+
|
221
|
+
let (:document2) do
|
222
|
+
d = DummyDocument.new
|
223
|
+
d.title = 'Document Two'
|
224
|
+
d
|
225
|
+
end
|
226
|
+
|
227
|
+
let (:person1) do
|
228
|
+
p = DummyPerson.new
|
229
|
+
p.foafname = 'Alice'
|
230
|
+
p
|
231
|
+
end
|
232
|
+
|
233
|
+
let (:person2) do
|
234
|
+
p = DummyPerson.new
|
235
|
+
p.foafname = 'Bob'
|
236
|
+
p
|
237
|
+
end
|
238
|
+
|
239
|
+
let (:data) { <<END
|
240
|
+
_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeClass> .
|
241
|
+
_:1 <http://purl.org/dc/terms/relation> _:2 .
|
242
|
+
_:2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Document> .
|
243
|
+
_:2 <http://purl.org/dc/terms/title> "Document One" .
|
244
|
+
_:2 <http://purl.org/dc/terms/creator> _:3 .
|
245
|
+
_:2 <http://purl.org/dc/terms/creator> _:4 .
|
246
|
+
_:4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
|
247
|
+
_:4 <http://xmlns.com/foaf/0.1/name> "Bob" .
|
248
|
+
_:3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
|
249
|
+
_:3 <http://xmlns.com/foaf/0.1/name> "Alice" .
|
250
|
+
_:3 <http://xmlns.com/foaf/0.1/knows> _:4 ."
|
251
|
+
END
|
252
|
+
}
|
253
|
+
|
254
|
+
after do
|
255
|
+
Object.send(:remove_const, "DummyDocument")
|
256
|
+
Object.send(:remove_const, "DummyPerson")
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'should allow access to deep nodes' do
|
260
|
+
document1.creator = [person1, person2]
|
261
|
+
document2.creator = person1
|
262
|
+
person1.knows = person2
|
263
|
+
subject.item = [document1]
|
264
|
+
expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob']
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|