rdf-reasoner 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 377e84cbd7ab81ee861446c9918634bc97bcfe25
4
- data.tar.gz: b03ed57e310bc107a48923e391cef30344e64776
2
+ SHA256:
3
+ metadata.gz: 23cf1038b49812deb6c2fb5095635f0fe97f415b4338f1f5f734dd9c53643995
4
+ data.tar.gz: 95755ad7c6c666a994ca7a89780214681f02727d517e836b3a8fe69e4bb07ce4
5
5
  SHA512:
6
- metadata.gz: 4d0aeeec319bf740256541783eee1514fea11ae98d3a3ae26863fb85357e79e3630b18f0ce3adc5faac42663b9b0c9d742bec1ff1b268f7c8152691125018cc4
7
- data.tar.gz: 6b8d37050cb611c36e70ea612542fdcf2b36375023bc5072f111f9a12387f9379b7131c7e06fb90243cd619f63a28826683fe5949cbb8e6dea6618df652a4639
6
+ metadata.gz: 6965cd311294b46d9b93a6a9be69da05538e59037efde845eae1c6ec626e8e01710026dc957746e31d1fb63413cffcf514c05832665c3c316d0d0cc15f45e90c
7
+ data.tar.gz: 91db92c27cb62d60a2f630be5343fb83704f532a64ba5bacbfd8c37fde2f024a9ab4422a6729a6d4abcb8e4334575f83dee30bf261c78f8132907c3efa2c4e5f
data/README.md CHANGED
@@ -104,7 +104,7 @@ The `rdf` command-line interface is extended with `entail` and `lint` commands.
104
104
  ## Dependencies
105
105
 
