Class: RdfsPlusRulebook

Inherits:
RdfsRulebook show all
Defined in:
lib/pomegranate/rdfs_plus_rulebook.rb

Instance Method Summary collapse

Methods inherited from RdfsRulebook

#rdfs_domain, #rdfs_range, #rdfs_rules, #rdfs_sub_class_of, #rdfs_sub_property_of

Instance Method Details

#owl_equivalent_classObject

Implements Class Equivalence through owl:equivalentClass

Semantics

Given:
A owl:equivalentClass B
r rdf:type A

Infer:
r rdf:type B

   AND

Given:
C owl:equivalentClass D
C rdfs:subClassOf D
z rdf:type D

Infer:
z rdf:type C

Example

p = Triple.new("mit:class", "owl:equivalentClass", "mit:subject"); 
h = Triple.new(":6.111", "rdf:type", "mit:class");
assert p; assert h; #=> infers a triple ~= Triple.new(":6.111", ":rdf:type", ":mit:subject")

Author:

  • Pius Uzamere



141
142
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 141

def owl_equivalent_class
end

#owl_equivalent_propertyObject

Implements Property Equivalence through owl:equivalentProperty

Semantics

Given:
A owl:equivalentProperty B
r A c

Infer:
r B C

   AND

Given:
C owl:equivalentClass D
C rdfs:subClassOf D
z rdf:type D

Infer:
z rdf:type C

Example

p = Triple.new("mit:took_class", "owl:equivalentProperty", "mit:took_course"); 
h = Triple.new(":Pius", "mit:took_course", ":6.111");
assert p; assert h; #=> infers a triple ~= Triple.new(":Pius", "mit:took_class", ":6.111")

Author:

  • Pius Uzamere



180
181
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 180

def owl_equivalent_property
end

#owl_functional_propertyObject

owl:FunctionalProperty

Semantics

Given:
P rdf:type owl:FunctionalProperty
x P y
x P z

Infer:
y owl:sameAs z

Example

p = Triple.new("mit:had_academic_advisor", "rdf:type", "owl:FunctionalProperty");
h = Triple.new(":Pius", "mit:had_academic_advisor", ":Hal");
d = Triple.new(":Pius", "mit:had_academic_advisor", ":Dude_Who_Wrote_SICP_With_Gerald_Sussman");
assert p; assert h; assert d; #=> infers a triple ~= Triple.new(":Hal", "owl:sameAs", ":Dude_Who_Wrote_SICP_With_Gerald_Sussman")

Author:

  • Pius Uzamere



276
277
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 276

def owl_functional_property
end

#owl_inverse_functional_propertyObject

owl:InverseFunctionalProperty

Semantics

Given:
P rdf:type owl:InverseFunctionalProperty
z P x
y P x

Infer:
y owl:sameAs z

Example

p = Triple.new("mit:lived_alone_fall_2004_in", "rdf:type", "owl:FunctionalProperty");
h = Triple.new(":Pius", "mit:lived_alone_fall_2004_in", ":pomegranate_314_at_Next_House");
d = Triple.new(":2004_UA_President", "mit:lived_alone_fall_2004_in", ":pomegranate_314_at_Next_House");
assert p; assert h; assert d; #=> infers a triple ~= Triple.new(":Pius", "owl:sameAs", ":2004_UA_President")

Author:

  • Pius Uzamere



311
312
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 311

def owl_inverse_functional_property
end

#owl_inverse_ofObject

Implements Type Propagation through owl:inverseOf

Semantics

Given:
P owl:inverseOf Q
x P y

Infer:
y Q x

Example

p = Triple.new(":Pius", ":took_a_class_taught_by", ":Winston"); 
h = Triple.new(":took_a_class_taught_by", "owl:inverseOf", ":taught") 
assert p; assert h;  #=> infers a triple ~= Triple.new(":Winston", "taught", ":Pius")

Author:

  • Pius Uzamere



41
42
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 41

def owl_inverse_of
end

#owl_same_asObject

Implements Individual Equivalence through owl:sameAs

Semantics

Given:
x owl:sameAs y
o P x

Infer:
o P y

   AND

Given:
x owl:sameAs y
x P o

Infer:
z rdf:type C

Example

p = Triple.new(":Pius", "owl:sameAs", ":Uzamere"); 
h = Triple.new(":Pius", "mit:took_course", ":6.171");
assert p; assert h; #=> infers a triple ~= Triple.new(":Uzamere", "mit:took_course", ":6.171")

Author:

  • Pius Uzamere



217
218
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 217

def owl_same_as
end

#owl_symmetric_propertyObject

Implements Type Propagation through owl:SymmetricProperty

Semantics

Given:
P rdf:type owl:SymmetricProperty

Infer:
P owl:inverseOf P

Example

p = Triple.new(":Pius", ":was_in_a_class_with", ":Adam"); 
h = Triple.new(":was_in_a_class_with", "rdf:type", "owl:SymmetricProperty") 
assert p; assert h;  #=> infers a triple ~= Triple.new(":Adam", ":was_in_a_class_with", ":Pius")

Author:

  • Pius Uzamere



71
72
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 71

def owl_symmetric_property
end

#owl_transitive_propertyObject

Implements Type Propagation through owl:TransitiveProperty

Semantics

Given:
P rdf:type owl:TransitiveProperty
X P Y
X P Z

Infer:
X P Z

Example

p = Triple.new(":Dirichlet", ":is_an_academic_ancestor_of", ":Minsky"); 
h = Triple.new(":Poisson", ":is_an_academic_ancestor_of", ":Dirichlet");
j = Triple.new(":is_an_academic_ancestor_of", "rdf:type", "owl:TransitiveProperty"); 
assert p; assert h; assert j;  #=> infers a triple ~= Triple.new(":Poisson", ":is_an_academic_ancestor_of", ":Minsky")

Author:

  • Pius Uzamere



100
101
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 100

def owl_transitive_property
end

#rdfs_plus_rulesObject

nodoc



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 23

def rdfs_plus_rules
  ## 
  # Implements Type Propagation through owl:inverseOf
  #
  # ==== Semantics
  #   Given:
  #   P owl:inverseOf Q
  #   x P y
  #
  #   Infer:
  #   y Q x
  #
  # ==== Example
  #   p = Triple.new(":Pius", ":took_a_class_taught_by", ":Winston"); 
  #   h = Triple.new(":took_a_class_taught_by", "owl:inverseOf", ":taught") 
  #   assert p; assert h;  #=> infers a triple ~= Triple.new(":Winston", "taught", ":Pius")
  #
  # @author Pius Uzamere
  def owl_inverse_of
  end
  
  rule :owl_inverse_of,
    [Triple,:fact,{m.predicate=>:pred, m.object => :new_subj, m.subject => :new_obj}],
    [Triple,:ont_statement,{m.object => :inferred_pred},m.predicate=="owl:inverseOf", m.subject == b(:pred)],
    [:not, Triple, m.predicate==b(:inferred_pred), m.subject==b(:new_subj), m.object==b(:new_obj)] do |v|
      inferred_property = v[:ont_statement].object
      obj = v[:fact].subject
      subj = v[:fact].object
      assert Triple.new(subj, inferred_property, obj)
      puts "Made type inference based on owl:inverseOf: Triple(#{subj}, #{inferred_property}, #{obj})"
  end
  
  ## 
  # Implements Type Propagation through owl:SymmetricProperty
  #
  # ==== Semantics
  #   Given:
  #   P rdf:type owl:SymmetricProperty
  #
  #   Infer:
  #   P owl:inverseOf P
  #
  # ==== Example
  #   p = Triple.new(":Pius", ":was_in_a_class_with", ":Adam"); 
  #   h = Triple.new(":was_in_a_class_with", "rdf:type", "owl:SymmetricProperty") 
  #   assert p; assert h;  #=> infers a triple ~= Triple.new(":Adam", ":was_in_a_class_with", ":Pius")
  #
  # @author Pius Uzamere
  def owl_symmetric_property
  end
  
  rule :owl_symmetric_property,
    [Triple,:ont_statement,m.predicate=="rdf:type",m.object=="owl:SymmetricProperty"] do |v|
      prop = v[:ont_statement].subject
      assert Triple.new(prop, "owl:inverseOf", prop)
      puts "Made type inference based on owl:SymmetricProperty: Triple(#{prop}, owl:inverseOf, #{prop})"
  end
  
  ## 
  # Implements Type Propagation through owl:TransitiveProperty
  #
  # ==== Semantics
  #   Given:
  #   P rdf:type owl:TransitiveProperty
  #   X P Y
  #   X P Z
  #
  #   Infer:
  #   X P Z
  #
  # ==== Example
  #   p = Triple.new(":Dirichlet", ":is_an_academic_ancestor_of", ":Minsky"); 
  #   h = Triple.new(":Poisson", ":is_an_academic_ancestor_of", ":Dirichlet");
  #   j = Triple.new(":is_an_academic_ancestor_of", "rdf:type", "owl:TransitiveProperty"); 
  #   assert p; assert h; assert j;  #=> infers a triple ~= Triple.new(":Poisson", ":is_an_academic_ancestor_of", ":Minsky")
  #
  # @author Pius Uzamere
  def owl_transitive_property
  end
      
  rule :owl_transitive_property,
    [Triple,:ont_statement,{m.subject => :trans_prop},m.predicate=="rdf:type",m.object=="owl:TransitiveProperty"],
    [Triple,:fact1,{m.predicate=>:predi, m.subject => :sub, m.object => :trans_obj}, m.predicate == b(:trans_prop), m.subject.not== m.object],
    [Triple,:fact2, m.predicate==b(:predi), m.subject==b(:trans_obj), m.predicate.not=="owl:inverseOf", m.object.not== b(:sub) ] do |v|
      subj = v[:fact1].subject
      obj = v[:fact2].object
      prop = v[:ont_statement].subject
      assert Triple.new(subj, prop, obj)
      puts "Made type inference based on owl:TransitiveProperty: Triple(#{subj}, #{prop}, #{obj})"
  end
  
  ## 
  # Implements Class Equivalence through owl:equivalentClass
  #
  # ==== Semantics
  #   Given:
  #   A owl:equivalentClass B
  #   r rdf:type A
  #   
  #   Infer:
  #   r rdf:type B
  #
  #      AND
  #
  #   Given:
  #   C owl:equivalentClass D
  #   C rdfs:subClassOf D
  #   z rdf:type D
  #
  #   Infer:
  #   z rdf:type C
  #
  # ==== Example
  #   p = Triple.new("mit:class", "owl:equivalentClass", "mit:subject"); 
  #   h = Triple.new(":6.111", "rdf:type", "mit:class");
  #   assert p; assert h; #=> infers a triple ~= Triple.new(":6.111", ":rdf:type", ":mit:subject")
  #
  # @author Pius Uzamere
  def owl_equivalent_class
  end
  
  rule :owl_equivalent_class,
    [Triple,:ont_statement,m.predicate=="owl:equivalentClass"] do |v|
      assert Triple.new("owl:equivalentClass", "rdf:type", "owl:SymmetricProperty")
      assert Triple.new("owl:equivalentClass", "rdfs:subPropertyOf", "rdfs:subClassOf")
      #this is cute . . . only annoying thing is that you don't get the downstream explanation of the inferences
  end
  
  
  ## 
  # Implements Property Equivalence through owl:equivalentProperty
  #
  # ==== Semantics
  #   Given:
  #   A owl:equivalentProperty B
  #   r A c
  #   
  #   Infer:
  #   r B C
  #
  #      AND
  #
  #   Given:
  #   C owl:equivalentClass D
  #   C rdfs:subClassOf D
  #   z rdf:type D
  #
  #   Infer:
  #   z rdf:type C
  #
  # ==== Example
  #   p = Triple.new("mit:took_class", "owl:equivalentProperty", "mit:took_course"); 
  #   h = Triple.new(":Pius", "mit:took_course", ":6.111");
  #   assert p; assert h; #=> infers a triple ~= Triple.new(":Pius", "mit:took_class", ":6.111")
  #
  # @author Pius Uzamere
  
  def owl_equivalent_property
  end
  
  rule :owl_equivalent_property,
    [Triple,:ont_statement,m.predicate=="owl:equivalentProperty"] do |v|
      assert Triple.new("owl:equivalentProperty", "rdf:type", "owl:SymmetricProperty")
      assert Triple.new("owl:equivalentProperty", "rdfs:subPropertyOf", "rdfs:subPropertyOf")
      #this is cute . . . only annoying thing is that you don't get the downstream explanation of the inferences
  end

  ## 
  # Implements Individual Equivalence through owl:sameAs
  #
  # ==== Semantics
  #   Given:
  #   x owl:sameAs y
  #   o P x
  #   
  #   Infer:
  #   o P y
  #
  #      AND
  #
  #   Given:
  #   x owl:sameAs y
  #   x P o
  #
  #   Infer:
  #   z rdf:type C
  #
  # ==== Example
  #   p = Triple.new(":Pius", "owl:sameAs", ":Uzamere"); 
  #   h = Triple.new(":Pius", "mit:took_course", ":6.171");
  #   assert p; assert h; #=> infers a triple ~= Triple.new(":Uzamere", "mit:took_course", ":6.171")
  #
  # @author Pius Uzamere
  
  def owl_same_as
  end
  
  rule :owl_same_as_symmetricity,
    [Triple,:ont_statement, m.predicate=="owl:sameAs"] do |v|
    assert Triple.new("owl:sameAs", "rdf:type", "owl:SymmetricProperty")
    puts "asserting the symmetricity of owl:sameAs"
  end
  
  
  rule :owl_same_as_when_subject,

    [Triple,:ont_statement,{m.subject => :original, m.object => :doppelganger}, m.predicate=="owl:sameAs"],
    [Triple,:fact, {m.predicate => :p, m.object => :common_object}, m.subject == b(:original), m.subject.not== b(:doppelganger), m.predicate.not== "owl:sameAs"],
    [:not, Triple, m.predicate==b(:p), m.subject==b(:doppelganger), m.object==b(:common_object)] do |v|

    subj = v[:ont_statement].object
    pred = v[:fact].predicate
    obj = v[:fact].object
    
    puts "Made type inference based on owl:sameAs: Triple(#{subj}, #{pred}, #{obj})"
    assert Triple.new(subj, pred, obj)
    #this is cute . . . only annoying thing is that you don't get the downstream explanation of the inferences
  end
  
  rule :owl_same_as_when_object,
    [Triple,:ont_statement,{m.object => :original, m.subject => :doppelganger}, m.predicate=="owl:sameAs"],
    [Triple,:fact, {m.predicate => :p, m.object => :ob, m.subject => :common_subject}, m.object == b(:original), m.object.not== b(:doppelganger), m.predicate.not== "owl:sameAs"],
    [:not, Triple, m.predicate==b(:p), m.subject==b(:common_subject), m.object==b(:doppelganger)] do |v|

    obj = v[:ont_statement].subject
    pred = v[:fact].predicate
    subj = v[:fact].subject
    
    puts "Made type inference based on owl:sameAs: Triple(#{subj}, #{pred}, #{obj})"
    assert Triple.new(subj, pred, obj)
    #this is cute . . . only annoying thing is that you don't get the downstream explanation of the inferences
  end
  
  ## 
  # owl:FunctionalProperty
  #
  # ==== Semantics
  #   Given:
  #   P rdf:type owl:FunctionalProperty
  #   x P y
  #   x P z
  #   
  #   Infer:
  #   y owl:sameAs z
  #
  # ==== Example
  #   p = Triple.new("mit:had_academic_advisor", "rdf:type", "owl:FunctionalProperty");
  #   h = Triple.new(":Pius", "mit:had_academic_advisor", ":Hal");
  #   d = Triple.new(":Pius", "mit:had_academic_advisor", ":Dude_Who_Wrote_SICP_With_Gerald_Sussman");
  #   assert p; assert h; assert d; #=> infers a triple ~= Triple.new(":Hal", "owl:sameAs", ":Dude_Who_Wrote_SICP_With_Gerald_Sussman")
  #
  # @author Pius Uzamere
  
  def owl_functional_property
  end
  
  rule :owl_functional_property,
    [Triple,:ont_statement,{m.subject => :the_prop}, m.predicate == "rdf:type", m.object=="owl:FunctionalProperty"],
    [Triple,:fact1, {m.subject => :common_subject, m.object => :first_object}, m.predicate == b(:the_prop)],
    [Triple,:fact2, {m.object => :second_object}, m.subject == b(:common_subject), m.predicate == b(:the_prop)] do |v|

      subj = v[:fact1].object
      obj = v[:fact2].object
      
      puts "Made type inference based on owl:FunctionalProperty: Triple(#{subj}, owl:sameAs, #{obj})"
      assert Triple.new(subj, "owl:sameAs", obj)
  end
  
  ## 
  # owl:InverseFunctionalProperty
  #
  # ==== Semantics
  #   Given:
  #   P rdf:type owl:InverseFunctionalProperty
  #   z P x
  #   y P x
  #   
  #   Infer:
  #   y owl:sameAs z
  #
  # ==== Example
  #   p = Triple.new("mit:lived_alone_fall_2004_in", "rdf:type", "owl:FunctionalProperty");
  #   h = Triple.new(":Pius", "mit:lived_alone_fall_2004_in", ":pomegranate_314_at_Next_House");
  #   d = Triple.new(":2004_UA_President", "mit:lived_alone_fall_2004_in", ":pomegranate_314_at_Next_House");
  #   assert p; assert h; assert d; #=> infers a triple ~= Triple.new(":Pius", "owl:sameAs", ":2004_UA_President")
  #
  # @author Pius Uzamere
  
  def owl_inverse_functional_property
  end
  
  rule :owl_inverse_functional_property,
    [Triple,:ont_statement,{m.subject => :the_prop}, m.predicate == "rdf:type", m.object=="owl:InverseFunctionalProperty"],
    [Triple,:fact1, {m.object => :common_object, m.subject => :first_subject}, m.predicate == b(:the_prop)],
    [Triple,:fact2, {m.subject => :second_subject}, m.object == b(:common_object), m.predicate == b(:the_prop)] do |v|

      subj = v[:fact1].subject
      obj = v[:fact2].subject
      
      puts "Made type inference based on owl:InverseFunctionalProperty: Triple(#{subj}, owl:sameAs, #{obj})"
      assert Triple.new(subj, "owl:sameAs", obj)
  end

end

#rulesObject



17
18
19
20
# File 'lib/pomegranate/rdfs_plus_rulebook.rb', line 17

def rules
  rdfs_rules
  rdfs_plus_rules
end