(in-package :cl-user) (def-test-fixture lsw-owl-fixture () () (:documentation "Test fixture for lsw owl testing")) (defmethod setup ((fix lsw-owl-fixture))) (defmethod teardown ((fix lsw-owl-fixture)) t) (defun must-not-be-owl-full (ontology) (when (eq (get-owl-species (kb ontology)) :owl-full) (failure "~a is OWL Full:~a" ontology (get-owl-full-features (kb ontology))))) (defmethod violate-cardinality ((test lsw-owl-fixture)) (with-ontology violate-cardinality () ((object-property !holds) (class !has-only-one :partial (restriction !holds (cardinality 1))) (individual !held1) (individual !held2) (different-individuals !held1 !held2) (individual !holder (type !has-only-one) (value !holds !held1) (value !holds !held2))) (unless (null (check violate-cardinality)) (failure "Inconsistency due to cardinality restriction not detected in ~a" violate-cardinality)) (must-not-be-owl-full violate-cardinality))) (defmethod violate-domain ((test lsw-owl-fixture)) (with-ontology violate-domain () ((class !tool :partial) (class !book :partial) (disjoint-classes !tool !book) (object-property !holds-tool (range !tool)) (class !holds-tools :partial) (individual !the-unbearable-lightness-of-being (type !book)) (individual !contrarian (type !holds-tools) (value !holds-tool !the-unbearable-lightness-of-being))) (unless (null (check violate-domain)) (failure "Should be inconsistent due to domain violation: ~a" violate-domain)) (must-not-be-owl-full violate-domain))) (defmethod violate-all-values-from ((test lsw-owl-fixture)) (with-ontology violate-all-values-from () ((class !tool :partial) (class !book :partial) (disjoint-classes !tool !book) (object-property !holds) (class !holds-tools :partial (restriction !holds (all-values-from !tool))) (individual !the-unbearable-lightness-of-being (type !book)) (individual !contrarian (type !holds-tools) (value !holds !the-unbearable-lightness-of-being))) (unless (null (check violate-all-values-from)) (failure "Should be inconsistent due to all-values-from constraint ~a" violate-all-values-from)) (must-not-be-owl-full violate-all-values-from))) (defmethod violate-has-value ((test lsw-owl-fixture)) (with-ontology violate-has-value () ((class !book :partial) (object-property !holds :functional) (individual !the-unbearable-lightness-of-being (type !book)) (individual !the-variety-of-religious-experience (type !book)) (different-individuals !the-unbearable-lightness-of-being !the-variety-of-religious-experience) (class !book-holder :partial (restriction !holds (has-value !the-unbearable-lightness-of-being))) (individual !contrarian (type !book-holder) (value !holds !the-variety-of-religious-experience))) (unless (null (check violate-has-value)) (failure "Should be inconsistent due to has-value constraint: ~a" violate-has-value)) (must-not-be-owl-full violate-has-value) )) (in-package :cl-user) (defmethod inconsistent-finite-infinite ((test lsw-owl-fixture)) (with-ontology inconsistent-finite-infinite () ((class !human :partial) (class !woman :partial) (class !man :partial) (sub-class-of !man !human) (sub-class-of !woman !human) (disjoint-classes !woman !man) (object-property !child) (object-property !father (inverse-of !child)) (sub-class-of !human (restriction !father (all-values-from !man))) (sub-class-of !human (restriction !father (cardinality 1))) (sub-class-of !human (restriction !child (max-cardinality 1))) (object-property !ssn :inverse-functional (range (one-of !one !two))) (sub-class-of !human (restriction !ssn (cardinality 1))) (individual !mary (type !woman)) (individual !one) (individual !two)) (must-not-be-owl-full inconsistent-finite-infinite) (when (check inconsistent-finite-infinite) (failure "~a should be inconsistent but the reasoner thinks it is consistent" inconsistent-finite-infinite)))) (defmethod consistent-infinite-infinite ((test lsw-owl-fixture)) (with-ontology consistent-infinite-infinite () ((class !human :partial) (class !woman :partial) (class !man :partial) (sub-class-of !man !human) (sub-class-of !woman !human) (disjoint-classes !woman !man) (object-property !child) (object-property !father (inverse-of !child)) (sub-class-of !human (restriction !father (all-values-from !man))) (sub-class-of !human (restriction !father (cardinality 1))) (sub-class-of !human (restriction !child (max-cardinality 1))) (object-property !ssn :inverse-functional) (sub-class-of !human (restriction !ssn (cardinality 1))) (individual !mary (type !woman))) (must-not-be-owl-full consistent-infinite-infinite) (when (not (check consistent-infinite-infinite)) (failure "~a should be consistent but the reasoner thinks it is inconsistent" consistent-infinite-infinite)))) (defmethod query-non-distinguished-variable ((test lsw-owl-fixture)) (with-ontology some-exists? () ((object-property !holds) (class !holder :partial (restriction !holds (min-cardinality 1))) (individual !alan (type !holder))) (let ((*default-kb* (kb some-exists?))) (unless (and (null (sparql '(:select (?who)() (?who !ex:holds ?what)) :use-reasoner :pellet)) (sparql '(:select (?who)() (?who !ex:holds [])) :use-reasoner :pellet)) (failure "distinguished variable query should return nothing, non-distinguished !alan"))))) (eval '(with-import-redirect "http://www.reactome.org/cgi-bin/biopaxexporter?DB=gk_current&ID=109581" "owl:tests;reactome-109581-apoptosis-2006-05-05.owl" (with-import-redirect "http://www.biopax.org/release/biopax-level2.owl" "owl:tests;biopax-level2-2005-05-05.owl" (define-ontology test-biopax+pathway-participants (:base "http://www.biopax.org/prototype") (ontology-annotation !owl:imports !) (ontology-annotation !owl:imports !) (object-property !PARTICIPANTS* :transitive) (sub-property-of !bp2:PARTICIPANTS !PARTICIPANTS*) (sub-property-of !bp2:PATHWAY-COMPONENTS !PARTICIPANTS*) (sub-property-of !bp2:STEP-INTERACTIONS !PARTICIPANTS*) (sub-property-of !bp2:PHYSICAL-ENTITY !PARTICIPANTS*) (sub-property-of !bp2:COMPONENTS !PARTICIPANTS*))))) (defmethod test-biopax+pathway-participants-not-owl-full ((test lsw-owl-fixture)) (must-not-be-owl-full test-biopax+pathway-participants)) (defmethod count-apoptosis-proteins ((test lsw-owl-fixture)) (let ((*default-kb* test-biopax+pathway-participants)) (let ((howmany (length (sparql `(:select (?protein) (:distinct t) (!reactome:Apoptosis ! ?part) (?protein !rdf:type !bp2:protein)) :use-reasoner :jena ))) (expected 38)) (unless (= expected howmany) (failure "Expected to find ~a proteins in the apoptosis pathway, but found ~a" expected howmany))))) (defmethod count-protein-pathways ((test lsw-owl-fixture)) (let ((*default-kb* test-biopax+pathway-participants)) (let* ((expected 5) (the-protein !reactome:UniProt_P45983_1_Mitogen_activated_protein_kinase_8__EC_2_7_1_37___Stress_activated_protein_kinase_JNK1___c_Jun_N_terminal_kinase_1___JNK_46_) (howmany (length (sparql `(:select (?name) (:distinct t) (?pathway ! ,the-protein) (?pathway !rdf:type !bp2:pathway) (?pathway !bp2:NAME ?name) ) :use-reasoner :jena )))) (unless (= expected howmany) (failure "Expected to find ~a pathways that ~a participated in, but found ~a" expected the-protein howmany))))) (defmethod make-sure-we-can-detect-owl-full ((test lsw-owl-fixture)) (with-ontology full () ((object-property !foo (range !xsd:int))) (unless (and (eq (get-owl-species (kb full)) :owl-full) (some (lambda(message) (search "Invalid Range Restriction" message)) (get-owl-full-features (kb full)))) (failure "Should have detected that a object property make an ontology owl full. Report says:~%~{~a~%~}" (get-owl-full-features (kb full)))))) (defmethod check-datatype-range ((test lsw-owl-fixture)) (with-ontology data () ((datatype-property !hasFloat (range !xsd:float)) (individual !a (type !owl:Thing) (value !hasFloat "1.9"))) (multiple-value-bind (is reason) (consistent data) (unless (and (not is) (search "does not belong to datatype" (second reason))) (failure "Didn't complain that about an untyped literal when a float was expected"))))) (defmethod test-hierarchy ((test lsw-owl-fixture)) (let ((small-piece-of-go (list !go:GO_0000060 (list !go:GO_0000189 !go:GO_0000201 !go:GO_0000208) !go:GO_0007184 !go:GO_0007262 (list !go:GO_0035105 !go:GO_0006993))) (all-of-them (list !go:GO_0000060 !go:GO_0000189 !go:GO_0000201 !go:GO_0000208 !go:GO_0007184 !go:GO_0007262 !go:GO_0035105 !go:GO_0006993))) (with-ontology type-hierarchy () ((value-partition small-piece-of-go :disjoint nil :covering nil)) (let ((result (sparql '(:select (?term) () (?term !rdfs:subClassOf !go:GO_0000060) (:filter (not (equal ?term !owl:Nothing)))) :use-reasoner :jena :kb (kb type-hierarchy) :flatten t))) (when (or (not (= (length result) (length all-of-them))) (set-difference result all-of-them)) (failure "type-hierarchy query failed: returned ~a instead of ~a" result all-of-them)))) (with-ontology existential-hierarchy () ((object-property !go:go_isa :transitive ) (existential-hierarchy !go:go_isa small-piece-of-go ) (class !go:probe :complete (restriction !go:go_isa (some-values-from !go:GO_0000060)))) (let ((result (cons !go:GO_0000060 (sparql '(:select (?term) () (?term !rdfs:subClassOf !go:probe) (:filter (and (not (equal ?term !owl:Nothing)) (not (equal ?term !go:probe))))) :use-reasoner :jena :kb (kb existential-hierarchy) :flatten t )))) (when (or (not (= (length result) (length all-of-them))) (set-difference result all-of-them)) (failure "existential-hierarchy probe-class query failed: returned ~a instead of ~a" result all-of-them)) (setq result (cons !go:GO_0000060 (descendants (restriction !go:go_isa (some-values-from !go:GO_0000060)) (kb existential-hierarchy)))) (when (or (not (= (length result) (length all-of-them))) (set-difference result all-of-them)) (failure "existential-hierarchy probe-class query failed: returned ~a instead of ~a" result all-of-them)))) (with-ontology individual-hierarchy () ((class !go:term :partial) (object-property !go:go_isa :transitive) (individual-hierarchy !go:term !go:go_isa small-piece-of-go)) (let ((result (cons !go:GO_0000060 (sparql '(:select (?term) (:distinct t) (?term !go:go_isa !go:GO_0000060)) :use-reasoner :jena :kb (kb individual-hierarchy) :flatten t)))) (when (or (not (= (length result) (length all-of-them))) (set-difference result all-of-them)) (failure "individual-hierarchy query failed: returned ~a instead of ~a" result all-of-them)))))) ;; this is to test a bug in the CorrectedRDFRenderer or the abstract parser. #| (defmethod no-structure-sharing-generated ((test lsw-owl-fixture)) (with-ontology structure-sharing () ((class !Tr :partial) (class !G :partial !Tr) (class !D :partial) (class !S :partial !D) (object-property !p) (property-property !p (object-property !T)) (class !p1 :complete (restriction !p (some-values-from !S))) (class !p2 :complete (restriction '(!p !T (some-values-from !G)) (some-values-from !S))) ) (unless (equal (get-owl-species (kb structure-sharing)) :owl-dl) (failure "Structure sharing is being generated from abstract syntax")) ) (let ((*shared-structure-workaround* nil)) (with-ontology structure-sharing () ((class !Tr :partial) (class !G :partial !Tr) (class !D :partial) (class !S :partial !D) (object-property !p) (property-property !p (object-property !T)) (class !p1 :complete (restriction !p (some-values-from !S))) (class !p2 :complete (restriction '(!p !T (some-values-from !G)) (some-values-from !S))) ) (when (equal (get-owl-species (kb structure-sharing)) :owl-dl) (failure "Structure sharing workaround is no longer needed.")) ))) |# (defparameter *a-and-b-have-same-bnode* " ]> ") (defmethod cyclic-bnodes ((test lsw-owl-fixture)) (let* ((rdf " ]> ") (kb (load-kb-jena-from-string rdf 'cyclic-bnodes))) (unless (equal (get-owl-species kb) :owl-full) (failure "Pellet bug: cyclic bnode is ~a instead of OWL-FULL" (get-owl-species kb))))) (defmethod shared-bnode ((test lsw-owl-fixture)) (let* ((rdf " ]> ") (kb (load-kb-jena-from-string rdf 'cyclic-bnodes))) (unless (equal (get-owl-species kb) :owl-full) (failure "Pellet bug: shared-bnode is ~a instead of OWL-FULL" (get-owl-species kb))))) (defparameter lsw-owl-test-suite (simple-test-suite "OWL Test Suite" "Test that OWL inferencing is working" lsw-owl-fixture test-hierarchy make-sure-we-can-detect-owl-full cyclic-bnodes shared-bnode violate-has-value violate-domain violate-all-values-from violate-cardinality consistent-infinite-infinite inconsistent-finite-infinite query-non-distinguished-variable check-datatype-range test-biopax+pathway-participants-not-owl-full count-apoptosis-proteins count-protein-pathways #|no-structure-sharing-generated|#)) (pushnew 'lsw-owl-test-suite *all-lsw-test-suites*)