linked_vocabs 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8afd0f6c1a9ef5c1b998260ea65516f997d8450e
4
- data.tar.gz: 16715bdd289fed07c8a13b0ad1c0efeef41167d0
3
+ metadata.gz: 5078355060b71f3b05b1d72b0d2cf66d5851ec7b
4
+ data.tar.gz: 424415eb503470073eed8d1120e9120438ac7516
5
5
  SHA512:
6
- metadata.gz: 7be672326fb2ee98c5d39407f26d461b008c798e8ba6a6f5aa8318cc3132341f7fb7b4002f476c1113158587ede9a283ef1fb1909fa974c0e3f91ec3b376debc
7
- data.tar.gz: 8c26071cf7e3bfbe01bcfd5168c4d6706d32a18c4e3ead87e882f1c69bc631676c210c3d47b13d573a07c7061c9be6e4f627d8d2f169b931f5199d894c1e9979
6
+ metadata.gz: 88ebf20502f9385e0b56149e802d4481442c56c26d558213159b9082813b214fa694ac2caf30dfc74dd32f39ba7fd131a75c3afbb5e19673463da4e50bdd34f5
7
+ data.tar.gz: 282e714d4e05d4a557b61244b167d2fbb0e87f73041146d71b9256fbea2c97e2def28db3b24c39bb241e68101e56a2f3013e039c39a93e8233cc84aeb96f83c9
@@ -8,7 +8,7 @@ module LinkedVocabs
8
8
  # QuestioningAuthority to RdfResource classes.
9
9
  # @TODO: introduce graph context for provenance
10
10
  module Controlled
11
-
11
+
12
12
  def self.included(klass)
13
13
  klass.extend ClassMethods
14
14
  klass.property :hiddenLabel, :predicate => RDF::SKOS.hiddenLabel
@@ -20,7 +20,7 @@ module LinkedVocabs
20
20
  end
21
21
  delegate :search, :get_full_record, :response, :results, :to => :qa_interface
22
22
 
23
-
23
+
24
24
  # Override set_subject! to find terms when (and only when) they
25
25
  # exist in the vocabulary
26
26
  def set_subject!(uri_or_str)
@@ -31,6 +31,8 @@ module LinkedVocabs
31
31
  rescue RuntimeError, NoMethodError
32
32
  end
33
33
 
34
+ return false if uri_or_str.is_a? RDF::Node
35
+
34
36
  self.class.vocabularies.each do |vocab, config|
35
37
  if uri_or_str.start_with? config[:prefix]
36
38
  # @TODO: is it good to need a full URI for a non-strict vocab?
@@ -50,7 +52,7 @@ module LinkedVocabs
50
52
  uri_or_str = vocab_matches.first
51
53
  return super if self.class.uses_vocab_prefix?(uri_or_str) and not uri_or_str.kind_of? RDF::Node
52
54
  end
53
-
55
+
54
56
  def in_vocab?
55
57
  return false unless self.class.uses_vocab_prefix?(rdf_subject.to_s)
56
58
  self.class.vocabularies.each do |vocab, config|
@@ -161,7 +163,7 @@ module LinkedVocabs
161
163
 
162
164
  def get_full_record(id, sub_authority)
163
165
  end
164
-
166
+
165
167
  private
166
168
 
167
169
  def sparql_starts_search(q)
@@ -173,10 +175,10 @@ module LinkedVocabs
173
175
  query = @sparql.query("SELECT DISTINCT ?s ?p ?o WHERE { ?s ?p ?o. FILTER(contains(lcase(?o), '#{q.downcase}'))}")
174
176
  solutions_from_sparql_query(query)
175
177
  end
176
-
178
+
177
179
  def solutions_from_sparql_query(query)
178
180
  # @TODO: labels should be taken from ActiveTriples::Resource.
179
- # However, the default labels there are hidden behind a private method.
181
+ # However, the default labels there are hidden behind a private method.
180
182
  labels = [RDF::SKOS.prefLabel,
181
183
  RDF::DC.title,
182
184
  RDF::RDFS.label]
@@ -187,7 +189,7 @@ module LinkedVocabs
187
189
  return label_solutions.uniq unless label_solutions.empty?
188
190
  solutions.map { |solution| build_hit(solution) }.compact.uniq
189
191
  end
190
-
192
+
191
193
  def build_hit(solution)
192
194
  { :id => solution[:s].to_s, :label => solution[:o].to_s }
193
195
  end
@@ -6,7 +6,7 @@ module LinkedVocabs::Validators
6
6
  values.each do |v|
7
7
  unless v.try(:in_vocab?)
8
8
  term = v.try(:rdf_subject) || v
