Class: RdfsRulebook

Inherits:
Ruleby::Rulebook
  • Object
show all
Defined in:
lib/pomegranate/rdfs_rulebook.rb

Direct Known Subclasses

RdfsPlusRulebook

Instance Method Summary collapse

Instance Method Details

#rdfs_domainObject

Implements Type Propagation through rdfs:domain

Semantics

Given:
P rdfs:domain D
x P y

Infer:
x rdf:type D

Example

p = Triple.new("mit:majored_in", "rdfs:domain", ":student"); 
h = Triple.new(":Pius", "mit:majored_in", ":Course_17") 
assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "rdf:type", ":student")

Author:

  • Pius Uzamere



124
125
# File 'lib/pomegranate/rdfs_rulebook.rb', line 124

def rdfs_domain
end

#rdfs_rangeObject

Implements Type Propagation through rdfs:range

Semantics

Given:
P rdfs:range R
x P y

Infer:
y rdf:type R

Example

p = Triple.new("mit:majored_in", "rdfs:range", ":major"); 
h = Triple.new(":Pius", "mit:majored_in", ":Course_17") 
assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "rdf:type", ":student")

Author:

  • Pius Uzamere



153
154
# File 'lib/pomegranate/rdfs_rulebook.rb', line 153

def rdfs_range
end

#rdfs_rulesObject

nodoc



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/pomegranate/rdfs_rulebook.rb', line 42

def rdfs_rules
  
  ## 
  # Implements Type Propagation through rdfs:subClassOf
  #
  # ==== Semantics
  #   Given:
  #   A rdfs:subClassOf B
  #   r rdf:type A
  #
  #   Infer:
  #   r rdf:type B
  #
  # ==== Example
  #   p = Triple.new(":Pius", "rdf:type", ":male"); 
  #   h = Triple.new(":male", "rdfs:subClassOf", ":human") 
  #   assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "rdf:type", ":human")
  #
  # @author Pius Uzamere
  def rdfs_sub_class_of
  end
  
  rule :rdfs_sub_class_of,
  #TODO: add a patch to ruleby whereby the parser will raise when there's a no method error (e.g. m.subj)
    [Triple,:fact,{m.subject => :subj, m.object=>:obj},m.predicate=="rdf:type"],
    [Triple,:ont_statement,{m.object => :inferred_class },m.predicate=="rdfs:subClassOf", m.subject == b(:obj)],
    [:not, Triple, m.predicate=="rdf:type", m.subject==b(:subj), m.object==b(:inferred_class)] do |v|
      inferred_class = v[:ont_statement].object
      subj = v[:fact].subject
      assert Triple.new(subj, "rdf:type", inferred_class)
      puts "Made type inference based on rdfs:subClassOf: Triple(#{subj}, rdf:type, #{inferred_class})"  
  end
  

  ## 
  # Implements Type Propagation through rdfs:subPropertyOf
  #
  # ==== Semantics
  #   Given:
  #   P rdfs:subPropertyOf R
  #   A P B
  #
  #   Infer:
  #   A R B
  #
  # ==== Example
  #   p = Triple.new(":Pius", "mit:majored_in", ":Course_6"); 
  #   h = Triple.new("mit:majored_in", "rdfs:subPropertyOf", "mit:took_some_classes_in") 
  #   assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "mit:took_some_classes_in", ":Course_6")
  #
  # @author Pius Uzamere
  def rdfs_sub_property_of
  end
  
  rule :rdfs_sub_property_of,
    [Triple,:fact,{m.predicate=>:pred, m.subject => :subj, m.object=>:obj}],
    [Triple,:ont_statement, {m.object => :inferred_pred}, m.predicate=="rdfs:subPropertyOf", m.subject == b(:pred)],
    [:not, Triple, m.predicate==b(:inferred_pred), m.subject==b(:subj), m.object==b(:obj)] do |v|
      inferred_property = v[:ont_statement].object
      subj = v[:fact].subject
      obj = v[:fact].object
      assert Triple.new(subj, inferred_property, obj)
      puts "Made type inference based on subPropertyOf: Triple(#{subj},#{inferred_property}, #{obj})"  
  end
  
  ## 
  # Implements Type Propagation through rdfs:domain
  #
  # ==== Semantics
  #   Given:
  #   P rdfs:domain D
  #   x P y
  #
  #   Infer:
  #   x rdf:type D
  #
  # ==== Example
  #   p = Triple.new("mit:majored_in", "rdfs:domain", ":student"); 
  #   h = Triple.new(":Pius", "mit:majored_in", ":Course_17") 
  #   assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "rdf:type", ":student")
  #
  # @author Pius Uzamere
  def rdfs_domain
  end
  
  rule :rdfs_domain,
    [Triple,:fact,{m.predicate=>:pred}],
    [Triple,:ont_statement,m.predicate=="rdfs:domain", m.subject == b(:pred)] do |v|
      inferred_type = v[:ont_statement].object
      subj = v[:fact].subject
      assert Triple.new(subj, "rdf:type", inferred_type)
      puts "Made type inference based on rdfs:domain: Triple(#{subj},rdf:type, #{inferred_type})"  
  end
  
  ## 
  # Implements Type Propagation through rdfs:range
  #
  # ==== Semantics
  #   Given:
  #   P rdfs:range R
  #   x P y
  #
  #   Infer:
  #   y rdf:type R
  #
  # ==== Example
  #   p = Triple.new("mit:majored_in", "rdfs:range", ":major"); 
  #   h = Triple.new(":Pius", "mit:majored_in", ":Course_17") 
  #   assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "rdf:type", ":student")
  #
  # @author Pius Uzamere
  def rdfs_range
  end
  
  rule :rdfs_range,
    [Triple,:fact,{m.predicate=>:pred}],
    [Triple,:ont_statement,m.predicate=="rdfs:range", m.subject == b(:pred)] do |v|
      inferred_type = v[:ont_statement].object
      subj = v[:fact].object
      assert Triple.new(subj, "rdf:type", inferred_type)
      puts "Made type inference based on rdfs:range: Triple(#{subj},rdf:type, #{inferred_type})"  
  end
  
end

#rdfs_sub_class_ofObject

Implements Type Propagation through rdfs:subClassOf

Semantics

Given:
A rdfs:subClassOf B
r rdf:type A

Infer:
r rdf:type B

Example

p = Triple.new(":Pius", "rdf:type", ":male"); 
h = Triple.new(":male", "rdfs:subClassOf", ":human") 
assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "rdf:type", ":human")

Author:

  • Pius Uzamere



61
62
# File 'lib/pomegranate/rdfs_rulebook.rb', line 61

def rdfs_sub_class_of
end

#rdfs_sub_property_ofObject

Implements Type Propagation through rdfs:subPropertyOf

Semantics

Given:
P rdfs:subPropertyOf R
A P B

Infer:
A R B

Example

p = Triple.new(":Pius", "mit:majored_in", ":Course_6"); 
h = Triple.new("mit:majored_in", "rdfs:subPropertyOf", "mit:took_some_classes_in") 
assert p; assert h;  #=> infers a triple ~= Triple.new(":Pius", "mit:took_some_classes_in", ":Course_6")

Author:

  • Pius Uzamere



93
94
# File 'lib/pomegranate/rdfs_rulebook.rb', line 93

def rdfs_sub_property_of
end

#rulesObject



37
38
39
# File 'lib/pomegranate/rdfs_rulebook.rb', line 37

def rules
  rdfs_rules
end