OWL-API: define owl format based on string content

I have owl files with various formats (RDF / XML, Turtle, Manchester OWL Syntax). I want to define a format based on its contents, since the other format has its own style.

eg

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, although I have two files with the same name myOntology.owl , I can determine its format based on the above content (just by opening it in an editor). How to do this using the OWL-API in JAVA? Also, how are they distinguished by loading methods from OWLOntologyManager ?

0
source share
1 answer

Unfortunately, OWL serializations do not have explicit markers, as other formats do.

The OWL API is simply trying to use all the formats that it knows about until it passes; it is not always effective, but there is no other way to do it.

On the other hand, the vast majority of parsers detect errors in several lines of the beginning. Thus, the failure occurs rather quickly.

To successfully load ontologies, you can access the actual format using the getFormat () method.

0
source

All Articles