owlcs / owlapi

OWL API main repository
821 stars 315 forks source link

unexpected behavior with malformed triples #1056

Open balhoff opened 2 years ago

balhoff commented 2 years ago

I'm not sure this is exactly a bug, since the input isn't fully correct OWL. But the behavior is unexpected: if an ontology includes an annotated axiom using a reserved term as the annotated property, an annotation for this axiom is placed on some other completely unrelated axiom. I would instead expect these triples to be left over as "unparsed triples". Here is an example input causing this behavior:

@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/p
:p rdf:type owl:ObjectProperty ;
   rdfs:subPropertyOf :q .

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

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

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

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

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

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

# Here are the triples causing the bad behavior
_:blank1 rdf:type owl:Axiom ;
   owl:annotatedSource _:blank2 ;
   owl:annotatedProperty rdf:first ;
   owl:annotatedTarget :x ;
   rdfs:comment "This rdf:first assertion is annotated" .

You can test the result using ROBOT like this:

robot convert -i input.ttl -o output.ofn

output.ofn will look like this:

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#>)

Ontology(<http://example.org/>

Declaration(Class(:A))
Declaration(ObjectProperty(:p))
Declaration(ObjectProperty(:q))

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

# Object Property: :p (:p)

SubObjectPropertyOf(Annotation(rdfs:comment "This rdf:first assertion is annotated") :p :q)
)

The rdfs:comment is randomly attached to the SubObjectPropertyOf axiom.