Search code examples
semantic-webowlowl-api

I want to know How to parse the file in OWL/XML syntax


I don't know how to parse this file, can someone tell me how to parse it? The file is on the below. I have tried to find the way to parse for about 3 days.

<?xml version="1.0"?>


<!DOCTYPE Ontology [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY ontology_people1 "http://www.okkam.org/ontology_people1.owl#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>


<Ontology xmlns="http://www.w3.org/2006/12/owl2-xml#"
     xml:base="http://www.w3.org/2006/12/owl2-xml#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:ontology_people1="http://www.okkam.org/ontology_people1.owl#"
     URI="http://www.okkam.org/ontology_people1.owl">
    <SubClassOf>
        <Class URI="&ontology_people1;Address"/>
        <Class URI="&ontology_people1;Location"/>
    </SubClassOf>
    <Declaration>
        <Class URI="&ontology_people1;Address"/>
    </Declaration>
   ......
</Ontology>



<!-- Generated by the OWL API (version 2.2.1.1138) http://owlapi.sourceforge.net -->

Solution

  • This can be parsed with the default parsers loaded by OWLAPI.

    This should be enough:

    import java.io.File;
    
    import org.semanticweb.owlapi.apibinding.OWLManager;
    import org.semanticweb.owlapi.model.OWLOntology;
    import org.semanticweb.owlapi.model.OWLOntologyCreationException;
    import org.semanticweb.owlapi.model.OWLOntologyManager;
    
    public class Check {
        public static void main(String[] args) throws OWLOntologyCreationException {
            OWLOntologyManager manager=OWLManager.createOWLOntologyManager();
            OWLOntology o=manager.loadOntologyFromOntologyDocument(new File("filename.xml"));
        }
    }