0

I want to add new axiom into ontology, for that I created method which converts String [which is in Manchester OWL Syntax] into OWLClassExpression using ManchesterOWLSyntaxParser and later form new OWLAxiom and add to Ontology.

But I am getting following Exception (org.semanticweb.owlapi.manchestersyntax.renderer.ParserException) :-

Exception in thread "main" org.semanticweb.owlapi.manchestersyntax.renderer.ParserException: Encountered owl:real at line 1 column 12. Expected one of:
    Datatype name
    not
    {

    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl$ExceptionBuilder.build(ManchesterOWLSyntaxParserImpl.java:2441)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataRangePrimary(ManchesterOWLSyntaxParserImpl.java:813)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataUnionOf(ManchesterOWLSyntaxParserImpl.java:756)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataIntersectionOf(ManchesterOWLSyntaxParserImpl.java:737)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataRange(ManchesterOWLSyntaxParserImpl.java:729)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseDataRestriction(ManchesterOWLSyntaxParserImpl.java:695)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseNonNaryClassExpression(ManchesterOWLSyntaxParserImpl.java:584)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseIntersection(ManchesterOWLSyntaxParserImpl.java:488)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseUnion(ManchesterOWLSyntaxParserImpl.java:511)
    at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseClassExpression(ManchesterOWLSyntaxParserImpl.java:470)
    at OWLAPI.convertStringToClassExpression(OWLAPI.java:29)

Following is my Ontology :-

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www.semanticweb.org/empty#"
     xml:base="http://www.semanticweb.org/empty"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/empty"/>
    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Data properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->
    <!-- http://www.semanticweb.org/empty#name -->
    <owl:DatatypeProperty rdf:about="http://www.semanticweb.org/empty#name"/>
    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Classes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->
    <!-- http://www.semanticweb.org/empty#A -->
    <owl:Class rdf:about="http://www.semanticweb.org/empty#A"/>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.5.1) http://owlapi.sourceforge.net -->

My JAVA code is :-

// some code above to form OWLManager and Ontology
System.out.println(convertStringToClassExpression("name max 1 owl:real"));
private OWLClassExpression convertStringToClassExpression(String expression) {
        ManchesterOWLSyntaxParser parser = OWLManager.createManchesterParser();
        parser.setStringToParse(expression);
        parser.setDefaultOntology(owlOntology); // my ontology
        ShortFormEntityChecker checker = new ShortFormEntityChecker(getShortFormProvider());
        parser.setOWLEntityChecker(checker);
        return parser.parseClassExpression();
    }
private BidirectionalShortFormProvider getShortFormProvider() {
        Set<OWLOntology> ontologies = owlManager.getOntologies(); // my OWLOntologyManager
        ShortFormProvider sfp = new ManchesterOWLSyntaxPrefixNameShortFormProvider(
                owlManager.getOntologyFormat(owlOntology));
        BidirectionalShortFormProvider shortFormProvider = new BidirectionalShortFormProviderAdapter(
                ontologies, sfp);
        return shortFormProvider;
    }

But if I change my String from name max 1 owl:real to name max 1 xsd:string then there is no exception thrown from code. What's the problem ? How to avoid it ?

SuhasD
  • 728
  • 2
  • 7
  • 20
  • 1
    `ManchesterOWLSyntaxParserImpl` (currently) doesn't handle the OWL 2 datatypes `owl:real` and `owl:rational`. Is using `float` or `xsd:double` an option for your use case (their values spaces are pairwise disjoint by definition, however)? – dhke Aug 19 '16 at 07:33
  • Ok. So how protege handles this case? I can add `name max 1 owl:real` as an ClassExpression to any axiom. Did I miss something (I mean extra processing , wrong implementation) ? – SuhasD Aug 19 '16 at 08:20
  • Which versions of the OWLAPI did you try? Newest Protègé has 4.2.5, you have 3.5.1 marked in your ontology, but upstream is already at 5.0.1. I just verified that 4.0.2 has no `owl:real` support. – dhke Aug 19 '16 at 08:29
  • I am using OWLAPI 4.1.3 and protege 5.0.0 (uses OWLAPI 3.5.1). So I guess OWLAPI doesnt have support yet. – SuhasD Aug 19 '16 at 08:46
  • Can you add it as an issue on the owlapi bug tracker? – Ignazio Aug 19 '16 at 09:21
  • @Ignazio Added to bug tracker https://github.com/owlcs/owlapi/issues/556 – SuhasD Aug 19 '16 at 10:02

1 Answers1

0

This is an OWLAPI bug, fixed in the current trunk versions. The fix will be released in 4.2.6 and 5.0.3, once they are completed and published on Maven Central.

Ignazio
  • 10,504
  • 1
  • 14
  • 25