9
- vocabularies = record.class.properties[attribute].class_name.vocabularies.keys
9
+ vocabularies = record.class.properties[attribute.to_s].class_name.vocabularies.keys
10
10
  record.errors.add :base, "value `#{term} for `#{attribute}` property is not a term in a controlled vocabulary #{vocabularies.join(', ')}"
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module LinkedVocabs
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "guard-rspec"
24
24
 
25
25
  spec.add_dependency 'rake'
26
- spec.add_dependency 'active-triples', '>=0.1.0'
26
+ spec.add_dependency 'active-triples', '>=0.6.0'
27
27
  spec.add_dependency 'rdf', '>=1.1.2.1'
28
28
  spec.add_dependency 'sparql'
29
29
  spec.add_dependency 'sparql-client'
@@ -18,6 +18,12 @@ describe LinkedVocabs::Controlled do
18
18
 
19
19
  subject { DummyAuthority }
20
20
 
21
+ describe '#set_subject' do
22
+ it 'handles bnodes' do
23
+ expect(subject.new.set_subject!(RDF::Node.new)).to eq false
24
+ end
25
+ end
26
+
21
27
  describe 'vocabulary registration' do
22
28
  it 'should add vocabulary' do
23
29
  expect(subject.vocabularies).to include :dcmitype
@@ -82,7 +88,7 @@ describe LinkedVocabs::Controlled do
82
88
  describe '#load_vocabularies' do
83
89
  it 'should load data' do
84
90
  subject.load_vocabularies
85
- expect(subject.new('Image').has_subject?(RDF::URI('http://purl.org/dc/dcmitype/Image'))).to be_true
91
+ expect(subject.new('Image').has_subject?(RDF::URI('http://purl.org/dc/dcmitype/Image'))).to eq true
86
92
  end
87
93
  end
88
94
 
@@ -6,13 +6,13 @@ describe LinkedVocabs::Validators::PropertyValidator do
6
6
  include LinkedVocabs::Controlled
7
7
  use_vocabulary :dcmitype
8
8
 
9
- property :type, :predicate => RDF::DC.type, :class_name => DummyAuthority
9
+ property :dctype, :predicate => RDF::DC.type, :class_name => DummyAuthority
10
10
  end
11
11
 
12
12
  class DummyResource < ActiveTriples::Resource
13
- validates_vocabulary_of :type
13
+ validates_vocabulary_of :dctype
14
14
 
15
- property :type, :predicate => RDF::DC.type, :class_name => DummyAuthority
15
+ property :dctype, :predicate => RDF::DC.type, :class_name => DummyAuthority
16
16
  end
17
17
  end
18
18
 
@@ -20,27 +20,27 @@ describe LinkedVocabs::Validators::PropertyValidator do
20
20
  Object.send(:remove_const, 'DummyAuthority') if Object
21
21
  Object.send(:remove_const, 'DummyResource') if Object
22
22
  end
23
-
23
+
24
24
  subject { DummyResource.new }
25
25
  let(:authority) { DummyAuthority }
26
-
26
+
27
27
  context 'with value in vocabulary' do
28
28
  before do
29
- subject.type = authority.list_terms.first
29
+ subject.dctype = authority.list_terms.first
30
30
  end
31
31
  it 'is valid' do
32
32
  expect(subject).to be_valid
33
33
  end
34
34
 
35
35
  it 'is invalid with other invalid values' do
36
- subject.type << 'freetext value'
36
+ subject.dctype << 'freetext value'
37
37
  expect(subject).not_to be_valid
38
38
  end
39
39
  end
40
40
 
41
41
  context 'with value out of vocabulary' do
42
42
  before do
43
- subject.type = authority.new
43
+ subject.dctype = authority.new
44
44
  end
45
45
  it 'is invalid' do
46
46
  expect(subject).not_to be_valid
@@ -50,7 +50,7 @@ describe LinkedVocabs::Validators::PropertyValidator do
50
50
  context 'with value of wrong class' do
51
51
  before do
52
52
  class NotAuthority < ActiveTriples::Resource; end
53
- subject.type = NotAuthority.new
53
+ subject.dctype = NotAuthority.new
54
54
  end
55
55
 
56
56
  after do
@@ -64,7 +64,7 @@ describe LinkedVocabs::Validators::PropertyValidator do
64
64
 
65
65
  context 'with literal value' do
66
66
  before do
67
- subject.type = 'freetext value'
67
+ subject.dctype = 'freetext value'
68
68
  end
69
69
  it 'is invalid' do
70
70
  expect(subject).not_to be_valid
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linked_vocabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-15 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.1.0
89
+ version: 0.6.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.1.0
96
+ version: 0.6.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rdf
99
99
  requirement: !ruby/object:Gem::Requirement