Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for handling negations in ShEx validation #433

Merged
merged 2 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,15 @@ public Model enrichSuperClasses(Model model) throws IOException {
String getOntTerms =
"PREFIX owl: <http://www.w3.org/2002/07/owl#> "
+ "SELECT DISTINCT ?term " +
" WHERE { " +
" WHERE { " +
" { " +
" ?ind a owl:NamedIndividual . " +
" ?ind a ?term . " +
" ?ind a ?term . " +
" } " +
" UNION" +
" {" +
" ?term a owl:Class ." +
" }" +
" FILTER(?term != owl:NamedIndividual)" +
" FILTER(isIRI(?term)) ." +
" }";
Expand Down Expand Up @@ -672,9 +678,11 @@ public Set<String> getNodeTypes(Model model, String node_uri) throws IOException
String getOntTerms =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
+ "SELECT DISTINCT ?type " +
" WHERE { " +
"<"+node_uri+"> rdf:type ?type . " +
+ "SELECT DISTINCT ?type ?is_negated " +
" WHERE { " +
"{ <"+node_uri+"> rdf:type ?type . FILTER(isIRI(?type)) VALUES ?is_negated { false } }" +
"UNION" +
"{ <"+node_uri+"> rdf:type ?blank . ?blank owl:complementOf ?type . FILTER(isBlank(?blank) && isIRI(?type)) VALUES ?is_negated { true } }" +
"FILTER(?type != owl:NamedIndividual)" +
" }";
Set<String> types = new HashSet<String>();
Expand All @@ -684,7 +692,11 @@ public Set<String> getNodeTypes(Model model, String node_uri) throws IOException
while (results.hasNext()) {
QuerySolution qs = results.next();
Resource type = qs.getResource("type");
types.add(getCurie(type.getURI()));
boolean isNegated = qs.getLiteral("is_negated").getBoolean();
String typeCurie = getCurie(type.getURI());
if (isNegated) {
types.add("NOT(" + typeCurie + ")");
} else types.add(typeCurie);
// OWLClass t = tbox_reasoner.getRootOntology().getOWLOntologyManager().getOWLDataFactory().getOWLClass(IRI.create(type.getURI()));
// for(OWLClass p : tbox_reasoner.getSuperClasses(t, false).getFlattened()) {
// String type_curie = getCurie(p.getIRI().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,34 @@ public void testShexMetadata() throws IOException {
boolean should_be_valid = true;
validate("src/test/resources/validation/should_pass/", shexMeta, should_be_valid);
}

@Test
public void testHandleNegatedTermInReport() throws Exception {
validate(new File("src/test/resources/validation/model_test/ZFIN_ZDB-GENE-030131-514.ttl"), shex, true);
}

public void validate(String dir, ShexValidator shex, boolean should_be_valid) throws IOException {
public void validate(String dir, ShexValidator shex, boolean shouldBeValid) throws IOException {
File directory = new File(dir);
if(directory.isDirectory()) {
for(File file : directory.listFiles()) {
if(file.getName().endsWith("ttl")) {
Model test_model = ModelFactory.createDefaultModel();
test_model.read(file.getAbsolutePath());
System.out.println("validating "+file.getAbsolutePath()+" size "+test_model.size());
//Note that in the live system, Arachne is executed on the model prior to this step, potentially adding inferred classes that are missed with this.
//this is faster and useful for debugging the shex though. See org.geneontology.minerva.server.validation.ValidationTest in the Test branch of Minerva server for a more complete test
test_model = shex.enrichSuperClasses(test_model);
ShexValidationReport report = shex.runShapeMapValidation(test_model);
if(should_be_valid) {
assertTrue(file+" not conformant "+report.getAsText()+"\n"+report.getAsTab(""), report.isConformant());
}else {
assertFalse(file+" is conformant (should not be)", report.isConformant());
}
}
validate(file, shex, shouldBeValid);
}
}
}

private void validate(File file, ShexValidator shex, boolean shouldBeValid) throws IOException {
if(file.getName().endsWith("ttl")) {
Model test_model = ModelFactory.createDefaultModel();
test_model.read(file.getAbsolutePath());
System.out.println("validating "+file.getAbsolutePath()+" size "+test_model.size());
//Note that in the live system, Arachne is executed on the model prior to this step, potentially adding inferred classes that are missed with this.
//this is faster and useful for debugging the shex though. See org.geneontology.minerva.server.validation.ValidationTest in the Test branch of Minerva server for a more complete test
test_model = shex.enrichSuperClasses(test_model);
ShexValidationReport report = shex.runShapeMapValidation(test_model);
if(shouldBeValid) {
assertTrue(file+" not conformant "+report.getAsText()+"\n"+report.getAsTab(""), report.isConformant());
}else {
assertFalse(file+" is conformant (should not be)", report.isConformant());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
@prefix : <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514> .

<http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514> rdf:type owl:Ontology ;
owl:versionIRI <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514> ;
<http://geneontology.org/lego/modelstate> "production"^^xsd:string ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2021-07-26"^^xsd:string ;
<http://purl.org/dc/elements/1.1/title> "fkbp4 (ZFIN:ZDB-GENE-030131-514)" ;
<http://purl.org/pav/providedBy> "http://zfin.org"^^xsd:string ;
<https://w3id.org/biolink/vocab/in_taxon> <http://purl.obolibrary.org/obo/NCBITaxon_7955> .

#################################################################
# Annotation properties
#################################################################

### http://geneontology.org/lego/evidence
<http://geneontology.org/lego/evidence> rdf:type owl:AnnotationProperty .


### http://geneontology.org/lego/modelstate
<http://geneontology.org/lego/modelstate> rdf:type owl:AnnotationProperty .


### http://geneontology.org/lego/hint/layout/x
<http://geneontology.org/lego/hint/layout/x> rdf:type owl:AnnotationProperty .


### http://geneontology.org/lego/hint/layout/y
<http://geneontology.org/lego/hint/layout/y> rdf:type owl:AnnotationProperty .


### http://purl.org/dc/elements/1.1/contributor
<http://purl.org/dc/elements/1.1/contributor> rdf:type owl:AnnotationProperty .


### http://purl.org/dc/elements/1.1/date
<http://purl.org/dc/elements/1.1/date> rdf:type owl:AnnotationProperty .


### http://purl.org/dc/elements/1.1/source
<http://purl.org/dc/elements/1.1/source> rdf:type owl:AnnotationProperty .


### http://purl.org/dc/elements/1.1/title
<http://purl.org/dc/elements/1.1/title> rdf:type owl:AnnotationProperty .


### http://purl.org/pav/providedBy
<http://purl.org/pav/providedBy> rdf:type owl:AnnotationProperty .


### https://w3id.org/biolink/vocab/in_taxon
<https://w3id.org/biolink/vocab/in_taxon> rdf:type owl:AnnotationProperty .


#################################################################
# Object Properties
#################################################################

### http://purl.obolibrary.org/obo/RO_0002333
<http://purl.obolibrary.org/obo/RO_0002333> rdf:type owl:ObjectProperty .


### http://purl.obolibrary.org/obo/RO_0002418
<http://purl.obolibrary.org/obo/RO_0002418> rdf:type owl:ObjectProperty .


#################################################################
# Classes
#################################################################

### http://identifiers.org/zfin/ZDB-GENE-030131-514
<http://identifiers.org/zfin/ZDB-GENE-030131-514> rdf:type owl:Class .


### http://purl.obolibrary.org/obo/ECO_0000314
<http://purl.obolibrary.org/obo/ECO_0000314> rdf:type owl:Class .


### http://purl.obolibrary.org/obo/GO_0003674
<http://purl.obolibrary.org/obo/GO_0003674> rdf:type owl:Class .


### http://purl.obolibrary.org/obo/GO_0060765
<http://purl.obolibrary.org/obo/GO_0060765> rdf:type owl:Class .


#################################################################
# Individuals
#################################################################

### http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f2a1f833-510d-4ec6-8fac-f378b60295fb
<http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f2a1f833-510d-4ec6-8fac-f378b60295fb> rdf:type owl:NamedIndividual ,
<http://purl.obolibrary.org/obo/ECO_0000314> ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/dc/elements/1.1/source> "PMID:31661769" ;
<http://purl.org/pav/providedBy> "http://zfin.org" .


### http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f8df1fb9-8e8e-4308-b005-d1177bb42178
<http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f8df1fb9-8e8e-4308-b005-d1177bb42178> rdf:type owl:NamedIndividual ,
[ rdf:type owl:Class ;
owl:complementOf <http://purl.obolibrary.org/obo/GO_0060765>
] ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/pav/providedBy> "http://zfin.org" .


### http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/7a68dea6-060e-46ea-afe7-4b4611cd3a9d
<http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/7a68dea6-060e-46ea-afe7-4b4611cd3a9d> rdf:type owl:NamedIndividual ,
<http://purl.obolibrary.org/obo/ECO_0000314> ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/dc/elements/1.1/source> "PMID:31661769" ;
<http://purl.org/pav/providedBy> "http://zfin.org" .


### http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/712db525-58a3-4d65-994e-7cdab1fa451f
<http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/712db525-58a3-4d65-994e-7cdab1fa451f> rdf:type owl:NamedIndividual ,
<http://identifiers.org/zfin/ZDB-GENE-030131-514> ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/pav/providedBy> "http://zfin.org" .


### http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/73729ebd-5c25-4827-bccd-fad00f800e26
<http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/73729ebd-5c25-4827-bccd-fad00f800e26> rdf:type owl:NamedIndividual ,
<http://purl.obolibrary.org/obo/GO_0003674> ;
<http://purl.obolibrary.org/obo/RO_0002333> <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/712db525-58a3-4d65-994e-7cdab1fa451f> ;
<http://purl.obolibrary.org/obo/RO_0002418> <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f8df1fb9-8e8e-4308-b005-d1177bb42178> ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/pav/providedBy> "http://zfin.org"^^xsd:string .

[ rdf:type owl:Axiom ;
owl:annotatedSource <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/73729ebd-5c25-4827-bccd-fad00f800e26> ;
owl:annotatedProperty <http://purl.obolibrary.org/obo/RO_0002333> ;
owl:annotatedTarget <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/712db525-58a3-4d65-994e-7cdab1fa451f> ;
<http://geneontology.org/lego/evidence> <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/7a68dea6-060e-46ea-afe7-4b4611cd3a9d> ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/pav/providedBy> "http://zfin.org"^^xsd:string ;
rdfs:comment "ZFIN:ZDB-GENE-030131-514 NOT RO:0002264 GO:0060765 ZFIN:ZDB-PUB-191031-1|PMID:31661769 ECO:0000314 2020-08-31 ZFIN contributor-id=GOC:zfin_curators"
] .

[ rdf:type owl:Axiom ;
owl:annotatedSource <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/73729ebd-5c25-4827-bccd-fad00f800e26> ;
owl:annotatedProperty <http://purl.obolibrary.org/obo/RO_0002418> ;
owl:annotatedTarget <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f8df1fb9-8e8e-4308-b005-d1177bb42178> ;
<http://geneontology.org/lego/evidence> <http://model.geneontology.org/ZFIN_ZDB-GENE-030131-514/f2a1f833-510d-4ec6-8fac-f378b60295fb> ;
<http://purl.org/dc/elements/1.1/contributor> "GOC:zfin_curators" ;
<http://purl.org/dc/elements/1.1/date> "2020-08-31" ;
<http://purl.org/pav/providedBy> "http://zfin.org"^^xsd:string ;
rdfs:comment "ZFIN:ZDB-GENE-030131-514 NOT RO:0002264 GO:0060765 ZFIN:ZDB-PUB-191031-1|PMID:31661769 ECO:0000314 2020-08-31 ZFIN contributor-id=GOC:zfin_curators"
] .


### Generated by the OWL API (version 4.5.15) https://github.com/owlcs/owlapi