Skip to content

Commit

Permalink
Add axiom annotation parsing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff authored and ignazio1977 committed May 20, 2022
1 parent 132773d commit e0e9ef7
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.semanticweb.owlapi.rio;


import org.junit.jupiter.api.Test;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

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

public class TestRDFParsingAmongMalformedAxiomAnnotations {

@Test
public void testAxiomParsing() throws OWLOntologyCreationException, IOException {
try (InputStream ttlStream = this.getClass().getResourceAsStream("/rdfParserReservedPropertiesAnnotations.ttl")) {
OWLOntology ontTTL = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(ttlStream);
assertEquals(14, ontTTL.getAxiomCount(), "Test file should have 14 axioms");
Optional<OWLAnnotation> annotationOpt = ontTTL.getAxioms().stream()
.flatMap(ax -> ax.getAnnotations().stream())
.filter(ann -> ann.getValue().isLiteral())
.filter(ann -> ann.getValue().asLiteral().get().getLiteral().equals("This assertion is annotated"))
.findAny();
assertFalse(annotationOpt.isPresent(), "Annotation should not have been added to any axiom.");
}
}

}
115 changes: 115 additions & 0 deletions contract/src/test/resources/rdfParserReservedPropertiesAnnotations.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@prefix : <http://example.org/> .
@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://example.org/> .

<http://example.org/> rdf:type owl:Ontology .

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

### http://example.org/contains
:contains rdf:type owl:ObjectProperty .


### http://example.org/has_book
:has_book rdf:type owl:ObjectProperty ;
owl:propertyChainAxiom ( :has_books
:contains
) .


### http://example.org/has_books
:has_books rdf:type owl:ObjectProperty .


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

### http://example.org/Book
:Book rdf:type owl:Class .


### http://example.org/BookOrLibrary
:BookOrLibrary rdf:type owl:Class ;
owl:equivalentClass [ rdf:type owl:Class ;
owl:unionOf ( :Book
:Library
)
] .

[ rdf:type owl:Axiom ;
owl:annotatedSource :BookOrLibrary ;
owl:annotatedProperty owl:equivalentClass ;
owl:annotatedTarget [ rdf:type owl:Class ;
owl:unionOf ( :Book
:Library
)
] ;
rdfs:comment "This equivalence axiom is annotated."
] .


### http://example.org/Library
:Library rdf:type owl:Class ;
rdfs:subClassOf [ rdf:type owl:Restriction ;
owl:onProperty :has_books ;
owl:allValuesFrom [ rdf:type owl:Restriction ;
owl:onProperty :contains ;
owl:allValuesFrom :Book
]
] .


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

### http://example.org/moby_dick
:moby_dick rdf:type owl:NamedIndividual .


### http://example.org/the_library
:the_library rdf:type owl:NamedIndividual ,
:Library .

[ rdf:type owl:Axiom ;
owl:annotatedSource :the_library ;
owl:annotatedProperty rdf:type ;
owl:annotatedTarget :Library ;
rdfs:comment "This class assertion is annotated."
] .


### http://example.org/the_republic
:the_republic rdf:type owl:NamedIndividual .

_:genid42 rdf:type owl:Axiom ;
owl:annotatedSource _:genid8 ;
owl:annotatedProperty rdf:first ;
owl:annotatedTarget :moby_dick ;
rdfs:comment "This assertion is annotated" .

# These triples should be ignored
_:genid43 rdf:type owl:Axiom ;
owl:annotatedSource _:genid8 ;
owl:annotatedProperty rdfs:first ; #Not a real property but triggers bug
owl:annotatedTarget :moby_dick ;
rdfs:comment "This assertion is annotated" .

# These triples should be ignored
_:genid44 rdf:type owl:Axiom ;
owl:annotatedSource _:genid8 ;
owl:annotatedProperty rdf:subject ;
owl:annotatedTarget :moby_dick ;
rdfs:comment "This assertion is annotated" .

_:genid8 :contains :moby_dick .


### Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi

0 comments on commit e0e9ef7

Please sign in to comment.