rdf-reasoner 0.4.3 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +19 -18
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/lib/rdf/reasoner.rb +1 -1
- data/lib/rdf/reasoner/extensions.rb +60 -3
- data/lib/rdf/reasoner/format.rb +3 -3
- data/lib/rdf/reasoner/owl.rb +7 -31
- data/lib/rdf/reasoner/rdfs.rb +86 -25
- data/lib/rdf/reasoner/schema.rb +4 -4
- metadata +22 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 651a1431487e77d50420f0c33506df9d756e7eab48790589bdfacdc404b88fea
|
4
|
+
data.tar.gz: 66c536de0f20de0fe2f50be36e8a712d24efd4e1ea7674b4bff234d91a827272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 551d92044542d411803d75619a6f0d38d5cae5ae4331f7b11109006518a5db6c1fe8f7589d343e915b2e8187997a20fb68917771ebf5eba9297d0cc721e76be3
|
7
|
+
data.tar.gz: 47ee7417fdf42130820419558718332ad77748386cec3d8ef4513e5e711b299fd4bdabe5500a12eb1effdc55acb19ba5a9bce41e3e4ef63ec2510ace662c9a0b
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@ Reasons over RDFS/OWL vocabularies and schema.org to generate statements which a
|
|
8
8
|
* Entail `rdfs:subPropertyOf` generating an array of terms which are ancestors of the subject.
|
9
9
|
* Entail `rdfs:domain` and `rdfs:range` adding `rdf:type` assertions on the subject or object.
|
10
10
|
* Inverse `rdfs:subClassOf` entailment, to find descendant classes of the subject term.
|
11
|
+
* Inverse `rdfs:subPropertyOf` entailment, to find descendant properties of the subject term.
|
11
12
|
* Entail `owl:equivalentClass` generating an array of terms equivalent to the subject.
|
12
13
|
* Entail `owl:equivalentProperty` generating an array of terms equivalent to the subject.
|
13
14
|
* `domainCompatible?` determines if a particular resource is compatible with the domain definition of a given predicate, based on the intersection of entailed subclasses with the property domain.
|
@@ -51,7 +52,7 @@ Domain and Range entailment include specific rules for schema.org vocabularies.
|
|
51
52
|
|
52
53
|
RDF::Reasoner.apply(:rdfs)
|
53
54
|
graph = RDF::Graph.load("etc/doap.ttl")
|
54
|
-
subj = RDF::URI("
|
55
|
+
subj = RDF::URI("https://rubygems.org/gems/rdf-reasoner")
|
55
56
|
RDF::Vocab::DOAP.name.domain_compatible?(subj, graph) # => true
|
56
57
|
|
57
58
|
### Determine if a resource is compatible with the ranges of a property
|
@@ -103,16 +104,16 @@ The `rdf` command-line interface is extended with `entail` and `lint` commands.
|
|
103
104
|
|
104
105
|
## Dependencies
|
105
106
|
|
106
|
-
* [Ruby](
|
107
|
-
* [RDF.rb](
|
107
|
+
* [Ruby](https://ruby-lang.org/) (>= 2.2.2)
|
108
|
+
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.0)
|
108
109
|
|
109
110
|
## Mailing List
|
110
111
|
|
111
|
-
* <
|
112
|
+
* <https://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
112
113
|
|
113
114
|
## Authors
|
114
115
|
|
115
|
-
* [Gregg Kellogg](
|
116
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
116
117
|
|
117
118
|
## Contributing
|
118
119
|
|
@@ -132,17 +133,17 @@ The `rdf` command-line interface is extended with `entail` and `lint` commands.
|
|
132
133
|
## License
|
133
134
|
|
134
135
|
This is free and unencumbered public domain software. For more information,
|
135
|
-
see <
|
136
|
-
|
137
|
-
[Ruby]:
|
138
|
-
[RDF]:
|
139
|
-
[YARD]:
|
140
|
-
[YARD-GS]:
|
141
|
-
[PDD]:
|
142
|
-
[SPARQL]:
|
143
|
-
[SPARQL Query]:
|
144
|
-
[SPARQL Entailment]:
|
145
|
-
[RDF 1.1]:
|
146
|
-
[RDF.rb]:
|
147
|
-
[RDF Schema]:
|
136
|
+
see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
137
|
+
|
138
|
+
[Ruby]: https://ruby-lang.org/
|
139
|
+
[RDF]: https://www.w3.org/RDF/
|
140
|
+
[YARD]: https://yardoc.org/
|
141
|
+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
142
|
+
[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
|
143
|
+
[SPARQL]: https://en.wikipedia.org/wiki/SPARQL
|
144
|
+
[SPARQL Query]: https://www.w3.org/TR/2013/REC-sparql11-query-20130321/
|
145
|
+
[SPARQL Entailment]:https://www.w3.org/TR/sparql11-entailment/
|
146
|
+
[RDF 1.1]: https://www.w3.org/TR/rdf11-concepts
|
147
|
+
[RDF.rb]: https://www.rubydoc.info/github/ruby-rdf/rdf/
|
148
|
+
[RDF Schema]: https://www.w3.org/TR/rdf-schema/
|
148
149
|
[Rack]: https://rack.github.io/
|
data/UNLICENSE
CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
21
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
|
-
For more information, please refer to <
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.3
|
data/lib/rdf/reasoner.rb
CHANGED
@@ -7,7 +7,7 @@ module RDF
|
|
7
7
|
# RDFS/OWL reasonsing for RDF.rb.
|
8
8
|
#
|
9
9
|
# @see http://www.w3.org/TR/2013/REC-sparql11-entailment-20130321/
|
10
|
-
# @author [Gregg Kellogg](
|
10
|
+
# @author [Gregg Kellogg](https://greggkellogg.net/)
|
11
11
|
module Reasoner
|
12
12
|
require 'rdf/reasoner/format'
|
13
13
|
autoload :OWL, 'rdf/reasoner/owl'
|
@@ -2,7 +2,62 @@
|
|
2
2
|
require 'rdf'
|
3
3
|
|
4
4
|
module RDF
|
5
|
-
class
|
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.
|
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.
|
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(',')})"
|
data/lib/rdf/reasoner/format.rb
CHANGED
@@ -5,7 +5,7 @@ module RDF::Reasoner
|
|
5
5
|
# @example Obtaining an LD Patch format class
|
6
6
|
# RDF::Format.for(:reasoner) #=> RDF::Reasoner::Format
|
7
7
|
#
|
8
|
-
# @see
|
8
|
+
# @see https://www.w3.org/TR/ldpatch/
|
9
9
|
class Format < RDF::Format
|
10
10
|
|
11
11
|
##
|
@@ -23,7 +23,7 @@ module RDF::Reasoner
|
|
23
23
|
start, stmt_cnt = Time.now, RDF::CLI.repository.count
|
24
24
|
RDF::CLI.repository.entail!
|
25
25
|
secs, new_cnt = (Time.new - start), (RDF::CLI.repository.count - stmt_cnt)
|
26
|
-
opts[:logger].info "
|
26
|
+
opts[:logger].info "Entailed #{new_cnt} new statements in #{secs} seconds."
|
27
27
|
end
|
28
28
|
},
|
29
29
|
lint: {
|
@@ -38,7 +38,7 @@ module RDF::Reasoner
|
|
38
38
|
opts[:messages].merge!(RDF::CLI.repository.lint)
|
39
39
|
opts[:output].puts "Linter responded with #{opts[:messages].empty? ? 'no' : ''} messages."
|
40
40
|
secs = Time.new - start
|
41
|
-
opts[:logger].info "
|
41
|
+
opts[:logger].info "Linted in #{secs} seconds."
|
42
42
|
end
|
43
43
|
}
|
44
44
|
}
|
data/lib/rdf/reasoner/owl.rb
CHANGED
@@ -4,7 +4,7 @@ module RDF::Reasoner
|
|
4
4
|
##
|
5
5
|
# Rules for generating OWL entailment triples
|
6
6
|
#
|
7
|
-
# Extends `RDF::
|
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::
|
30
|
-
unless class?
|
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::
|
70
|
-
unless property?
|
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
|
132
|
-
::RDF::
|
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)
|
data/lib/rdf/reasoner/rdfs.rb
CHANGED
@@ -4,7 +4,7 @@ module RDF::Reasoner
|
|
4
4
|
##
|
5
5
|
# Rules for generating RDFS entailment triples
|
6
6
|
#
|
7
|
-
# Extends `RDF::
|
7
|
+
# Extends `RDF::URI` and `RDF::Statement` with specific entailment capabilities
|
8
8
|
module RDFS
|
9
9
|
##
|
10
10
|
# @return [RDF::Util::Cache]
|
@@ -34,14 +34,29 @@ module RDF::Reasoner
|
|
34
34
|
@@subPropertyOf_cache ||= RDF::Util::Cache.new(-1)
|
35
35
|
end
|
36
36
|
|
37
|
+
##
|
38
|
+
# @return [RDF::Util::Cache]
|
39
|
+
# @private
|
40
|
+
def subProperty_cache
|
41
|
+
@@subProperty_cache ||= RDF::Util::Cache.new(-1)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# @return [RDF::Util::Cache]
|
46
|
+
# @private
|
47
|
+
def descendant_property_cache
|
48
|
+
@@descendant_property_cache ||= RDF::Util::Cache.new(-1)
|
49
|
+
end
|
50
|
+
|
37
51
|
##
|
38
52
|
# For a Term: yield or return inferred subClassOf relationships by recursively applying to named super classes to get a complete set of classes in the ancestor chain of this class
|
39
53
|
# For a Statement: if predicate is `rdf:types`, yield or return inferred statements having a subClassOf relationship to the type of this statement
|
54
|
+
# @todo Should be able to entail owl:Restriction, which is a BNode. This should be allowed, and also add BNode values of that node, recursively, similar to SPARQL concise_bounded_description.uu
|
40
55
|
# @private
|
41
56
|
def _entail_subClassOf
|
42
57
|
case self
|
43
|
-
when RDF::
|
44
|
-
unless class?
|
58
|
+
when RDF::URI, RDF::Node
|
59
|
+
unless class?
|
45
60
|
yield self if block_given?
|
46
61
|
return Array(self)
|
47
62
|
end
|
@@ -58,6 +73,7 @@ module RDF::Reasoner
|
|
58
73
|
if self.predicate == RDF.type
|
59
74
|
if term = (RDF::Vocabulary.find_term(self.object) rescue nil)
|
60
75
|
term._entail_subClassOf do |t|
|
76
|
+
next if t.node? # Don't entail BNodes
|
61
77
|
statements << RDF::Statement(self.to_h.merge(object: t, inferred: true))
|
62
78
|
end
|
63
79
|
end
|
@@ -75,7 +91,7 @@ module RDF::Reasoner
|
|
75
91
|
# @private
|
76
92
|
def _entail_subClass
|
77
93
|
case self
|
78
|
-
when RDF::
|
94
|
+
when RDF::URI, RDF::Node
|
79
95
|
unless class?
|
80
96
|
yield self if block_given?
|
81
97
|
return Array(self)
|
@@ -110,8 +126,8 @@ module RDF::Reasoner
|
|
110
126
|
# @private
|
111
127
|
def _entail_subPropertyOf
|
112
128
|
case self
|
113
|
-
when RDF::
|
114
|
-
unless property?
|
129
|
+
when RDF::URI, RDF::Node
|
130
|
+
unless property?
|
115
131
|
yield self if block_given?
|
116
132
|
return Array(self)
|
117
133
|
end
|
@@ -137,8 +153,53 @@ module RDF::Reasoner
|
|
137
153
|
end
|
138
154
|
end
|
139
155
|
|
156
|
+
##
|
157
|
+
# For a Term: yield or return inferred subProperty relationships
|
158
|
+
# by recursively applying to named subproperties to get a complete
|
159
|
+
# set of properties in the descendant chain of this property
|
160
|
+
#
|
161
|
+
# For a Statement: this is a no-op, as it's not useful in this context
|
162
|
+
# @private
|
163
|
+
|
164
|
+
def _entail_subProperty
|
165
|
+
case self
|
166
|
+
when RDF::URI, RDF::Node
|
167
|
+
unless property?
|
168
|
+
yield self if block_given?
|
169
|
+
return Array(self)
|
170
|
+
end
|
171
|
+
|
172
|
+
terms = descendant_property_cache[self] ||= (
|
173
|
+
Array(self.subProperty).map do |c|
|
174
|
+
c._entail_subProperty rescue c
|
175
|
+
end.flatten + Array(self)).compact
|
176
|
+
|
177
|
+
terms.each {|t| yield t } if block_given?
|
178
|
+
terms
|
179
|
+
else []
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
##
|
184
|
+
# Get the immediate subproperties of this property.
|
185
|
+
#
|
186
|
+
# This iterates over terms defined in the vocabulary of this term,
|
187
|
+
# as well as the vocabularies imported by this vocabulary.
|
188
|
+
# @return [Array<RDF::Vocabulary::Term>]
|
189
|
+
def subProperty
|
190
|
+
raise RDF::Reasoner::Error,
|
191
|
+
"#{self} Can't entail subProperty" unless property?
|
192
|
+
vocabs = [self.vocab] + self.vocab.imported_from
|
193
|
+
subProperty_cache[self] ||= vocabs.map do |v|
|
194
|
+
Array(v.properties).select do |p|
|
195
|
+
p.property? && Array(p.subPropertyOf).include?(self)
|
196
|
+
end
|
197
|
+
end.flatten.compact
|
198
|
+
end
|
199
|
+
|
140
200
|
##
|
141
201
|
# For a Statement: yield or return inferred statements having an rdf:type of the domain of the statement predicate
|
202
|
+
# @todo Should be able to entail owl:unionOf, which is a BNode. This should be allowed, and also add BNode values of that node, recursively, similar to SPARQL concise_bounded_description.uu
|
142
203
|
# @private
|
143
204
|
def _entail_domain
|
144
205
|
case self
|
@@ -146,6 +207,7 @@ module RDF::Reasoner
|
|
146
207
|
statements = []
|
147
208
|
if term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
|
148
209
|
term.domain.each do |t|
|
210
|
+
next if t.node? # Don't entail BNodes
|
149
211
|
statements << RDF::Statement(self.to_h.merge(predicate: RDF.type, object: t, inferred: true))
|
150
212
|
end
|
151
213
|
end
|
@@ -158,6 +220,7 @@ module RDF::Reasoner
|
|
158
220
|
|
159
221
|
##
|
160
222
|
# For a Statement: if object is a resource, yield or return inferred statements having an rdf:type of the range of the statement predicate
|
223
|
+
# @todo Should be able to entail owl:unionOf, which is a BNode. This should be allowed, and also add BNode values of that node, recursively, similar to SPARQL concise_bounded_description.uu
|
161
224
|
# @private
|
162
225
|
def _entail_range
|
163
226
|
case self
|
@@ -165,6 +228,7 @@ module RDF::Reasoner
|
|
165
228
|
statements = []
|
166
229
|
if object.resource? && term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
|
167
230
|
term.range.each do |t|
|
231
|
+
next if t.node? # Don't entail BNodes
|
168
232
|
statements << RDF::Statement(self.to_h.merge(subject: self.object, predicate: RDF.type, object: t, inferred: true))
|
169
233
|
end
|
170
234
|
end
|
@@ -187,23 +251,19 @@ module RDF::Reasoner
|
|
187
251
|
# Fully entailed types of resource, if not provided, they are queried
|
188
252
|
def domain_compatible_rdfs?(resource, queryable, options = {})
|
189
253
|
raise RDF::Reasoner::Error, "#{self} can't get domains" unless property?
|
190
|
-
|
191
|
-
domains = Array(self.domain) - [RDF::OWL.Thing, RDF::RDFS.Resource]
|
254
|
+
domains = Array(self.domain).reject(&:node?) - [RDF::OWL.Thing, RDF::RDFS.Resource]
|
192
255
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
256
|
+
# Fully entailed types of the resource
|
257
|
+
types = options.fetch(:types) do
|
258
|
+
queryable.query(subject: resource, predicate: RDF.type).
|
259
|
+
map {|s| (t = (RDF::Vocabulary.find_term(s.object)) rescue nil) && t.entail(:subClassOf)}.
|
260
|
+
flatten.
|
261
|
+
uniq.
|
262
|
+
compact
|
263
|
+
end unless domains.empty?
|
201
264
|
|
202
|
-
|
203
|
-
|
204
|
-
else
|
205
|
-
true
|
206
|
-
end
|
265
|
+
# Every domain must match some entailed type
|
266
|
+
Array(types).empty? || domains.all? {|d| types.include?(d)}
|
207
267
|
end
|
208
268
|
|
209
269
|
##
|
@@ -218,7 +278,7 @@ module RDF::Reasoner
|
|
218
278
|
# Fully entailed types of resource, if not provided, they are queried
|
219
279
|
def range_compatible_rdfs?(resource, queryable, options = {})
|
220
280
|
raise RDF::Reasoner::Error, "#{self} can't get ranges" unless property?
|
221
|
-
if
|
281
|
+
if !(ranges = Array(self.range).reject(&:node?) - [RDF::OWL.Thing, RDF::RDFS.Resource]).empty?
|
222
282
|
if resource.literal?
|
223
283
|
ranges.all? do |range|
|
224
284
|
if [RDF::RDFS.Literal, RDF.XMLLiteral, RDF.HTML].include?(range)
|
@@ -301,13 +361,14 @@ module RDF::Reasoner
|
|
301
361
|
mod.add_entailment :subClassOf, :_entail_subClassOf
|
302
362
|
mod.add_entailment :subClass, :_entail_subClass
|
303
363
|
mod.add_entailment :subPropertyOf, :_entail_subPropertyOf
|
364
|
+
mod.add_entailment :subProperty, :_entail_subProperty
|
304
365
|
mod.add_entailment :domain, :_entail_domain
|
305
366
|
mod.add_entailment :range, :_entail_range
|
306
367
|
end
|
307
368
|
end
|
308
369
|
|
309
|
-
# Extend
|
310
|
-
::RDF::
|
370
|
+
# Extend URI with these methods
|
371
|
+
::RDF::URI.send(:include, RDFS)
|
311
372
|
|
312
373
|
# Extend Statement with these methods
|
313
374
|
::RDF::Statement.send(:include, RDFS)
|
@@ -317,4 +378,4 @@ module RDF::Reasoner
|
|
317
378
|
|
318
379
|
# Extend Mutable with these methods
|
319
380
|
::RDF::Mutable.send(:include, RDFS)
|
320
|
-
end
|
381
|
+
end
|
data/lib/rdf/reasoner/schema.rb
CHANGED
@@ -7,7 +7,7 @@ module RDF::Reasoner
|
|
7
7
|
##
|
8
8
|
# Rules for generating RDFS entailment triples
|
9
9
|
#
|
10
|
-
# Extends `RDF::
|
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
|
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
|
189
|
-
::RDF::
|
188
|
+
# Extend URI with this methods
|
189
|
+
::RDF::URI.send(:include, Schema)
|
190
190
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-reasoner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -16,90 +16,84 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.2.8
|
19
|
+
version: '3.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 2.2.8
|
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
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
33
|
+
version: '3.0'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
40
|
+
version: '3.0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rdf-xsd
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
45
|
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
47
|
+
version: '3.0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
54
|
+
version: '3.0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: rdf-spec
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
59
|
- - "~>"
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
61
|
+
version: '3.0'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
68
|
+
version: '3.0'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
70
|
+
name: rdf-turtle
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
73
|
- - "~>"
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
75
|
+
version: '3.0'
|
82
76
|
type: :development
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - "~>"
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
82
|
+
version: '3.0'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
84
|
+
name: json-ld
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
92
86
|
requirements:
|
93
87
|
- - "~>"
|
94
88
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
89
|
+
version: '3.0'
|
96
90
|
type: :development
|
97
91
|
prerelease: false
|
98
92
|
version_requirements: !ruby/object:Gem::Requirement
|
99
93
|
requirements:
|
100
94
|
- - "~>"
|
101
95
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
96
|
+
version: '3.0'
|
103
97
|
- !ruby/object:Gem::Dependency
|
104
98
|
name: equivalent-xml
|
105
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,28 +114,28 @@ dependencies:
|
|
120
114
|
requirements:
|
121
115
|
- - "~>"
|
122
116
|
- !ruby/object:Gem::Version
|
123
|
-
version: '3.
|
117
|
+
version: '3.8'
|
124
118
|
type: :development
|
125
119
|
prerelease: false
|
126
120
|
version_requirements: !ruby/object:Gem::Requirement
|
127
121
|
requirements:
|
128
122
|
- - "~>"
|
129
123
|
- !ruby/object:Gem::Version
|
130
|
-
version: '3.
|
124
|
+
version: '3.8'
|
131
125
|
- !ruby/object:Gem::Dependency
|
132
126
|
name: yard
|
133
127
|
requirement: !ruby/object:Gem::Requirement
|
134
128
|
requirements:
|
135
129
|
- - "~>"
|
136
130
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
131
|
+
version: 0.9.19
|
138
132
|
type: :development
|
139
133
|
prerelease: false
|
140
134
|
version_requirements: !ruby/object:Gem::Requirement
|
141
135
|
requirements:
|
142
136
|
- - "~>"
|
143
137
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
138
|
+
version: 0.9.19
|
145
139
|
description: Reasons over RDFS/OWL vocabularies to generate statements which are entailed
|
146
140
|
based on base RDFS/OWL rules along with vocabulary information. It can also be used
|
147
141
|
to ask specific questions, such as if a given object is consistent with the vocabulary
|
@@ -162,7 +156,7 @@ files:
|
|
162
156
|
- lib/rdf/reasoner/rdfs.rb
|
163
157
|
- lib/rdf/reasoner/schema.rb
|
164
158
|
- lib/rdf/reasoner/version.rb
|
165
|
-
homepage:
|
159
|
+
homepage: https://github.com/ruby-rdf/rdf-reasoner
|
166
160
|
licenses:
|
167
161
|
- Unlicense
|
168
162
|
metadata: {}
|
@@ -181,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
175
|
- !ruby/object:Gem::Version
|
182
176
|
version: '0'
|
183
177
|
requirements: []
|
184
|
-
|
185
|
-
rubygems_version: 2.6.12
|
178
|
+
rubygems_version: 3.0.4
|
186
179
|
signing_key:
|
187
180
|
specification_version: 4
|
188
181
|
summary: RDFS/OWL Reasoner for RDF.rb
|