将字符串转换为复杂的OWL公理

时间:2015-03-09 17:28:12

标签: java parsing owl owl-api

我正在尝试使用基于this示例的OWLFunctionalSyntaxParser将字符串解析回OWL Axioms。这适用于简单的公理,例如: ObjectPropertyAssertionAxiom。对于以下公理(为了清楚起见,前缀:是URL的缩写)

EquivalentClasses(<prefix:LeucocytesRestricted> ObjectIntersectionOf(<prefix:Leucocytes> DataSomeValuesFrom(<prefix:hasLeucocytesValue> DataRangeRestriction(xsd:double facetRestriction(minInclusive \"20.0\"^^xsd:double)))) )

我收到以下异常

org.coode.owlapi.functionalparser.ParseException: Encountered "" at line 1, column 260.
Was expecting one of:

    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.generateParseException(OWLFunctionalSyntaxParser.java:5335)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.jj_consume_token(OWLFunctionalSyntaxParser.java:5194)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.DataRange(OWLFunctionalSyntaxParser.java:761)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.DataSomeValuesFrom(OWLFunctionalSyntaxParser.java:531)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.ClassExpression(OWLFunctionalSyntaxParser.java:310)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.ClassExpressionSet(OWLFunctionalSyntaxParser.java:339)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.ObjectIntersectionOf(OWLFunctionalSyntaxParser.java:383)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.ClassExpression(OWLFunctionalSyntaxParser.java:290)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.ClassExpressionSet(OWLFunctionalSyntaxParser.java:339)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.EquivalentClasses(OWLFunctionalSyntaxParser.java:932)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.ClassAxiom(OWLFunctionalSyntaxParser.java:901)
    at org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.Axiom(OWLFunctionalSyntaxParser.java:867)
    at be.ugent.ontal.ontology.ConflictDetector.stringToAxiom(ConflictDetector.java:125)
    at be.ugent.ontal.ontology.ConflictDetector.addClassAxiom(ConflictDetector.java:74)
    at be.ugent.ontal.facade.command.AddClassAxiomCommand.execute(AddClassAxiomCommand.java:27)
    at be.ugent.ontal.facade.Invoker.storeAndExecute(Invoker.java:13)
    at be.ugent.ontal.facade.MyWebSocket.onText(MyWebSocket.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:71)
    at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:68)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextMessage(JettyAnnotatedEventDriver.java:209)
    at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextFrame(JettyAnnotatedEventDriver.java:201)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)
    at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:309)
    at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)
    at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)
    at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:613)
    at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:468)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
    at java.lang.Thread.run(Thread.java:745)

我也尝试过parser.EquivalentClasses(),但这也不起作用。他们以任何方式解析如此复杂的表达方式吗?最终目标是让一个OWLEquivalentClassesAxiom对象代表这个字符串。

提前致谢!

编辑:

这是我目前使用的代码

InputStream in = new ByteArrayInputStream(axiom.getBytes());

OWLFunctionalSyntaxParser parser = new OWLFunctionalSyntaxParser(in);
parser.setUp(ontology, new OWLOntologyLoaderConfiguration());

try {
    System.out.println(axiom);
    output.add(parser.Axiom());
} catch(Exception e) {
    e.printStackTrace();
}

1 个答案:

答案 0 :(得分:1)

我怀疑输入流中存在语法错误。我做了一个随机的例子,它似乎正在起作用:

    String axiom="EquivalentClasses(:TestPizza ObjectIntersectionOf(DataMinCardinality(20 :hasToppingValue xsd:double) :Pizza))";
    InputStream in = new ByteArrayInputStream(axiom.getBytes());

    OWLFunctionalSyntaxParser parser;
    parser = new OWLFunctionalSyntaxParser(in);
    parser.setUp(localOntology,new OWLOntologyLoaderConfiguration());
    DefaultPrefixManager nsm=new DefaultPrefixManager("http://www.co-ode.org/ontologies/pizza/pizza.owl#");
    parser.setPrefixes(nsm);
     try {
        OWLClassAxiom temp=parser.EquivalentClasses();
        System.out.println(axiom);
        System.out.println(temp);
    } catch ( ParseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }