Question

Is there a way to Convert an OWL axiom to Manchester Syntax? I know that the OWL-API will allow you to parse a sentence in Manchester Syntax into OWL functional syntax, but I need to do exactly the opposite.

Was it helpful?

Solution

Thanks a lot for pointing me in the right direction, this is how I solved my problem.

public static void main(String[] args) throws ParserException, OWLOntologyCreationException {

    File file=new File("ontology/pizza.owl");
    OWLOntologyManager manager;
    OWLOntology localOntology=null;
    OWLDataFactory factory ;

    try {


        //loading the ontology
        manager=OWLManager.createOWLOntologyManager();

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

        factory = localOntology.getOWLOntologyManager().getOWLDataFactory();

        OWLOntologyFormat format = manager.getOntologyFormat(localOntology);
        System.out.println("    format: " + format);

        ManchesterOWLSyntaxOntologyFormat manSyntaxFormat = new ManchesterOWLSyntaxOntologyFormat();
        if(format.isPrefixOWLOntologyFormat()) {
            manSyntaxFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
        }

        manager.setOntologyFormat(localOntology, manSyntaxFormat);
        manager.saveOntology(localOntology, manSyntaxFormat);
        System.out.println("Manchester syntax: --- saved in Manchester.owl");

        ManchesterOWLSyntaxOWLObjectRendererImpl rendering = new ManchesterOWLSyntaxOWLObjectRendererImpl();

        OWLClass c1 = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#IceCream"));

        Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Equivalent: "+rendering.render(c1e));

        c1eqclasses = c1.getDisjointClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Disjoint: "+rendering.render(c1e));

        c1eqclasses = c1.getSubClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Subclass: "+rendering.render(c1e));

        c1eqclasses = c1.getSuperClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Superclass: "+rendering.render(c1e));



    }
    catch (OWLOntologyStorageException e) {
        System.out.println("Could not save ontology: " + e.getMessage());
    }



}

OTHER TIPS

The OWL-API allows you also to read an ontology written in functional syntax and to convert it into Manchester syntax.

Example of code to write an ontology as file serialised in Manchester syntax:

File file = new File("/home/foo/bar.owl");
OWLOntologyFormat format = manager.getOntologyFormat(ontology);
ManchesterOWLSyntaxOntologyFormat manSyntaxFormat =
                                         new ManchesterOWLSyntaxOntologyFormat();
manager.saveOntology(ontology, manSyntaxFormat, IRI.create(file));

manager and ontology are standard objects from the OWL-API.

In the new version of OWL API (I use 4.0.1) , use these methods

Set<OWLEquivalentAxiom> axioms = localOntology.getEquivalentClassesAxiom(c1);

instead

Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);

Similarly for other calls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top