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

Relative Ontology IRI causes missing declaration #557

Closed
DaRealGunko opened this issue Aug 26, 2016 · 5 comments
Closed

Relative Ontology IRI causes missing declaration #557

DaRealGunko opened this issue Aug 26, 2016 · 5 comments
Assignees
Labels

Comments

@DaRealGunko
Copy link

DaRealGunko commented Aug 26, 2016

This code creates ClassAssertion instead of DataPropertyAssertion

OWLDataProperty prop = factory.getOWLDataProperty(IRI.create(getOntologyIRI()  + "#" +  owlDataProp));
OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(getOntologyIRI()  + "#" +  owlNamedIndividual));
OWLLiteral lit = factory.getOWLLiteral(val);

OWLDataPropertyAssertionAxiom axiom = factory.getOWLDataPropertyAssertionAxiom(prop, ind, lit);
if(manager.addAxiom(this.ontology, axiom) == ChangeApplied.SUCCESSFULLY)
    return saveOntology();
return false;

also here Stackoverflow

@ignazio1977
Copy link
Contributor

Including StackOverflow content for clarity:

CODE:

OWLDataProperty prop = factory.getOWLDataProperty(IRI.create(getOntologyIRI()  + "#" + owlDataProp));
OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(getOntologyIRI()  + "#" +  owlNamedIndividual));
OWLLiteral lit = factory.getOWLLiteral(val);

OWLDataPropertyAssertionAxiom axiom = factory.getOWLDataPropertyAssertionAxiom(prop, ind, lit);
if (manager.addAxiom(this.ontology, axiom) == ChangeApplied.SUCCESSFULLY)
    return saveOntology();
return false;

Creates an annotation assertion.

Expected result is (manually created):

data property assertion

I try to create OWLNegativeDataPropertyAssertionAxiom and it works fine. Also if I create getOWLNegativeDataPropertyAssertionAxiom first and then create OWLDataPropertyAssertionAxiom - it works.

OWLAPI: owlapi-distribution-4.1.4.jar

EDIT:

Created ontologies:

<?xml version="1.0"?>
<rdf:RDF xmlns="gunkoFB.owl#" xml:base="gunkoFB.owl" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:gunkoFB="gunkoFB.owl#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="gunkoFB.owl"/>
<owl:DatatypeProperty rdf:about="gunkoFB.owl#hasFirstName"/>
<owl:NamedIndividual rdf:about="gunkoFB.owl#Michal_Joštiak">
<hasFirstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Michal</hasFirstName>
</owl:NamedIndividual>

<?xml version="1.0"?>

<rdf:RDF xmlns="gunkoFB.owl#"
 xml:base="gunkoFB.owl"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:owl="http://www.w3.org/2002/07/owl#"
 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#">
<owl:Ontology rdf:about="gunkoFB.owl"/>

<owl:DatatypeProperty rdf:about="gunkoFB.owl#hasFirstName"/>

<owl:NamedIndividual rdf:about="gunkoFB.owl#Michal_Joštiak"/>
<rdf:Description>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NegativePropertyAssertion"/>
<owl:sourceIndividual rdf:resource="gunkoFB.owl#Michal_Joštiak"/>
<owl:assertionProperty rdf:resource="gunkoFB.owl#hasFirstName"/>
<owl:targetValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Michal</owl:targetValue>
</rdf:Description>

This case is when I save ontology as RDF/XML. Maybe its just Protege fail. When I save ontology as OWL/XML its OK again.

@ignazio1977
Copy link
Contributor

ignazio1977 commented Sep 7, 2016

My guess is RDF/XML is not storing all required declarations.

@ignazio1977 ignazio1977 added the bug label Sep 7, 2016
@ignazio1977
Copy link
Contributor

I cannot replicate the failure. The following code:

public class RDFXMLProblemWithDatapropertyTestCase extends TestBase {
@Test
public void shouldStoreDeclarationForDataproperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
    OWLDataProperty prop = df.getOWLDataProperty(IRI.create("gunkoFB.owl#hasFirstName"));
    OWLNamedIndividual ind = df.getOWLNamedIndividual(IRI.create("gunkoFB.owl#Michal_Joštiak"));
    OWLLiteral lit = df.getOWLLiteral("Michal");

    OWLDataPropertyAssertionAxiom axiom = df.getOWLDataPropertyAssertionAxiom(prop, ind, lit);
    OWLOntology o = m.createOntology(IRI.create("urn:test:ontology"));
    m.addAxiom(o, axiom);
    StringDocumentTarget save = saveOntology(o, new RDFXMLDocumentFormat());
    System.out.println(save);
    OWLOntology o2=loadOntologyFromString(save);
    for(OWLAxiom ax:o2.getAxioms()) {
        System.out.println(ax);
    }
}
}

Produces this output:

