开发者

parsing owl file

Thanks for the previous posts. That helped a lot in parsing the owl file. Please look at the following code.

        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

        OWLDataFactory factory = manager.getOWLDataFactory();

        File file = new File("sample.owl");

        OWLOntology localOntology = manager.loadOntologyFromOntologyDocument(file)开发者_运维问答;
        System.out.println("Loaded ontology: " + localOntology);

        IRI documentIRI = manager.getOntologyDocumentIRI(localOntology);
        System.out.println("    from: " + documentIRI);


        OWLClass clsAMethodA = factory.getOWLClass(documentIRI);

The examples stated in the documentation of owl uses IRI that right now doesnot exists. I am not understanding how do i extract all classes of the owl file. Where should i save the classes. How do i go about in saving those classes?? Any help?


You need to import the OWL API and then follow a code like mine. I am getting all the logical axioms. From axioms, you can extract other modelling elements such as classes and individuals.

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology localOntology=null;

    File file=new File("ontology/pizza.owl");
    if (file == null)
        return;

    //loading the ontology
    try {
        localOntology = manager.loadOntologyFromOntologyDocument(file);
    } catch (OWLOntologyCreationException e) {
        e.printStackTrace();
    }


            //get logical axioms
    Set<OWLLogicalAxiom> ax = localOntology.getLogicalAxioms();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