问题
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.
E.g
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>
Manchester OWL Syntax :
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
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 ?
回答1:
Unfortunately the OWL serializations do not have explicit markers like other formats do.
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.
For ontologies loading successfully, you can access the actual format with getFormat().
来源:https://stackoverflow.com/questions/38349636/owl-api-identify-owl-format-based-on-its-string-contents