OWLAPI : "ParserException" while converting String to Class Expression using ManchesterOWLSyntaxParser

377 Views Asked by At

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 ?

1

There are 1 best solutions below

0
Ignazio On

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.