0

我想将新的公理添加到本体中,为此我创建了将String[在Manchester OWL Syntax中的] 转换为OWLClassExpressionusingManchesterOWLSyntaxParser并随后形成新的OWLAxiom并添加到本体的方法。

但我得到以下异常(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)

以下是我的本体:-

<?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 -->

我的JAVA代码是:-

// 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;
    }

但是,如果我将字符串从 更改为name max 1 owl:realname max 1 xsd:string则代码不会引发异常。有什么问题 ?如何避免呢?

4

1 回答 1

0

这是一个 OWLAPI 错误,已在当前主干版本中修复。修复将在 4.2.6 和 5.0.3 中发布,一旦它们完成并在 Maven Central 上发布。

于 2016-09-07T19:17:33.093 回答