OWALAPI - переход от синтаксиса OWLEquivalentClassesAxiom к синтаксису манчестерского OWL (например, к Protege) - PullRequest
0 голосов
/ 14 ноября 2018

Я хочу знать, возможно ли перейти от выражения, подобного этому:

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>)))) )

, к этому типу выражения, проблема здесь не в том, чтобы сократить IRI, проблема здесь состоит в том, чтобы сделать переводы в«и только ...» с использованием OWLAPI:

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

Онтология, которую я использую, http://owl.man.ac.uk/2006/07/sssw/people.owl, и метод, в котором я получаю выражение, таков (в данном случае,эквиваленты для вегетарианца):

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 ]

0 голосов
/ 16 ноября 2018

Решением, которое мне помогло, было использование класса ManchesterOWLSyntaxOWLObjectRendererImpl и его метода render () для преобразования выражения в синтаксис Манчестера. После внесения изменений для решения проблемы метод оставался таким:

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));

    }
}
0 голосов
/ 16 ноября 2018

Входное выражение находится в функциональном синтаксисе, и, к сожалению, синтаксический анализатор для этого формата ожидает входную полную онтологию, а не одну аксиому.Вы можете получить часть нужного эффекта, обернув строку заголовком онтологии и выведя ее в формате синтаксиса Манчестера:

    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());

Вывод:

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)))
...