ld4l-foaf_rdf 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37e6858b4b5355b65a2e3157a2db5f280ff586fe
4
+ data.tar.gz: bc856fe13754c5bf584773d7d4a1a905c95fc892
5
+ SHA512:
6
+ metadata.gz: c36fae03f1eef58e1270f7aedb48592904108d07c32c712394ab0766ea8685b46bb06fd8ec8a2f2d26e858d586db6dfe1418849b0fb295c1c0855f5ae07c4cfb
7
+ data.tar.gz: cc03aa43c5c8981576eafa823fcad3dda079514c719ed871ad93d9d2b1beefb294a4405f6d48ceca40168115678e4ba985d178116e3258b83e09ff97ae7b319d
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ld4l-foaf-gem_no-rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # GETTING FROM GEMFILE UNTIL ActiveTriples master CODE IS RELEASED (>0.4.0), THEN MOVE THIS BACK TO *.gemspec FILE
6
+ # Use active-triples for handling of triple persistence
7
+ gem 'active-triples', :git => 'git@github.com:ActiveTriples/ActiveTriples.git', :branch => 'master'
8
+
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2014 Cornell University
2
+
3
+ ##########################################################################
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ #LD4L::FoafRDF
2
+
3
+ LD4L FOAF RDF provides tools for modeling person triples based on the FOAF ontology and persisting to a triplestore.
4
+
5
+
6
+ ## Installation
7
+
8
+ Temporary get the gem from github until the gem is released publicly.
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ <!-- gem 'ld4l-foaf_rdf' -->
13
+ gem 'ld4l-foaf_rdf', '~> 0.0.3', :git => 'git@github.com:ld4l/foaf_rdf.git'
14
+
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ <!--
21
+ Or install it yourself as:
22
+
23
+ $ gem install ld4l-foaf_rdf
24
+ -->
25
+
26
+
27
+ ## Usage
28
+
29
+ **Caveat:** This gem is part of the LD4L Project and is being used in that context. There is no guarantee that the
30
+ code will work in a usable way outside of its use in LD4L Use Cases.
31
+
32
+ ### Examples
33
+
34
+ Setup required for all examples.
35
+ ```
36
+ require 'ld4l/foaf_rdf'
37
+
38
+ # create an in-memory repository
39
+ ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
40
+ ```
41
+
42
+ Example creating a person.
43
+ ```
44
+ p = LD4L::FoafRDF::Person.new('p4')
45
+
46
+ puts p.dump :ttl
47
+ ```
48
+
49
+ Example triples created for a person.
50
+ ```
51
+ <http://localhost/p4> a <http://xmlns.com/foaf/0.1/Person> .
52
+ ```
53
+
54
+
55
+ ### Configurations
56
+
57
+ * base_uri - base URI used when new resources are created (default="http://localhost/")
58
+ * localname_minter - minter function to use for creating unique local names (default=nil which uses default minter in active_triples-local_name gem)
59
+
60
+ *Setup for all examples.*
61
+
62
+ * Restart your interactive session (e.g. irb, pry).
63
+ * Use the Setup for all examples in main Examples section above.
64
+
65
+ *Example usage using configured base_uri and default localname_minter.*
66
+ ```
67
+ LD4L::FoafRDF.configure do |config|
68
+ config.base_uri = "http://example.org/"
69
+ end
70
+
71
+ p = LD4L::FoafRDF::Person.new(ActiveTriples::LocalName::Minter.generate_local_name(
72
+ LD4L::FoafRDF::Person, 10, {:prefix=>'p'} ))
73
+
74
+ puts p.dump :ttl
75
+ ```
76
+ NOTE: If base_uri is not used, you need to restart your interactive environment (e.g. irb, pry). Once the
77
+ Person class is instantiated the first time, the base_uri for the class is set. If you ran
78
+ through the main Examples, the base_uri was set to the default base_uri.
79
+
80
+
81
+ *Example triples created for a person with configured base_uri and default minter.*
82
+ ```
83
+ <http://example.org/p45c9c85b-25af-4c52-96a4-cf0d8b70a768> a <http://xmlns.com/foaf/0.1/Person> .
84
+ ```
85
+
86
+ *Example usage using configured base_uri and configured localname_minter.*
87
+ ```
88
+ LD4L::FoafRDF.configure do |config|
89
+ config.base_uri = "http://example.org/"
90
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
91
+ end
92
+
93
+ p = LD4L::FoafRDF::Person.new(ActiveTriples::LocalName::Minter.generate_local_name(
94
+ LD4L::FoafRDF::Person, 10, 'p',
95
+ &LD4L::FoafRDF.configuration.localname_minter ))
96
+
97
+ puts p.dump :ttl
98
+ ```
99
+ NOTE: If base_uri is not used, you need to restart your interactive environment (e.g. irb, pry). Once the
100
+ Person class is instantiated the first time, the base_uri for the class is set. If you ran
101
+ through the main Examples, the base_uri was set to the default base_uri.
102
+
103
+
104
+ *Example triples created for a person with configured base_uri and configured minter.*
105
+ ```
106
+ <http://example.org/p_configured_6498ba05-8b21-4e8c-b9d4-a6d5d2180966> a <http://xmlns.com/foaf/0.1/Person> .
107
+ ```
108
+
109
+
110
+ ### Models
111
+
112
+ The LD4L::FoafRDF gem provides model definitions using the
113
+ [ActiveTriples](https://github.com/ActiveTriples/ActiveTriples) framework extension of
114
+ [ruby-rdf/rdf](https://github.com/ruby-rdf/rdf). The following models are provided:
115
+
116
+ 1. LD4L::FoafRDF::Person - Implements the Person class in the FOAF ontology. (extremely simple for holding rdf_subject only)
117
+
118
+
119
+ ### Ontologies
120
+
121
+ The listed ontologies are used to represent the primary metadata about the person.
122
+ Other ontologies may also be used that aren't listed.
123
+
124
+ * [FOAF](http://xmlns.com/foaf/spec/)
125
+ * [RDF](http://www.w3.org/TR/rdf-syntax-grammar/)
126
+
127
+
128
+ ## Contributing
129
+
130
+ 1. Fork it ( https://github.com/[my-github-username]/ld4l-foaf_rdf/fork )
131
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
132
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
133
+ 4. Push to the branch (`git push origin my-new-feature`)
134
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ld4l/foaf_rdf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ld4l-foaf_rdf"
8
+ spec.version = LD4L::FoafRDF::VERSION
9
+ spec.authors = ["E. Lynette Rayle"]
10
+ spec.email = ["elr37@cornell.edu"]
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.summary = %q{FOAF RDF models.}
13
+ spec.description = %q{LD4L FOAF RDF provides tools for modeling a person triples based on the FOAF ontology and persisting to a triplestore.}
14
+ spec.homepage = "https://github.com/ld4l/foaf_rdf"
15
+ spec.license = "APACHE2"
16
+ spec.required_ruby_version = '>= 2.1.2'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ # spec.test_files = `git ls-files -- {spec}/*`.split("\n") # FROM ActiveTriples gemspec file
21
+ # spec.require_paths = ["lib"] # NOT IN ActiveTriples gemspec file
22
+
23
+ # spec.add_dependency('ffi', '~> 1.9.5')
24
+ spec.add_dependency('rdf', '~> 1.1')
25
+
26
+ # GETTING FROM GEMFILE UNTIL ActiveTriples master CODE IS RELEASED (>0.4.0), THEN MOVE THIS BACK TO *.gemspec FILE
27
+ # spec.add_dependency('active-triples', '~> 0.4')
28
+
29
+ spec.add_dependency('active_triples-local_name', '~> 0.1')
30
+
31
+ spec.add_development_dependency('pry')
32
+ spec.add_development_dependency('rdoc')
33
+ spec.add_development_dependency('rspec')
34
+ spec.add_development_dependency('guard-rspec')
35
+ spec.add_development_dependency('webmock')
36
+
37
+ spec.extra_rdoc_files = [
38
+ "LICENSE.txt",
39
+ "README.md"
40
+ ]
41
+ end
42
+
@@ -0,0 +1,41 @@
1
+ module LD4L
2
+ module FoafRDF
3
+ class Configuration
4
+
5
+ attr_reader :base_uri
6
+ attr_reader :localname_minter
7
+
8
+ def self.default_base_uri
9
+ @default_base_uri = "http://localhost/".freeze
10
+ end
11
+ private_class_method :default_base_uri
12
+
13
+ def self.default_localname_minter
14
+ # by setting to nil, it will use the default minter in the minter gem
15
+ @default_localname_minter = nil
16
+ end
17
+ private_class_method :default_localname_minter
18
+
19
+ def initialize
20
+ @base_uri = self.class.send(:default_base_uri)
21
+ @localname_minter = self.class.send(:default_localname_minter)
22
+ end
23
+
24
+ def base_uri=(new_base_uri)
25
+ @base_uri = new_base_uri
26
+ end
27
+
28
+ def reset_base_uri
29
+ @base_uri = self.class.send(:default_base_uri)
30
+ end
31
+
32
+ def localname_minter=(new_minter)
33
+ @localname_minter = new_minter
34
+ end
35
+
36
+ def reset_localname_minter
37
+ @localname_minter = self.class.send(:default_localname_minter)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ module LD4L
2
+ module FoafRDF
3
+ class Person < ActiveTriples::Resource
4
+
5
+ class << self; attr_reader :localname_prefix end
6
+ @localname_prefix="p"
7
+
8
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module LD4L
2
+ module FoafRDF
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'rdf'
2
+ require 'active_triples'
3
+ require 'active_triples/local_name'
4
+ require 'linkeddata'
5
+ require 'ld4l/foaf_rdf/version'
6
+
7
+
8
+ module LD4L
9
+ module FoafRDF
10
+
11
+ # Methods for configuring the GEM
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.reset
21
+ @configuration = Configuration.new
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+
28
+
29
+ # RDF vocabularies
30
+ # none - uses RDF::FOAF vocabulary
31
+
32
+ # autoload classes
33
+ autoload :Configuration, 'ld4l/foaf_rdf/configuration'
34
+ autoload :Person, 'ld4l/foaf_rdf/person'
35
+
36
+ def self.class_from_string(class_name, container_class=Kernel)
37
+ container_class = container_class.name if container_class.is_a? Module
38
+ container_parts = container_class.split('::')
39
+ (container_parts + class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
40
+ if mod == Kernel
41
+ Object.const_get(class_name)
42
+ elsif mod.const_defined? class_name.to_sym
43
+ mod.const_get(class_name)
44
+ else
45
+ container_parts.pop
46
+ class_from_string(class_name, container_parts.join('::'))
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+
@@ -0,0 +1,174 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LD4L::FoafRDF' 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 DummyPerson < LD4L::FoafRDF::Person
10
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
11
+ end
12
+ end
13
+ after do
14
+ Object.send(:remove_const, "DummyPerson") if Object
15
+ end
16
+ it "should generate a Person URI using the default base_uri" do
17
+ expect(DummyPerson.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::FoafRDF.configure do |config|
24
+ config.base_uri = "http://localhost/test_slash/"
25
+ end
26
+ class DummyPerson < LD4L::FoafRDF::Person
27
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
28
+ end
29
+ end
30
+ after do
31
+ Object.send(:remove_const, "DummyPerson") if Object
32
+ LD4L::FoafRDF.reset
33
+ end
34
+
35
+ it "should generate a Person URI using the configured base_uri" do
36
+ expect(DummyPerson.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::FoafRDF.configure do |config|
43
+ config.base_uri = "http://localhost/test_no_slash"
44
+ end
45
+ class DummyPerson < LD4L::FoafRDF::Person
46
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
47
+ end
48
+ end
49
+ after do
50
+ Object.send(:remove_const, "DummyPerson") if Object
51
+ LD4L::FoafRDF.reset
52
+ end
53
+
54
+ it "should generate a Person URI using the configured base_uri" do
55
+ expect(DummyPerson.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::FoafRDF.configure do |config|
61
+ config.base_uri = "http://localhost/test_config/"
62
+ end
63
+ expect(LD4L::FoafRDF.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::FoafRDF.configure do |config|
68
+ config.base_uri = "http://localhost/test_config/"
69
+ end
70
+ expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/test_config/"
71
+ LD4L::FoafRDF.configuration.reset_base_uri
72
+ expect(LD4L::FoafRDF.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::FoafRDF.configure do |config|
77
+ config.base_uri = "http://localhost/test_config/"
78
+ end
79
+ expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/test_config/"
80
+ LD4L::FoafRDF.reset
81
+ expect(LD4L::FoafRDF.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
+ before do
88
+ class DummyPerson < LD4L::FoafRDF::Person
89
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
90
+ end
91
+ end
92
+ after do
93
+ Object.send(:remove_const, "DummyPerson") if Object
94
+ end
95
+ it "should use default minter in minter gem" do
96
+ localname = ActiveTriples::LocalName::Minter.generate_local_name(
97
+ LD4L::FoafRDF::Person, 10, {:prefix=>'default_'},
98
+ LD4L::FoafRDF.configuration.localname_minter )
99
+ expect(localname).to be_kind_of String
100
+ expect(localname.size).to eq 44
101
+ 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}/
102
+ end
103
+ end
104
+
105
+ context "when minter is configured" do
106
+ before do
107
+ LD4L::FoafRDF.configure do |config|
108
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
109
+ end
110
+ class DummyPerson < LD4L::FoafRDF::Person
111
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
112
+ end
113
+ end
114
+ after do
115
+ Object.send(:remove_const, "DummyPerson") if Object
116
+ LD4L::FoafRDF.reset
117
+ end
118
+
119
+ it "should generate an Person URI using the configured localname_minter" do
120
+ localname = ActiveTriples::LocalName::Minter.generate_local_name(
121
+ LD4L::FoafRDF::Person, 10,
122
+ LD4L::FoafRDF::Person.localname_prefix,
123
+ &LD4L::FoafRDF.configuration.localname_minter )
124
+ expect(localname).to be_kind_of String
125
+ expect(localname.size).to eq 49
126
+ expect(localname).to match /p_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}/
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+
133
+ describe "LD4L::FoafRDF::Configuration" do
134
+ describe "#base_uri" do
135
+ it "should default to localhost" do
136
+ expect(LD4L::FoafRDF::Configuration.new.base_uri).to eq "http://localhost/"
137
+ end
138
+
139
+ it "should be settable" do
140
+ config = LD4L::FoafRDF::Configuration.new
141
+ config.base_uri = "http://localhost/test"
142
+ expect(config.base_uri).to eq "http://localhost/test"
143
+ end
144
+
145
+ it "should be re-settable" do
146
+ config = LD4L::FoafRDF::Configuration.new
147
+ config.base_uri = "http://localhost/test/again"
148
+ expect(config.base_uri).to eq "http://localhost/test/again"
149
+ config.reset_base_uri
150
+ expect(config.base_uri).to eq "http://localhost/"
151
+ end
152
+ end
153
+
154
+ describe "#localname_minter" do
155
+ it "should default to nil" do
156
+ expect(LD4L::FoafRDF::Configuration.new.localname_minter).to eq nil
157
+ end
158
+
159
+ it "should be settable" do
160
+ config = LD4L::FoafRDF::Configuration.new
161
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
162
+ expect(config.localname_minter).to be_kind_of Proc
163
+ end
164
+
165
+ it "should be re-settable" do
166
+ config = LD4L::FoafRDF::Configuration.new
167
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
168
+ expect(config.localname_minter).to be_kind_of Proc
169
+ config.reset_localname_minter
170
+ expect(config.localname_minter).to eq nil
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,263 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LD4L::FoafRDF::Person' do
4
+ # it_behaves_like 'an ActiveTriple::Resource'
5
+
6
+ subject { LD4L::FoafRDF::Person.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::FoafRDF::Person.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 RDF::FOAF.Person" do
62
+ expect(subject.type.first.value).to eq RDF::FOAF.Person.value
63
+ end
64
+ end
65
+
66
+ describe '#localname_prefix' do
67
+ it "should return default prefix" do
68
+ prefix = LD4L::FoafRDF::Person.localname_prefix
69
+ expect(prefix).to eq "p"
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::FoafRDF::Person.new("123")}
109
+
110
+ before do
111
+ # Create inmemory repository
112
+ @repo = RDF::Repository.new
113
+ allow(subject.class).to receive(:repository).and_return(nil)
114
+ allow(subject).to receive(:repository).and_return(@repo)
115
+ subject.persist!
116
+ end
117
+
118
+ it "should persist to the repository" do
119
+ expect(@repo.statements.first).to eq subject.statements.first
120
+ end
121
+
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '#destroy!' do
127
+ before do
128
+ subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE')
129
+ end
130
+
131
+ subject { LD4L::FoafRDF::Person.new('456')}
132
+
133
+ it 'should return true' do
134
+ expect(subject.destroy!).to be true
135
+ expect(subject.destroy).to be true
136
+ end
137
+
138
+ it 'should delete the graph' do
139
+ subject.destroy
140
+ expect(subject).to be_empty
141
+ end
142
+ end
143
+
144
+ describe '#type' do
145
+ it 'should return the type configured on the parent class' do
146
+ expect(subject.type).to eq [LD4L::FoafRDF::Person.type]
147
+ end
148
+
149
+ it 'should set the type' do
150
+ subject.type = RDF::URI('http://example.org/AnotherClass')
151
+ expect(subject.type).to eq [RDF::URI('http://example.org/AnotherClass')]
152
+ end
153
+
154
+ it 'should be the type in the graph' do
155
+ subject.query(:subject => subject.rdf_subject, :predicate => RDF.type).statements do |s|
156
+ expect(s.object).to eq RDF::URI('http://example.org/AnotherClass')
157
+ end
158
+ end
159
+ end
160
+
161
+ describe '#rdf_label' do
162
+ subject {LD4L::FoafRDF::Person.new("123")}
163
+
164
+ it 'should return an array of label values' do
165
+ expect(subject.rdf_label).to be_kind_of Array
166
+ end
167
+
168
+ it 'should return the default label as URI when no title property exists' do
169
+ expect(subject.rdf_label).to eq ["#{LD4L::FoafRDF::Person.base_uri}123"]
170
+ end
171
+
172
+ it 'should prioritize configured label values' do
173
+ custom_label = RDF::URI('http://example.org/custom_label')
174
+ subject.class.configure :rdf_label => custom_label
175
+ subject << RDF::Statement(subject.rdf_subject, custom_label, RDF::Literal('New Label'))
176
+ expect(subject.rdf_label).to eq ['New Label']
177
+ end
178
+ end
179
+
180
+ describe '#solrize' do
181
+ it 'should return a label for bnodes' do
182
+ expect(subject.solrize).to eq subject.rdf_label
183
+ end
184
+
185
+ it 'should return a string of the resource uri' do
186
+ subject.set_subject! 'http://example.org/moomin'
187
+ expect(subject.solrize).to eq 'http://example.org/moomin'
188
+ end
189
+ end
190
+
191
+ describe 'big complex graphs' do
192
+ before do
193
+ class DummyPerson < ActiveTriples::Resource
194
+ configure :type => RDF::URI('http://example.org/Person')
195
+ property :foafname, :predicate => RDF::FOAF.name
196
+ property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
197
+ property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
198
+ end
199
+
200
+ class DummyDocument < ActiveTriples::Resource
201
+ configure :type => RDF::URI('http://example.org/Document')
202
+ property :title, :predicate => RDF::DC.title
203
+ property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson'
204
+ end
205
+
206
+ LD4L::FoafRDF::Person.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument
207
+ end
208
+
209
+ subject { LD4L::FoafRDF::Person.new }
210
+
211
+ let (:document1) do
212
+ d = DummyDocument.new
213
+ d.title = 'Document One'
214
+ d
215
+ end
216
+
217
+ let (:document2) do
218
+ d = DummyDocument.new
219
+ d.title = 'Document Two'
220
+ d
221
+ end
222
+
223
+ let (:person1) do
224
+ p = DummyPerson.new
225
+ p.foafname = 'Alice'
226
+ p
227
+ end
228
+
229
+ let (:person2) do
230
+ p = DummyPerson.new
231
+ p.foafname = 'Bob'
232
+ p
233
+ end
234
+
235
+ let (:data) { <<END
236
+ _:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeClass> .
237
+ _:1 <http://purl.org/dc/terms/relation> _:2 .
238
+ _:2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Document> .
239
+ _:2 <http://purl.org/dc/terms/title> "Document One" .
240
+ _:2 <http://purl.org/dc/terms/creator> _:3 .
241
+ _:2 <http://purl.org/dc/terms/creator> _:4 .
242
+ _:4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
243
+ _:4 <http://xmlns.com/foaf/0.1/name> "Bob" .
244
+ _:3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
245
+ _:3 <http://xmlns.com/foaf/0.1/name> "Alice" .
246
+ _:3 <http://xmlns.com/foaf/0.1/knows> _:4 ."
247
+ END
248
+ }
249
+
250
+ after do
251
+ Object.send(:remove_const, "DummyDocument")
252
+ Object.send(:remove_const, "DummyPerson")
253
+ end
254
+
255
+ it 'should allow access to deep nodes' do
256
+ document1.creator = [person1, person2]
257
+ document2.creator = person1
258
+ person1.knows = person2
259
+ subject.item = [document1]
260
+ expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob']
261
+ end
262
+ end
263
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe "LD4L::FoafRDF" do
4
+ describe "#configure" do
5
+
6
+ before do
7
+ LD4L::FoafRDF.configure do |config|
8
+ config.base_uri = "http://localhost/test/"
9
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
10
+ end
11
+ class DummyPerson < LD4L::FoafRDF::Person
12
+ configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default
13
+ end
14
+ end
15
+ after do
16
+ LD4L::FoafRDF.reset
17
+ Object.send(:remove_const, "DummyPerson") if Object
18
+ end
19
+
20
+ it "should return configured value" do
21
+ config = LD4L::FoafRDF.configuration
22
+ expect(config.base_uri).to eq "http://localhost/test/"
23
+ expect(config.localname_minter).to be_kind_of Proc
24
+ end
25
+
26
+ it "should use configured value in Person sub-class" do
27
+ p = DummyPerson.new('1')
28
+ expect(p.rdf_subject.to_s).to eq "http://localhost/test/1"
29
+
30
+ p = DummyPerson.new(ActiveTriples::LocalName::Minter.generate_local_name(
31
+ LD4L::FoafRDF::Person, 10, 'foo',
32
+ &LD4L::FoafRDF.configuration.localname_minter ))
33
+ expect(p.rdf_subject.to_s.size).to eq 73
34
+ expect(p.rdf_subject.to_s).to match /http:\/\/localhost\/test\/foo_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}/
35
+ end
36
+ end
37
+
38
+ describe ".reset" do
39
+ before :each do
40
+ LD4L::FoafRDF.configure do |config|
41
+ config.base_uri = "http://localhost/test/"
42
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
43
+ end
44
+ end
45
+
46
+ it "resets the configuration" do
47
+ LD4L::FoafRDF.reset
48
+ config = LD4L::FoafRDF.configuration
49
+ expect(config.base_uri).to eq "http://localhost/"
50
+ expect(config.localname_minter).to eq nil
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'ld4l/foaf_rdf'
5
+ require 'pry'
6
+
7
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.color = true
11
+ config.tty = true
12
+
13
+ # Uncomment the following line to get errors and backtrace for deprecation warnings
14
+ # config.raise_errors_for_deprecations!
15
+
16
+ # Use the specified formatter
17
+ config.formatter = :progress
18
+ end
19
+
20
+ ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ld4l-foaf_rdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - E. Lynette Rayle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdf
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_triples-local_name
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: LD4L FOAF RDF provides tools for modeling a person triples based on the
112
+ FOAF ontology and persisting to a triplestore.
113
+ email:
114
+ - elr37@cornell.edu
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.md
120
+ files:
121
+ - ".gitignore"
122
+ - ".ruby-gemset"
123
+ - ".ruby-version"
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - ld4l-foaf_rdf.gemspec
129
+ - lib/ld4l/foaf_rdf.rb
130
+ - lib/ld4l/foaf_rdf/configuration.rb
131
+ - lib/ld4l/foaf_rdf/person.rb
132
+ - lib/ld4l/foaf_rdf/version.rb
133
+ - spec/ld4l/foaf_rdf/configuration_spec.rb
134
+ - spec/ld4l/foaf_rdf/person_rdf_spec.rb
135
+ - spec/ld4l/foaf_rdf_spec.rb
136
+ - spec/spec_helper.rb
137
+ homepage: https://github.com/ld4l/foaf_rdf
138
+ licenses:
139
+ - APACHE2
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 2.1.2
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.2.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: FOAF RDF models.
161
+ test_files:
162
+ - spec/ld4l/foaf_rdf/configuration_spec.rb
163
+ - spec/ld4l/foaf_rdf/person_rdf_spec.rb
164
+ - spec/ld4l/foaf_rdf_spec.rb
165
+ - spec/spec_helper.rb