106
106
  * [Ruby](http://ruby-lang.org/) (>= 2.2.2)
107
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.1.1)
107
+ * [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
108
108
 
109
109
  ## Mailing List
110
110
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.5.0
@@ -2,7 +2,62 @@
2
2
  require 'rdf'
3
3
 
4
4
  module RDF
5
- class Vocabulary::Term
5
+ class URI
6
+ class << self
7
+ @@entailments = {}
8
+
9
+ ##
10
+ # Add an entailment method. The method accepts no arguments, and returns or yields an array of values associated with the particular entailment method
11
+ # @param [Symbol] method
12
+ # @param [Proc] proc
13
+ def add_entailment(method, proc)
14
+ @@entailments[method] = proc
15
+ end
16
+ end
17
+
18
+ ##
19
+ # Perform an entailment on this term.
20
+ #
21
+ # @param [Symbol] method A registered entailment method
22
+ # @yield term
23
+ # @yieldparam [Term] term
24
+ # @return [Array<Term>]
25
+ def entail(method, &block)
26
+ self.send(@@entailments.fetch(method), &block)
27
+ end
28
+
29
+ ##
30
+ # Determine if the domain of a property term is consistent with the specified resource in `queryable`.
31
+ #
32
+ # @param [RDF::Resource] resource
33
+ # @param [RDF::Queryable] queryable
34
+ # @param [Hash{Symbol => Object}] options ({})
35
+ # @option options [Array<RDF::Vocabulary::Term>] :types
36
+ # Fully entailed types of resource, if not provided, they are queried
37
+ def domain_compatible?(resource, queryable, options = {})
38
+ %w(owl rdfs schema).map {|r| "domain_compatible_#{r}?".to_sym}.all? do |meth|
39
+ !self.respond_to?(meth) || self.send(meth, resource, queryable, options)
40
+ end
41
+ end
42
+
43
+ ##
44
+ # Determine if the range of a property term is consistent with the specified resource in `queryable`.
45
+ #
46
+ # Specific entailment regimes should insert themselves before this to apply the appropriate semantic condition
47
+ #
48
+ # @param [RDF::Resource] resource
49
+ # @param [RDF::Queryable] queryable
50
+ # @param [Hash{Symbol => Object}] options ({})
51
+ # @option options [Array<RDF::Vocabulary::Term>] :types
52
+ # Fully entailed types of resource, if not provided, they are queried
53
+ def range_compatible?(resource, queryable, options = {})
54
+ %w(owl rdfs schema).map {|r| "range_compatible_#{r}?".to_sym}.all? do |meth|
55
+ !self.respond_to?(meth) || self.send(meth, resource, queryable, options)
56
+ end
57
+ end
58
+ end
59
+
60
+ class Node
6
61
  class << self
7
62
  @@entailments = {}
8
63
 
@@ -187,6 +242,7 @@ module RDF
187
242
  if term && term.class?
188
243
  # Warn against using a deprecated term
189
244
  superseded = term.attributes[:'schema:supersededBy']
245
+ superseded = superseded.pname if superseded.respond_to?(:pname)
190
246
  (messages[:class] ||= {})[pname] = ["Term is superseded by #{superseded}"] if superseded
191
247
  else
192
248
  (messages[:class] ||= {})[pname] = ["No class definition found"] unless vocab.nil? || [RDF::RDFV, RDF::RDFS].include?(vocab)
@@ -211,6 +267,7 @@ module RDF
211
267
  if term && term.property?
212
268
  # Warn against using a deprecated term
213
269
  superseded = term.attributes[:'schema:supersededBy']
270
+ superseded = superseded.pname if superseded.respond_to?(:pname)
214
271
  (messages[:property] ||= {})[pname] = ["Term is superseded by #{superseded}"] if superseded
215
272
  else
216
273
  ((messages[:property] ||= {})[pname] ||= []) << "No property definition found" unless vocab.nil?
@@ -225,7 +282,7 @@ module RDF
225
282
  compact
226
283
 
227
284
  unless term.domain_compatible?(stmt.subject, self, types: resource_types[stmt.subject])
228
- ((messages[:property] ||= {})[pname] ||= []) << if term.respond_to?(:domain)
285
+ ((messages[:property] ||= {})[pname] ||= []) << if !term.domain.empty?
229
286
  "Subject #{show_resource(stmt.subject)} not compatible with domain (#{Array(term.domain).map {|d| d.pname|| d}.join(',')})"
230
287
  else
231
288
  "Subject #{show_resource(stmt.subject)} not compatible with domainIncludes (#{term.domainIncludes.map {|d| d.pname|| d}.join(',')})"
@@ -240,7 +297,7 @@ module RDF
240
297
  compact if stmt.object.resource?
241
298
 
242
299
  unless term.range_compatible?(stmt.object, self, types: resource_types[stmt.object])
243
- ((messages[:property] ||= {})[pname] ||= []) << if term.respond_to?(:range)
300
+ ((messages[:property] ||= {})[pname] ||= []) << if !term.range.empty?
244
301
  "Object #{show_resource(stmt.object)} not compatible with range (#{Array(term.range).map {|d| d.pname|| d}.join(',')})"
245
302
  else
246
303
  "Object #{show_resource(stmt.object)} not compatible with rangeIncludes (#{term.rangeIncludes.map {|d| d.pname|| d}.join(',')})"
@@ -4,7 +4,7 @@ module RDF::Reasoner
4
4
  ##
5
5
  # Rules for generating OWL entailment triples
6
6
  #
7
- # Extends `RDF::Vocabulary::Term` and `RDF::Statement` with specific entailment capabilities
7
+ # Extends `RDF::URI` and `RDF::Statement` with specific entailment capabilities
8
8
  module OWL
9
9
  ##
10
10
  # @return [RDF::Util::Cache]
@@ -26,8 +26,8 @@ module RDF::Reasoner
26
26
  # @private
27
27
  def _entail_equivalentClass
28
28
  case self
29
- when RDF::Vocabulary::Term
30
- unless class? && respond_to?(:equivalentClass)
29
+ when RDF::URI, RDF::Node
30
+ unless class?
31
31
  yield self if block_given?
32
32
  return Array(self)
33
33
  end
@@ -66,8 +66,8 @@ module RDF::Reasoner
66
66
  # @private
67
67
  def _entail_equivalentProperty
68
68
  case self
69
- when RDF::Vocabulary::Term
70
- unless property? && respond_to?(:equivalentProperty)
69
+ when RDF::URI, RDF::Node
70
+ unless property?
71
71
  yield self if block_given?
72
72
  return Array(self)
73
73
  end
@@ -98,38 +98,14 @@ module RDF::Reasoner
98
98
  end
99
99
  end
100
100
 
101
- ##
102
- # EquivalentClass of this term, also populates reverse equivalents.
103
- #
104
- # When first called, this initializes a cache of reverse terms to terms where the the reverse term is listed as an equivalent of the original term.
105
- #
106
- # It returns the list of terms which are equivalent to this term however defined.
107
- # @return [Array<RDF::Vocabulary::Term>]
108
- def equivalentClass
109
- raise RDF::Reasoner::Error, "#{self} Can't entail equivalentClass" unless class?
110
- Array(self.attributes[:"owl:equivalentClass"]).map {|t| RDF::Vocabulary.expand_pname(t)}
111
- end
112
-
113
- ##
114
- # EquivalentProperty of this term, also populates reverse equivalents.
115
- #
116
- # When first called, this initializes a cache of reverse terms to terms where the the reverse term is listed as an equivalent of the original term.
117
- #
118
- # It returns the list of terms which are equivalent to this term however defined.
119
- # @return [Array<RDF::Vocabulary::Term>]
120
- def equivalentProperty
121
- raise RDF::Reasoner::Error, "#{self} Can't entail equivalentProperty" unless property?
122
- Array(self.attributes[:"owl:equivalentProperty"]).map {|t| RDF::Vocabulary.expand_pname(t)}
123
- end
124
-
125
101
  def self.included(mod)
126
102
  mod.add_entailment :equivalentClass, :_entail_equivalentClass
127
103
  mod.add_entailment :equivalentProperty, :_entail_equivalentProperty
128
104
  end
129
105
  end
130
106
 
131
- # Extend Term with these methods
132
- ::RDF::Vocabulary::Term.send(:include, OWL)
107
+ # Extend URI with these methods
108
+ ::RDF::URI.send(:include, OWL)
133
109
 
134
110
  # Extend Statement with these methods
135
111
  ::RDF::Statement.send(:include, OWL)
@@ -4,7 +4,7 @@ module RDF::Reasoner
4
4
  ##
5
5
  # Rules for generating RDFS entailment triples
6
6
  #
7
- # Extends `RDF::Vocabulary::Term` and `RDF::Statement` with specific entailment capabilities
7
+ # Extends `RDF::URI` and `RDF::Statement` with specific entailment capabilities
8
8
  module RDFS
9
9
  ##
10
10
  # @return [RDF::Util::Cache]
@@ -40,8 +40,8 @@ module RDF::Reasoner
40
40
  # @private
41
41
  def _entail_subClassOf
42
42
  case self
43
- when RDF::Vocabulary::Term
44
- unless class? && respond_to?(:subClassOf)
43
+ when RDF::URI, RDF::Node
44
+ unless class?
45
45
  yield self if block_given?
46
46
  return Array(self)
47
47
  end
@@ -75,7 +75,7 @@ module RDF::Reasoner
75
75
  # @private
76
76
  def _entail_subClass
77
77
  case self
78
- when RDF::Vocabulary::Term
78
+ when RDF::URI, RDF::Node
79
79
  unless class?
80
80
  yield self if block_given?
81
81
  return Array(self)
@@ -110,8 +110,8 @@ module RDF::Reasoner
110
110
  # @private
111
111
  def _entail_subPropertyOf
112
112
  case self
113
- when RDF::Vocabulary::Term
114
- unless property? && respond_to?(:subPropertyOf)
113
+ when RDF::URI, RDF::Node
114
+ unless property?
115
115
  yield self if block_given?
116
116
  return Array(self)
117
117
  end
@@ -187,23 +187,19 @@ module RDF::Reasoner
187
187
  # Fully entailed types of resource, if not provided, they are queried
188
188
  def domain_compatible_rdfs?(resource, queryable, options = {})
189
189
  raise RDF::Reasoner::Error, "#{self} can't get domains" unless property?
190
- if respond_to?(:domain)
191
- domains = Array(self.domain) - [RDF::OWL.Thing, RDF::RDFS.Resource]
190
+ domains = Array(self.domain) - [RDF::OWL.Thing, RDF::RDFS.Resource]
192
191
 
193
- # Fully entailed types of the resource
194
- types = options.fetch(:types) do
195
- queryable.query(subject: resource, predicate: RDF.type).
196
- map {|s| (t = (RDF::Vocabulary.find_term(s.object)) rescue nil) && t.entail(:subClassOf)}.
197
- flatten.
198
- uniq.
199
- compact
200
- end unless domains.empty?
192
+ # Fully entailed types of the resource
193
+ types = options.fetch(:types) do
194
+ queryable.query(subject: resource, predicate: RDF.type).
195
+ map {|s| (t = (RDF::Vocabulary.find_term(s.object)) rescue nil) && t.entail(:subClassOf)}.
196
+ flatten.
197
+ uniq.
198
+ compact
199
+ end unless domains.empty?
201
200
 
202
- # Every domain must match some entailed type
203
- Array(types).empty? || domains.all? {|d| types.include?(d)}
204
- else
205
- true
206
- end
201
+ # Every domain must match some entailed type
202
+ Array(types).empty? || domains.all? {|d| types.include?(d)}
207
203
  end
208
204
 
209
205
  ##
@@ -218,7 +214,7 @@ module RDF::Reasoner
218
214
  # Fully entailed types of resource, if not provided, they are queried
219
215
  def range_compatible_rdfs?(resource, queryable, options = {})
220
216
  raise RDF::Reasoner::Error, "#{self} can't get ranges" unless property?
221
- if respond_to?(:range) && !(ranges = Array(self.range) - [RDF::OWL.Thing, RDF::RDFS.Resource]).empty?
217
+ if !(ranges = Array(self.range) - [RDF::OWL.Thing, RDF::RDFS.Resource]).empty?
222
218
  if resource.literal?
223
219
  ranges.all? do |range|
224
220
  if [RDF::RDFS.Literal, RDF.XMLLiteral, RDF.HTML].include?(range)
@@ -306,8 +302,8 @@ module RDF::Reasoner
306
302
  end
307
303
  end
308
304
 
309
- # Extend Term with these methods
310
- ::RDF::Vocabulary::Term.send(:include, RDFS)
305
+ # Extend URI with these methods
306
+ ::RDF::URI.send(:include, RDFS)
311
307
 
312
308
  # Extend Statement with these methods
313
309
  ::RDF::Statement.send(:include, RDFS)
@@ -7,7 +7,7 @@ module RDF::Reasoner
7
7
  ##
8
8
  # Rules for generating RDFS entailment triples
9
9
  #
10
- # Extends `RDF::Vocabulary::Term` with specific entailment capabilities
10
+ # Extends `RDF::URI` with specific entailment capabilities
11
11
  module Schema
12
12
 
13
13
  ##
@@ -54,7 +54,7 @@ module RDF::Reasoner
54
54
  # Fully entailed types of resource, if not provided, they are queried
55
55
  def range_compatible_schema?(resource, queryable, options = {})
56
56
  raise RDF::Reasoner::Error, "#{self} can't get ranges" unless property?
57
- if respond_to?(:rangeIncludes) && !(ranges = Array(self.rangeIncludes) - [RDF::OWL.Thing]).empty?
57
+ if !(ranges = Array(self.rangeIncludes) - [RDF::OWL.Thing]).empty?
58
58
  if resource.literal?
59
59
  ranges.any? do |range|
60
60
  case range
@@ -185,6 +185,6 @@ module RDF::Reasoner
185
185
  end
186
186
  end
187
187
 
188
- # Extend the Term with this methods
189
- ::RDF::Vocabulary::Term.send(:include, Schema)
188
+ # Extend URI with this methods
189
+ ::RDF::URI.send(:include, Schema)
190
190
  end
metadata CHANGED
@@ -1,117 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-reasoner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2017-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdf
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '2.2'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '4.0'
19
+ version: '3.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '2.2'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '4.0'
26
+ version: '3.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rdf-vocab
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '2.2'
40
- - - "<"
31
+ - - "~>"
41
32
  - !ruby/object:Gem::Version
42
- version: '4.0'
33
+ version: '3.0'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '2.2'
50
- - - "<"
38
+ - - "~>"
51
39
  - !ruby/object:Gem::Version
52
- version: '4.0'
40
+ version: '3.0'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: rdf-xsd
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: '2.2'
60
- - - "<"
45
+ - - "~>"
61
46
  - !ruby/object:Gem::Version
62
- version: '4.0'
47
+ version: '3.0'
63
48
  type: :runtime
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '2.2'
70
- - - "<"
52
+ - - "~>"
71
53
  - !ruby/object:Gem::Version
72
- version: '4.0'
54
+ version: '3.0'
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: rdf-spec
75
57
  requirement: !ruby/object:Gem::Requirement
76
58
  requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '2.2'
80
- - - "<"
59
+ - - "~>"
81
60
  - !ruby/object:Gem::Version
82
- version: '4.0'
61
+ version: '3.0'
83
62
  type: :development
84
63
  prerelease: false
85
64
  version_requirements: !ruby/object:Gem::Requirement
86
65
  requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '2.2'
90
- - - "<"
66
+ - - "~>"
91
67
  - !ruby/object:Gem::Version
92
- version: '4.0'
68
+ version: '3.0'
93
69
  - !ruby/object:Gem::Dependency
94
- name: json-ld
70
+ name: rdf-turtle
95
71
  requirement: !ruby/object:Gem::Requirement
96
72
  requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: '2.1'
100
- - - "<"
73
+ - - "~>"
101
74
  - !ruby/object:Gem::Version
102
- version: '4.0'
75
+ version: '3.0'
103
76
  type: :development
104
77
  prerelease: false
105
78
  version_requirements: !ruby/object:Gem::Requirement
106
79
  requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '2.1'
110
- - - "<"
80
+ - - "~>"
111
81
  - !ruby/object:Gem::Version
112
- version: '4.0'
82
+ version: '3.0'
113
83
  - !ruby/object:Gem::Dependency
114
- name: rdf-turtle
84
+ name: json-ld
115
85
  requirement: !ruby/object:Gem::Requirement
116
86
  requirements:
117
87
  - - ">="
@@ -150,28 +120,28 @@ dependencies:
150
120
  requirements:
151
121
  - - "~>"
152
122
  - !ruby/object:Gem::Version
153
- version: '3.5'
123
+ version: '3.7'
154
124
  type: :development
155
125
  prerelease: false
156
126
  version_requirements: !ruby/object:Gem::Requirement
157
127
  requirements:
158
128
  - - "~>"
159
129
  - !ruby/object:Gem::Version
160
- version: '3.5'
130
+ version: '3.7'
161
131
  - !ruby/object:Gem::Dependency
162
132
  name: yard
163
133
  requirement: !ruby/object:Gem::Requirement
164
134
  requirements:
165
135
  - - "~>"
166
136
  - !ruby/object:Gem::Version
167
- version: '0.9'
137
+ version: 0.9.12
168
138
  type: :development
169
139
  prerelease: false
170
140
  version_requirements: !ruby/object:Gem::Requirement
171
141
  requirements:
172
142
  - - "~>"
173
143
  - !ruby/object:Gem::Version
174
- version: '0.9'
144
+ version: 0.9.12
175
145
  description: Reasons over RDFS/OWL vocabularies to generate statements which are entailed
176
146
  based on base RDFS/OWL rules along with vocabulary information. It can also be used
177
147
  to ask specific questions, such as if a given object is consistent with the vocabulary
@@ -212,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
182
  version: '0'
213
183
  requirements: []
214
184
  rubyforge_project:
215
- rubygems_version: 2.6.14
185
+ rubygems_version: 2.7.3
216
186
  signing_key:
217
187
  specification_version: 4
218
188
  summary: RDFS/OWL Reasoner for RDF.rb