0
votes

I want to know if it's possible pass from an expression like this:

EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )

to this type of expression, the problem here is not shorten the IRI, the problem here is to do the translations to "and,only..." using OWLAPI:

animal 
and (eats only (not (animal)))
and (eats only (not (part_of some animal)))

The ontology that I'm using is http://owl.man.ac.uk/2006/07/sssw/people.owl and the method in that I obtain the expression is this (in this case, equivalents for vegetarian):

public static void getEquivalentClasses2() throws OWLOntologyCreationException {

    IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
    System.out.println("Loaded " + ont.getOntologyID());
    //OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory();
    OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();

    //OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
    //OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration());

    ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();

    OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);

    OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);

    Set<OWLEquivalentClassesAxiom> setEquivalentes = null;

    OWLDataFactory fac = manager.getOWLDataFactory();

    OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));

    setEquivalentes = ont.getEquivalentClassesAxioms(expr);
    String equi = "";
    for(OWLEquivalentClassesAxiom e : setEquivalentes)
    {

        System.out.println(e);

    }
}
2
Your question is a bit confusing. What you really want is the Manchester OWL syntax, and yes, there are renderers for this syntax in OWL API- That's what Protege is indeed also using. Just call the render() method on the axiom - UninformedUser
@AKSW thank you for your answer, it works for me. I didn't know that what I was looking for was the Manchester OWL syntax, I'm going to modify the question to try to clarify it. - xKukum

2 Answers

0
votes

The input expression is in Functional Syntax and unfortunately the parser for this format expects a full ontology as input, not just one axiom. You can get part of the effect you want by wrapping the string with an ontology header and output it to a Manchester Syntax format:

    String axiom =
        "EquivalentClasses(<http://owl.man.ac.uk/2006/07/sssw/people#vegetarian> ObjectIntersectionOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal> ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(<http://owl.man.ac.uk/2006/07/sssw/people#animal>)) ObjectAllValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#eats> ObjectComplementOf(ObjectSomeValuesFrom(<http://owl.man.ac.uk/2006/07/sssw/people#part_of> <http://owl.man.ac.uk/2006/07/sssw/people#animal>)))) )";
    String ontology = "Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)\n"
        + "Prefix(owl:=<http://www.w3.org/2002/07/owl#>)\n"
        + "Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)\n"
        + "Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)\n"
        + "Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)\n"
        + "Prefix(:=<http://owl.man.ac.uk/2006/07/sssw/people#>)\n"
        + "Ontology(<file:test.owl>\n" + axiom + "\n)";
    OWLOntology o = OWLManager.createOWLOntologyManager()
        .loadOntologyFromOntologyDocument(new StringDocumentSource(ontology));
    StringDocumentTarget documentTarget = new StringDocumentTarget();
    ManchesterSyntaxDocumentFormat ontologyFormat = new ManchesterSyntaxDocumentFormat();
    ontologyFormat.asPrefixOWLDocumentFormat()
        .copyPrefixesFrom(o.getFormat().asPrefixOWLDocumentFormat());
    o.saveOntology(ontologyFormat, documentTarget);
    System.out.println(documentTarget.toString());

Output is:

Prefix: : <http://owl.man.ac.uk/2006/07/sssw/people#>
Prefix: owl: <http://www.w3.org/2002/07/owl#>
Prefix: rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Prefix: rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <file:test.owl>
ObjectProperty: eats
ObjectProperty: part_of
Class: animal
Class: vegetarian
    EquivalentTo: 
        animal
         and (eats only (not (animal)))
         and (eats only (not (part_of some animal)))
0
votes

The solution that works for me was to use the ManchesterOWLSyntaxOWLObjectRendererImpl class and its method render() to convert the expression to a Manchester syntax. After the changes to solve the problem,the method stayed like this:

public static void getEquivalentClasses2() throws OWLOntologyCreationException {

    IRI iri = IRI.create("http://owl.man.ac.uk/2006/07/sssw/people.owl");

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    OWLOntology ont = manager.loadOntologyFromOntologyDocument(iri);
    System.out.println("Loaded " + ont.getOntologyID());

    Set<OWLEquivalentClassesAxiom> setEquivalentes = null;

    OWLDataFactory fac = manager.getOWLDataFactory();

    OWLClass expr = fac.getOWLClass(IRI.create("http://owl.man.ac.uk/2006/07/sssw/people#vegetarian"));

    setEquivalentes = ont.getEquivalentClassesAxioms(expr);

    ManchesterOWLSyntaxOWLObjectRendererImpl rend = new ManchesterOWLSyntaxOWLObjectRendererImpl();

    for(OWLEquivalentClassesAxiom e : setEquivalentes)
    {

        System.out.println(rend.render(e));

    }
}