<?xml version="1.0"?>
<rdf:RDF xmlns="urn:test:ontology#"
 xml:base="urn:test:ontology"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:owl="http://www.w3.org/2002/07/owl#"
 xmlns:xml="http://www.w3.org/XML/1998/namespace"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 xmlns:gunkoFB="gunkoFB.owl#"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="urn:test:ontology"/>
<!-- gunkoFB.owl#hasFirstName -->
<owl:DatatypeProperty rdf:about="gunkoFB.owl#hasFirstName"/>
<!-- gunkoFB.owl#Michal_Joštiak -->
<owl:NamedIndividual rdf:about="gunkoFB.owl#Michal_Joštiak">
    <gunkoFB:hasFirstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Michal</gunkoFB:hasFirstName>
</owl:NamedIndividual>
</rdf:RDF>

Declaration(NamedIndividual(<gunkoFB.owl#Michal_Joštiak>))
Declaration(DataProperty(<gunkoFB.owl#hasFirstName>))
DataPropertyAssertion(<gunkoFB.owl#hasFirstName> <gunkoFB.owl#Michal_Joštiak> "Michal"^^xsd:string)

Can you provide a full sample that reproduces the error? this might be due to something else existing in the ontology.

@ignazio1977 ignazio1977 self-assigned this Sep 7, 2016
@DaRealGunko
Copy link
Author

Sample project with created owl:

GitHubBugSample.zip

@ignazio1977
Copy link
Contributor

Thanks for the code example.

When I run it, I get, for both OWLAPI 4.1.4 and 5.0.2, the following output:

<?xml version="1.0"?>
<rdf:RDF xmlns="test.owl#"
 xml:base="test.owl"
 xmlns:test="test.owl#"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:owl="http://www.w3.org/2002/07/owl#"
 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#">
<owl:Ontology rdf:about="test.owl"/>

<owl:DatatypeProperty rdf:about="test.owl#dataProp"/>

<owl:NamedIndividual rdf:about="test.owl#namedIndivindi">
    <dataProp rdf:datatype="http://www.w3.org/2001/XMLSchema#string">val</dataProp>
</owl:NamedIndividual>
</rdf:RDF>

When parsed, these axioms are found:

AnnotationAssertion(<test.owl#dataProp> <file:/Users/ignazio/workspace/GitHubBugSample/test.owl#namedIndivindi> "val"^^xsd:string)
Declaration(NamedIndividual(<file:/Users/ignazio/workspace/GitHubBugSample/test.owl#namedIndivindi>))
Declaration(DataProperty(<file:/Users/ignazio/workspace/GitHubBugSample/test.owl#dataProp>))

As it is evident, the issue is that the namespaces for the properties do not match. This is due to the ontology IRI being a relative one; the axiom property is stored as created, while the declaration is resolved to be absolute. On parsing, these no longer match, causing the OWLAPI to think the property is not declared.

As a workaround, use absolute IRIs for the ontology IRI. The IRIs should have been made absolute consistently.

static String ontologyPath = "http://test.owl";

@ignazio1977 ignazio1977 changed the title getOWLDataPropertyAssertionAxiom creates getOWLClassAssertionAxiom Relative Ontology IRI causes missing declaration Sep 9, 2016
ignazio1977 added a commit that referenced this issue Sep 9, 2016
Ontology IRIs must be absolute, not relative (it is an OWL 2 violation
for an ontology to have a relative IRI). If such an ontology is saved 
in RDF/XML to a file, parsing the file causes property declarations to
be missed (this does not happen for in memory save and parse, as there
is no base file IRI to derelativise IRIs).

As ontology IRIs must be absolute, but there is no good general strategy
to turn a relative ontology IRI in an absolute one, the approach is to
add "urn:absolute:" in front of the relative IRI. This resolves the
parsing ambiguity without throwing new exceptions.

We can't start throwing exceptions on invalid IRIs for various reasons:
first off, we are still using IRIs for representing blank nodes; second,
this would cause a large number of backwards compatibility issues with
existing ontologies. Hence the smellier approach of forcing absolute
IRIs in an arbitrary way.
ignazio1977 added a commit that referenced this issue Sep 9, 2016
Ontology IRIs must be absolute, not relative (it is an OWL 2 violation
for an ontology to have a relative IRI). If such an ontology is saved 
in RDF/XML to a file, parsing the file causes property declarations to
be missed (this does not happen for in memory save and parse, as there
is no base file IRI to derelativise IRIs).

As ontology IRIs must be absolute, but there is no good general strategy
to turn a relative ontology IRI in an absolute one, the approach is to
add "urn:absolute:" in front of the relative IRI. This resolves the
parsing ambiguity without throwing new exceptions.

We can't start throwing exceptions on invalid IRIs for various reasons:
first off, we are still using IRIs for representing blank nodes; second,
this would cause a large number of backwards compatibility issues with
existing ontologies. Hence the smellier approach of forcing absolute
IRIs in an arbitrary way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants