Skip to content

Commit

Permalink
OBO serialisation illegal axiom annotation (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkir-dev authored and ignazio1977 committed Feb 19, 2023
1 parent 97cca47 commit 0176cf8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.semanticweb.owlapi.obolibrarytest.oboformat;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -20,6 +25,7 @@
import org.semanticweb.owlapi.obolibrary.oboformat.model.Clause;
import org.semanticweb.owlapi.obolibrary.oboformat.model.Frame;
import org.semanticweb.owlapi.obolibrary.oboformat.model.OBODoc;
import org.semanticweb.owlapi.obolibrary.oboformat.writer.OBOFormatWriter;
import org.semanticweb.owlapi.vocab.OBOFormatConstants.OboFormatTag;
import org.semanticweb.owlapi.vocab.Obo2OWLConstants;
import org.semanticweb.owlapi.vocab.Obo2OWLConstants.Obo2OWLVocabulary;
Expand Down Expand Up @@ -170,4 +176,21 @@ void testOwl2OboProperty() {
assertTrue(comment.isPresent());
assertEquals(COMMENT, comment.get().getLiteral());
}

@Test
void testIllegalOWLAxiomConversion() throws IOException {
File illegalOWLFile = getFile("illegal_property.owl");

OWLOntology illegalOntology = loadFrom(illegalOWLFile);
OBODoc oboDoc = convert(illegalOntology);

OBOFormatWriter writer = new OBOFormatWriter();
StringWriter stringWriter = new StringWriter();
BufferedWriter bw = new BufferedWriter(stringWriter);
writer.write(oboDoc, bw);

String illegalOutput = "{http://www.w3.org/1999/02/22-rdf-syntax-ns#type=\"owl:Axiom\"}";
assertFalse(stringWriter.toString().contains(illegalOutput),
String.format("Ilegal output '%s' exists in the output", illegalOutput));
}
}
39 changes: 39 additions & 0 deletions contract/src/test/resources/obo/illegal_property.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.obolibrary.org/obo/fbbt/fbbt-simple.owl#"
xml:base="http://purl.obolibrary.org/obo/fbbt/fbbt-simple.owl"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#">
<owl:Ontology rdf:about="http://purl.obolibrary.org/obo/fbbt/fbbt-simple.owl">
</owl:Ontology>

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115">
<obo:IAO_0000114 rdf:resource="http://purl.obolibrary.org/obo/IAO_0000122"/>
<rdfs:label>definition</rdfs:label>
</owl:AnnotationProperty>

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasDbXref">
<rdfs:label>database_cross_reference</rdfs:label>
</owl:AnnotationProperty>

<!-- THIS AXIOM IS ILLEGAL -->
<owl:AnnotationProperty rdf:about="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"/>

<owl:Class rdf:about="http://purl.obolibrary.org/obo/FBbt_00000006">
<obo:IAO_0000115>Any segment (FBbt:00000003) that is part of some head (FBbt:00000004).</obo:IAO_0000115>
<oboInOwl:hasDbXref>UBERON:6000006</oboInOwl:hasDbXref>
</owl:Class>
<owl:Axiom>
<owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/FBbt_00000006"/>
<owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/>
<owl:annotatedTarget>Any segment (FBbt:00000003) that is part of some head (FBbt:00000004).</owl:annotatedTarget>
<oboInOwl:hasDbXref>FlyBase:FBrf0075072</oboInOwl:hasDbXref>
</owl:Axiom>

</rdf:RDF>

<!-- See: https://github.com/ontodev/robot/issues/1089 -->
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ public static Map<String, String> annotationPropertyMap() {
Obo2OWLConstants.DEFAULT_IRI_PREFIX + "IAO_synonymtypedef";
private static final String IRI_CLASS_SUBSETDEF =
Obo2OWLConstants.DEFAULT_IRI_PREFIX + "IAO_subsetdef";
private static final Set<String> SKIPPED_QUALIFIERS =
new HashSet<>(Arrays.asList("gci_relation", "gci_filler", CARDINALITY, MIN_CARDINALITY,
MAX_CARDINALITY, "all_some", ALL_ONLY));
// RDF_TYPE added to guard against scenario when a syntactic triple is
// accidentally interpreted as an annotation.
// See https://github.com/ontodev/robot/issues/1089 for context
private static final Set<String> SKIPPED_QUALIFIERS = new HashSet<>(
Arrays.asList("gci_relation", "gci_filler", CARDINALITY, MIN_CARDINALITY, MAX_CARDINALITY,
"all_some", ALL_ONLY, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
protected final Pattern absoluteURLPattern = Pattern.compile("<\\s*http.*?>");
protected final Set<OWLAxiom> untranslatableAxioms = new HashSet<>();
protected final Map<String, String> idSpaceMap = new HashMap<>();
Expand Down

0 comments on commit 0176cf8

Please sign in to comment.