Skip to content

Commit

Permalink
Migrated OWLAPI Ontodriver to OWLAPI 5.1.3 (latest).
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Dec 17, 2017
1 parent ad2ea6c commit c6f3a16
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 202 deletions.
Expand Up @@ -23,6 +23,8 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

public class ClassObjectPropertyComputer {

Expand Down Expand Up @@ -53,15 +55,15 @@ public ClassObjectPropertyComputer(final OWLClass clazz,
final OWLDataFactory f = merged.getOWLOntologyManager().getOWLDataFactory();

final OWLClass object = filler;
final Set<OWLClassExpression> superClasses = EntitySearcher.getSuperClasses(object, merged).collect(
Collectors.toSet());

if (EntitySearcher.getSuperClasses(object, merged)
.anyMatch(sc -> sc.equals(f.getOWLClass(IRI.create(SequencesVocabulary.c_List))))) {
if (superClasses.contains(f.getOWLClass(IRI.create(SequencesVocabulary.c_List)))) {
this.filler = new ClassObjectPropertyComputer(object,
f.getOWLObjectProperty(IRI.create(SequencesVocabulary.p_element)),
set, merged).getFiller();
card = Card.LIST;
} else if (EntitySearcher.getSuperClasses(object, merged).anyMatch(
sc -> sc.equals(f.getOWLClass(IRI.create(SequencesVocabulary.c_OWLSimpleList))))) {
} else if (superClasses.contains(f.getOWLClass(IRI.create(SequencesVocabulary.c_OWLSimpleList)))) {
this.filler = new ClassObjectPropertyComputer(object,
f.getOWLObjectProperty(IRI.create(SequencesVocabulary.p_hasNext)),
set, merged).getFiller();
Expand Down
Expand Up @@ -192,8 +192,7 @@ public void generateVocabulary(String context, String pkg, String targetDir, boo
verifyContextExistence(context);
}
ContextDefinition def = (context == null) ? DEFAULT_CONTEXT : contexts.get(context);
new JavaTransformer().
generateVocabulary(ontology, def, pkg, targetDir, withOWLAPI);
new JavaTransformer().generateVocabulary(ontology, def, pkg, targetDir, withOWLAPI);
}

private class ValidContextAnnotationValueVisitor implements OWLAnnotationValueVisitor {
Expand Down
1 change: 0 additions & 1 deletion ontodriver-owlapi/pom.xml
Expand Up @@ -16,7 +16,6 @@
</parent>

<properties>
<net.sourceforge.owlapi.version>4.2.4</net.sourceforge.owlapi.version>
<cz.cvut.kbss.owl2query.version>0.4.0</cz.cvut.kbss.owl2query.version>
</properties>

Expand Down
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2016 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -26,6 +26,7 @@

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class EpistemicAxiomRemover {

Expand Down Expand Up @@ -65,8 +66,7 @@ void remove(AxiomDescriptor descriptor) {
}

private Collection<OWLOntologyChange> removeClassAssertionAxioms(OWLNamedIndividual individual) {
final Collection<OWLClassExpression> types = EntitySearcher.getTypes(individual, ontology);
return types.stream().map(cls -> new MutableRemoveAxiom(ontology,
return EntitySearcher.getTypes(individual, ontology).map(cls -> new MutableRemoveAxiom(ontology,
dataFactory.getOWLClassAssertionAxiom(cls, individual))).collect(Collectors.toList());
}

Expand All @@ -81,8 +81,8 @@ private Collection<OWLOntologyChange> removeClassAssertionAxioms(OWLNamedIndivid
private Collection<? extends OWLOntologyChange> removeDataPropertyAssertions(OWLNamedIndividual individual,
Assertion assertion) {
final OWLDataProperty dataProperty = dataFactory.getOWLDataProperty(IRI.create(assertion.getIdentifier()));
final Collection<OWLLiteral> values = EntitySearcher.getDataPropertyValues(individual, dataProperty, ontology);
return values.stream().map(value -> new MutableRemoveAxiom(ontology,
final Stream<OWLLiteral> values = EntitySearcher.getDataPropertyValues(individual, dataProperty, ontology);
return values.map(value -> new MutableRemoveAxiom(ontology,
dataFactory.getOWLDataPropertyAssertionAxiom(dataProperty, individual, value)))
.collect(Collectors.toList());
}
Expand All @@ -102,9 +102,8 @@ private Collection<? extends OWLOntologyChange> removeDataPropertyAssertions(OWL
private Collection<? extends OWLOntologyChange> removeObjectPropertyAssertions(OWLNamedIndividual individual,
Assertion assertion) {
final OWLObjectProperty objProperty = dataFactory.getOWLObjectProperty(IRI.create(assertion.getIdentifier()));
final Collection<OWLIndividual> values = EntitySearcher
.getObjectPropertyValues(individual, objProperty, ontology);
return values.stream().filter(OWLIndividual::isNamed).map(value -> new MutableRemoveAxiom(ontology,
final Stream<OWLIndividual> values = EntitySearcher.getObjectPropertyValues(individual, objProperty, ontology);
return values.filter(OWLIndividual::isNamed).map(value -> new MutableRemoveAxiom(ontology,
dataFactory.getOWLObjectPropertyAssertionAxiom(objProperty, individual, value)))
.collect(Collectors.toList());
}
Expand All @@ -125,9 +124,9 @@ private Collection<? extends OWLOntologyChange> removeAnnotationAssertions(OWLNa
Assertion assertion) {
final OWLAnnotationProperty annProperty = dataFactory
.getOWLAnnotationProperty(IRI.create(assertion.getIdentifier()));
final Collection<OWLAnnotationAssertionAxiom> values = EntitySearcher
.getAnnotationAssertionAxioms(individual.getIRI(), ontology);
return values.stream().filter(axiom -> axiom.getProperty().equals(annProperty))
final Stream<OWLAnnotationAssertionAxiom> values =
EntitySearcher.getAnnotationAssertionAxioms(individual.getIRI(), ontology);
return values.filter(axiom -> axiom.getProperty().equals(annProperty))
.map(value -> new MutableRemoveAxiom(ontology, value)).collect(Collectors.toList());
}

Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.net.URI;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class ExplicitAxiomLoader implements AxiomLoader {

Expand Down Expand Up @@ -56,21 +57,18 @@ public Collection<Axiom<?>> loadAxioms(NamedResource subject, Set<Assertion> ass
axioms.addAll(adapter.getTypesHandler().getTypes(subject, null, false));
}
// This involves a lot of filtering, perhaps we should use EntitySearcher and look for values of concrete properties
final Collection<OWLDataPropertyAssertionAxiom> dpAssertions = ontology.getDataPropertyAssertionAxioms(
individual);
final Stream<OWLDataPropertyAssertionAxiom> dpAssertions = ontology.dataPropertyAssertionAxioms(individual);
axioms.addAll(dataPropertyValuesToAxioms(subject, dpAssertions));
final Collection<OWLObjectPropertyAssertionAxiom> opAssertions = ontology.getObjectPropertyAssertionAxioms(
individual);
final Stream<OWLObjectPropertyAssertionAxiom> opAssertions = ontology.objectPropertyAssertionAxioms(individual);
axioms.addAll(objectPropertyValuesToAxioms(subject, opAssertions));
final Collection<OWLAnnotationAssertionAxiom> apAssertions = ontology.getAnnotationAssertionAxioms(
individual.getIRI());
final Stream<OWLAnnotationAssertionAxiom> apAssertions = ontology.annotationAssertionAxioms(individual.getIRI());
axioms.addAll(annotationPropertyValuesToAxioms(subject, apAssertions));
return axioms;
}

private Collection<Axiom<?>> dataPropertyValuesToAxioms(NamedResource subject,
Collection<OWLDataPropertyAssertionAxiom> axioms) {
return axioms.stream().filter(this::shouldLoadDataPropertyValue)
Stream<OWLDataPropertyAssertionAxiom> axioms) {
return axioms.filter(this::shouldLoadDataPropertyValue)
.map(axiom -> axiomAdapter.toAxiom(subject, axiom, false))
.collect(Collectors.toList());
}
Expand All @@ -95,16 +93,16 @@ private boolean doesPropertyExist(IRI o) {
}

private Collection<Axiom<?>> objectPropertyValuesToAxioms(NamedResource subject,
Collection<OWLObjectPropertyAssertionAxiom> axioms) {
return axioms.stream().filter(axiom ->
Stream<OWLObjectPropertyAssertionAxiom> axiomStream) {
return axiomStream.filter(axiom ->
doesPropertyExist(axiom.getProperty().asOWLObjectProperty().getIRI()))
.map(axiom -> axiomAdapter.toAxiom(subject, axiom, false))
.collect(Collectors.toList());
}

private Collection<Axiom<?>> annotationPropertyValuesToAxioms(NamedResource subject,
Collection<OWLAnnotationAssertionAxiom> axioms) {
return axioms.stream().filter(this::shouldLoadAnnotationPropertyValue)
Stream<OWLAnnotationAssertionAxiom> axioms) {
return axioms.filter(this::shouldLoadAnnotationPropertyValue)
.map(axiom -> axiomAdapter.toAxiom(subject, axiom, false))
.collect(Collectors.toList());
}
Expand All @@ -127,11 +125,11 @@ private boolean shouldLoadAnnotationPropertyValue(OWLAnnotationAssertionAxiom ax
public Collection<Axiom<?>> loadPropertyAxioms(NamedResource subject) {
final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory);
final Collection<Axiom<?>> axioms = new ArrayList<>();
ontology.getDataPropertyAssertionAxioms(individual)
ontology.dataPropertyAssertionAxioms(individual)
.forEach(assertion -> axioms.add(axiomAdapter.toAxiom(subject, assertion, false)));
ontology.getObjectPropertyAssertionAxioms(individual)
ontology.objectPropertyAssertionAxioms(individual)
.forEach(assertion -> axioms.add(axiomAdapter.toAxiom(subject, assertion, false)));
ontology.getAnnotationAssertionAxioms(individual.getIRI())
ontology.annotationAssertionAxioms(individual.getIRI())
.forEach(assertion -> axioms.add(axiomAdapter.toAxiom(subject, assertion, false)));
return axioms;
}
Expand Down
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2016 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -14,15 +14,16 @@
*/
package cz.cvut.kbss.ontodriver.owlapi;

import cz.cvut.kbss.ontodriver.model.*;
import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
import cz.cvut.kbss.ontodriver.owlapi.exception.ReasonerNotAvailableException;
import cz.cvut.kbss.ontodriver.owlapi.util.OwlapiUtils;
import cz.cvut.kbss.ontodriver.model.*;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasoner;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class InferredAxiomLoader implements AxiomLoader {

Expand Down Expand Up @@ -92,9 +93,9 @@ private OWLDataProperty dataProperty(Assertion dataPropertyAssertion) {
}

private Collection<Axiom<?>> inferObjectPropertyValues(OWLNamedIndividual individual, Assertion opAssertion) {
final Set<OWLNamedIndividual> individuals = reasoner.getObjectPropertyValues(individual,
objectProperty(opAssertion)).getFlattened();
return individuals.stream().map(
final Stream<OWLNamedIndividual> individuals =
reasoner.getObjectPropertyValues(individual, objectProperty(opAssertion)).entities();
return individuals.map(
target -> axiomAdapter.createAxiom(subject, opAssertion, NamedResource.create(target.getIRI().toURI())))
.collect(
Collectors.toList());
Expand All @@ -108,21 +109,19 @@ private OWLObjectProperty objectProperty(Assertion objectPropertyAssertion) {
public Collection<Axiom<?>> loadPropertyAxioms(NamedResource subject) {
final Collection<Axiom<?>> axioms = new ArrayList<>();
final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory);
for (OWLDataProperty dp : ontology.getDataPropertiesInSignature()) {
ontology.dataPropertiesInSignature().forEach(dp -> {
final Set<OWLLiteral> values = reasoner.getDataPropertyValues(individual, dp);
for (OWLLiteral literal : values) {
axioms.add(axiomAdapter.createAxiom(subject,
Assertion.createDataPropertyAssertion(dp.getIRI().toURI(), true), literal));
}
}
for (OWLObjectProperty op : ontology.getObjectPropertiesInSignature()) {
final Set<OWLNamedIndividual> values = reasoner.getObjectPropertyValues(individual, op).getFlattened();
for (OWLNamedIndividual ind : values) {
axioms.add(axiomAdapter.createAxiom(subject,
Assertion.createObjectPropertyAssertion(op.getIRI().toURI(), true), NamedResource.create(
ind.getIRI().toURI())));
}
}
});
ontology.objectPropertiesInSignature().forEach(op -> {
final Assertion opAss = Assertion.createObjectPropertyAssertion(op.getIRI().toURI(), true);
reasoner.getObjectPropertyValues(individual, op).entities()
.forEach(ind -> axioms
.add(axiomAdapter.createAxiom(subject, opAss, NamedResource.create(ind.getIRI().toURI()))));
});
return axioms;
}
}
Expand Up @@ -54,7 +54,7 @@ Set<Axiom<URI>> getTypes(NamedResource subject, URI context, boolean includeInfe
}

private Collection<OWLClassExpression> loadExplicitClasses(NamedResource subject) {
return EntitySearcher.getTypes(getIndividual(subject), ontology);
return EntitySearcher.getTypes(getIndividual(subject), ontology).collect(Collectors.toSet());
}

private OWLNamedIndividual getIndividual(NamedResource subject) {
Expand All @@ -70,7 +70,7 @@ private Set<Axiom<URI>> owlClassesToAxioms(NamedResource subject, boolean inferr

private Collection<? extends OWLClassExpression> inferClasses(NamedResource subject) {
final OWLNamedIndividual individual = getIndividual(subject);
return reasoner.getTypes(individual, false).getFlattened();
return reasoner.getTypes(individual, false).entities().collect(Collectors.toSet());
}

void addTypes(NamedResource subject, URI context, Set<URI> types) {
Expand Down
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2016 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -14,12 +14,12 @@
*/
package cz.cvut.kbss.ontodriver.owlapi.list;

import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
import cz.cvut.kbss.ontodriver.model.NamedResource;
import cz.cvut.kbss.ontodriver.owlapi.AxiomAdapter;
import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
import cz.cvut.kbss.ontodriver.owlapi.exception.ReasonerNotAvailableException;
import cz.cvut.kbss.ontodriver.owlapi.util.OwlapiUtils;
import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
import cz.cvut.kbss.ontodriver.model.NamedResource;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntologyChange;
Expand All @@ -29,6 +29,7 @@
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

class InferredReferencedListIterator extends ReferencedListIterator {

Expand All @@ -55,16 +56,18 @@ public boolean hasNext() {

@Override
void doStep() {
final Collection<OWLNamedIndividual> nextNodes = reasoner
.getObjectPropertyValues(currentNode, currentNextNodeProperty).getFlattened();
final Collection<OWLNamedIndividual> nextNodes =
reasoner.getObjectPropertyValues(currentNode, currentNextNodeProperty).entities()
.collect(Collectors.toSet());
if (nextNodes.isEmpty()) {
this.next = Collections.emptyList();
return;
}
checkMaxSuccessors(currentNextNodeProperty, nextNodes);
this.currentNextNodeProperty = hasNextProperty;
this.currentNode = nextNodes.iterator().next();
this.next = reasoner.getObjectPropertyValues(currentNode, hasContentProperty).getFlattened();
this.next = reasoner.getObjectPropertyValues(currentNode, hasContentProperty).entities()
.collect(Collectors.toSet());
}

@Override
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

/**
* This class differs from the way basic SimpleListIterator iterates over the list. Here, we do step before even calling
Expand Down Expand Up @@ -63,7 +64,7 @@ public boolean hasNext() {
@Override
void doStep() {
final NodeSet<OWLNamedIndividual> nodeSet = reasoner.getObjectPropertyValues(currentNode, currentProperty);
this.next = nodeSet.isEmpty() ? Collections.emptySet() : nodeSet.getFlattened();
this.next = nodeSet.isEmpty() ? Collections.emptySet() : nodeSet.entities().collect(Collectors.toSet());
this.previousProperty = currentProperty;
this.currentProperty = hasNextProperty;
this.previousNode = this.currentNode;
Expand Down
Expand Up @@ -104,7 +104,7 @@ private class ReferencedListNodeGenerator {
private int index;
private Assertion property;

public ReferencedListNodeGenerator(NamedResource baseUri, Assertion nodeContent) {
ReferencedListNodeGenerator(NamedResource baseUri, Assertion nodeContent) {
this.baseUri = baseUri.toString() + "-SEQ_";
this.changes = new ArrayList<>();
this.nodeContentProperty = nodeContent;
Expand Down

0 comments on commit c6f3a16

Please sign in to comment.