本文介绍了OWL-API:根据其字符串内容识别猫头鹰格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同格式(RDF/XML,Turtle,Manchester OWL语法)的猫头鹰文件.我想根据其内容来识别格式,因为不同的格式都有其自己的风格.

I have owl files with different formats (RDF/XML , Turtle, Manchester OWL Syntax). I want to identify the format based on its contents as different format has its own style.

例如

RDF/XML:

<?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="namespace#"
xml:base="namespace"
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="namespace"/>
<!-- namespace#my1 -->
<owl:ObjectProperty rdf:about="namespace#my1"/>
<!-- namespace#my2 -->
<owl:ObjectProperty rdf:about="namespace#my2"/>
<!-- namespace#prop1 -->
<owl:DatatypeProperty rdf:about="namespace#prop1"/>
<!-- namespace#prop2 -->
<owl:DatatypeProperty rdf:about="namespace#prop2"/>
<!-- namespace#A -->
<owl:Class rdf:about="namespace#A"/>
<!-- namespace#B -->
<owl:Class rdf:about="namespace#B"/>
<!-- namespace#C -->
<owl:Class rdf:about="namespace#C"/>
<!-- namespace#P -->
<owl:Class rdf:about="namespace#P"/>
</rdf:RDF>

曼彻斯特OWL语法:

Prefix: : <namespace#>
Prefix: owl: <http://www.w3.org/2002/07/owl#>
Prefix: rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Prefix: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Prefix: rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Ontology: <namespace>
ObjectProperty: my2
ObjectProperty: my1
DataProperty: prop2
DataProperty: prop1
Class: B
Class: A
Class: P 
Class: C

因此,即使我有两个具有相同名称的文件myOntology.owl,我也可以根据上述内容(仅通过在编辑器中打开)识别其格式.如何在JAVA中使用OWL-API做到这一点?还有OWLOntologyManager的加载方法如何区分它们?

So even though I have two files having same name myOntology.owl I can identify its format based of above contents (by just opening in editor). How to do this using OWL-API in JAVA ? Also how load methods from OWLOntologyManager differentiates them ?

推荐答案

不幸的是,OWL序列化没有其他格式那样的显式标记.

Unfortunately the OWL serializations do not have explicit markers like other formats do.

OWL API只会尝试它知道的所有格式,直到通过为止.这并不总是有效的,但是没有其他方法可以做到这一点.

OWL API just tries all formats it knows about until one passes; this is not always efficient but there is no other way of doing this.

另一方面,绝大多数解析器将在开始的几行内检测到错误.因此失败相当快.

On the other hand, the vast majority of parsers will detect errors within a few lines of the start. So failure is fairly fast.

要成功加载本体,可以使用getFormat()访问实际格式.

For ontologies loading successfully, you can access the actual format with getFormat().

这篇关于OWL-API:根据其字符串内容识别猫头鹰格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:27