• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-rdf / rdf-reasoner / 7452239745

08 Jan 2024 07:28PM UTC coverage: 82.909% (+0.06%) from 82.847%
7452239745

push

github

gkellogg
* CI on Ruby 3.3.
* Reference release notes on GitHub.

228 of 275 relevant lines covered (82.91%)

426.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/lib/rdf/reasoner/owl.rb
1
# coding: utf-8
2

3
module RDF::Reasoner
2✔
4
  ##
5
  # Rules for generating OWL entailment triples
6
  #
7
  # Extends `RDF::URI` and `RDF::Statement` with specific entailment capabilities
8
  module OWL
2✔
9
    ##
10
    # @return [RDF::Util::Cache]
11
    # @private
12
    def equivalentClass_cache
2✔
13
      @@subPropertyOf_cache ||= {}
400✔
14
    end
15
    ##
16
    # @return [RDF::Util::Cache]
17
    # @private
18
    def equivalentProperty_cache
2✔
19
      @@equivalentProperty_cache ||= {}
628✔
20
    end
21

22

23
    ##
24
    # For a Term: yield or return inferred equivalentClass relationships
25
    # For a Statement: if predicate is `rdf:types`, yield or return inferred statements having a equivalentClass relationship to the type of this statement
26
    # @private
27
    def _entail_equivalentClass
2✔
28
      case self
212✔
29
      when RDF::URI, RDF::Node
30
        unless class?
92✔
31
          yield self if block_given?
×
32
          return Array(self)
×
33
        end
34

35
        # Initialize @equivalentClass_cache by iterating over all defined property terms having an `owl:equivalentClass` attribute and adding the source class as an equivalent of the destination class
36
        if equivalentClass_cache.empty?
92✔
37
          RDF::Vocabulary.each do |v|
2✔
38
            v.each do |term|
166✔
39
              term.equivalentClass.each do |equiv|
40
                (equivalentClass_cache[equiv] ||= []) << term
216✔
41
              end if term.class?
40,798✔
42
            end
43
          end
44
        end
45
        terms = (self.equivalentClass + Array(equivalentClass_cache[self])).uniq
92✔
46
        terms.each {|t| yield t} if block_given?
234✔
47
        terms
92✔
48
      when RDF::Statement
49
        statements = []
120✔
50
        if self.predicate == RDF.type
120✔
51
          if term = (RDF::Vocabulary.find_term(self.object) rescue nil)
76✔
52
            term._entail_equivalentClass do |t|
76✔
53
              statements << RDF::Statement(**self.to_h.merge(object: t, inferred: true))
128✔
54
            end
55
          end
56
        end
57
        statements.each {|s| yield s} if block_given?
220✔
58
        statements
120✔
59
      else []
×
60
      end
61
    end
62

63
    ##
64
    # For a Term: yield or return return inferred equivalentProperty relationships
65
    # For a Statement: yield or return inferred statements having a equivalentProperty relationship to predicate of this statement
66
    # @private
67
    def _entail_equivalentProperty
2✔
68
      case self
144✔
69
      when RDF::URI, RDF::Node
70
        unless property?
80✔
71
          yield self if block_given?
×
72
          return Array(self)
×
73
        end
74

75
        # Initialize equivalentProperty_cache by iterating over all defined property terms having an `owl:equivalentProperty` attribute and adding the source class as an equivalent of the destination class
76
        if equivalentProperty_cache.empty?
80✔
77
          RDF::Vocabulary.each do |v|
2✔
78
            v.each do |term|
166✔
79
              term.equivalentProperty.each do |equiv|
80
                (equivalentProperty_cache[equiv] ||= []) << term
468✔
81
              end if term.property?
40,798✔
82
            end
83
          end
84
        end
85
        terms = (self.equivalentProperty + Array(equivalentProperty_cache[self])).uniq
80✔
86
        terms.each {|t| yield t} if block_given?
170✔
87
        terms
80✔
88
      when RDF::Statement
89
        statements = []
64✔
90
        if term = (RDF::Vocabulary.find_term(self.predicate) rescue nil)
64✔
91
          term._entail_equivalentProperty do |t|
64✔
92
            statements << RDF::Statement(**self.to_h.merge(predicate: t, inferred: true))
80✔
93
          end
94
        end
95
        statements.each {|s| yield s} if block_given?
124✔
96
        statements
64✔
97
      else []
×
98
      end
99
    end
100

101
    def self.included(mod)
2✔
102
      mod.add_entailment :equivalentClass, :_entail_equivalentClass
8✔
103
      mod.add_entailment :equivalentProperty, :_entail_equivalentProperty
8✔
104
    end
105
  end
106

107
  # Extend URI with these methods
108
  ::RDF::URI.send(:include, OWL)
2✔
109

110
  # Extend Statement with these methods
111
  ::RDF::Statement.send(:include, OWL)
2✔
112

113
  # Extend Enumerable with these methods
114
  ::RDF::Enumerable.send(:include, OWL)
2✔
115

116
  # Extend Mutable with these methods
117
  ::RDF::Mutable.send(:include, OWL)
2✔
118
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc