(in-package :cl-user) ;; Demonstration for Dan Corwin of an example from topic maps ;; Challenge: make partOf transitive (with-ontology foo () ((class !body :partial) (class !association :partial) (class !arm :partial) (class !leg :partial) (object-property !hasPart (inverse-of !partOf)) (object-property !hasWhole (inverse-of !wholeOf)) (class !bodyWithLegPart :partial (restriction !wholeOf (some-values-from (intersection-of !association (restriction !hasPart (some-values-from !leg)))))) (class !bodyWithArmPart :partial (restriction !wholeOf (some-values-from (intersection-of !association (restriction !hasPart (some-values-from !arm)))))) (equivalent-classes !bodyWithArmPart !bodyWithLegPart) (object-property !wholeOf :functional) ;; association, parts are implicit (individual !samsBodyImplicit (type !bodyWithArmPart)) ;; association(s), parts are explicit (individual !leg1 (type !leg)) (individual !arm1 (type !arm)) (individual !association1 (type !association) (value !hasPart !leg1)) (individual !association2 (type !association) (value !hasPart !arm1)) (individual !samsBodyExplicit (value !wholeOf !association1)) (individual !samsBodyExplicit (value !wholeOf !association2)) ) (format t "~%Describing !samsBodyImplicit:~%") (describe !samsBodyImplicit) (format t "~%Describing !samsBodyExplicit:~%") (describe !samsBodyExplicit) (format t "~%Describing the associate (not that association1 and association2 are merged)~%") (describe !association1) (sparql `(:select (?what ?association)(:distinct t) (?what !wholeOf ?association) (?association !hasPart ?arm) (?association !hasPart ?leg) (:filter (is-canonical ?association))) :use-reasoner :jena :trace "Use non-distinguished variables") (sparql `(:select (?what)() (?what !wholeOf :_association) (:_association !hasPart :_arm) (:_association !hasPart :_leg)) :trace "Use non-distinguished variables" )) ;; Prints: ;; Describing !samsBodyImplicit: ;; Individual http://example.com/#samsBodyImplicit ;; All Types: ex:bodyWithLegPart, ex:bodyWithArmPart ;; Direct Types: ex:bodyWithLegPart, ex:bodyWithArmPart ;; Describing !samsBodyExplicit: ;; Individual http://example.com/#samsBodyExplicit ;; ex:wholeOf: "ex:association2", "ex:association1" ;; Describing the associate (not that association1 and association2 are merged) ;; Individual http://example.com/#association1 ;; All Types: ex:association ;; Direct Types: ex:association ;; Same as: "ex:association2" ;; ex:hasPart: "ex:leg1", "ex:arm1" ;; ex:hasWhole: "ex:samsBodyExplicit" ;; Query: Use non-distinguished variables ;; PREFIX reasoning: ;; PREFIX ex: ;; SELECT DISTINCT ?what ?association ;; WHERE { ;; ?what ex:wholeOf ?association . ;; ?association ex:hasPart ?arm . ;; ?association ex:hasPart ?leg . ;; FILTER reasoning:isCanonical(?association)} ;; Results: ;; !ex:samsBodyExplicit !ex:association1 ;; Query: Use non-distinguished variables ;; PREFIX ex: ;; SELECT ?what ;; WHERE { ;; ?what ex:wholeOf _:ASSOCIATION . ;; _:ASSOCIATION ex:hasPart _:ARM . ;; _:ASSOCIATION ex:hasPart _:LEG . } ;; Results: ;; !ex:samsBodyExplicit ;; !ex:samsBodyImplicit