diff --git a/src/sparql/taxon-constraints-never-in-taxon-annotation.rq b/src/sparql/taxon-constraints-never-in-taxon-annotation.rq index 7b489cbba4..b973c8f11d 100644 --- a/src/sparql/taxon-constraints-never-in-taxon-annotation.rq +++ b/src/sparql/taxon-constraints-never-in-taxon-annotation.rq @@ -42,16 +42,34 @@ WHERE { FILTER(STRENDS(STR(?taxon_complement), "#NOT")) BIND(IRI(STRBEFORE(STR(?taxon_complement), "#NOT")) AS ?taxon) FILTER ( - EXISTS { - ?term rdfs:subClassOf+ [ - a owl:Restriction ; - owl:onProperty in_taxon: ; - owl:someValuesFrom ?super_taxon - ] . - FILTER(!STRENDS(STR(?super_taxon), "#NOT")) - ?taxon rdfs:subClassOf+ ?super_taxon . - } + # only include computed never-in-taxon if... + ( + # there is a computed in-taxon that is a superclass of the never... + EXISTS { + ?term rdfs:subClassOf+ [ + a owl:Restriction ; + owl:onProperty in_taxon: ; + owl:someValuesFrom ?super_taxon + ] . + FILTER(!STRENDS(STR(?super_taxon), "#NOT")) + ?taxon rdfs:subClassOf+ ?super_taxon . + } + && + # and there is not another computed in-taxon that is not a superclass of the never... + NOT EXISTS { + ?term rdfs:subClassOf+ [ + a owl:Restriction ; + owl:onProperty in_taxon: ; + owl:someValuesFrom ?super_taxon + ] . + FILTER(!STRENDS(STR(?super_taxon), "#NOT")) + FILTER NOT EXISTS { + ?taxon rdfs:subClassOf+ ?super_taxon . + } + } + ) || + # or else if there are no computed in-taxon NOT EXISTS { ?term rdfs:subClassOf+ [ a owl:Restriction ;