From c6f3a16a5fe32ef8362125d90272421aae37dc97 Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Sun, 17 Dec 2017 16:40:57 +0100 Subject: [PATCH] Migrated OWLAPI Ontodriver to OWLAPI 5.1.3 (latest). --- .../owl2java/ClassObjectPropertyComputer.java | 10 +- .../jopa/owl2java/OWL2JavaTransformer.java | 3 +- ontodriver-owlapi/pom.xml | 1 - .../owlapi/EpistemicAxiomRemover.java | 23 ++-- .../owlapi/ExplicitAxiomLoader.java | 28 +++-- .../owlapi/InferredAxiomLoader.java | 31 +++-- .../kbss/ontodriver/owlapi/TypesHandler.java | 4 +- .../list/InferredReferencedListIterator.java | 17 +-- .../list/InferredSimpleListIterator.java | 3 +- .../owlapi/list/ReferencedListHandler.java | 2 +- .../owlapi/list/ReferencedListIterator.java | 27 +++-- .../owlapi/list/SimpleListIterator.java | 24 ++-- .../ontodriver/owlapi/util/OwlapiUtils.java | 16 +-- .../ontodriver/owlapi/AxiomAdapterTest.java | 6 +- .../owlapi/EpistemicAxiomRemoverTest.java | 38 ++++--- .../owlapi/MainAxiomLoaderTest.java | 107 ++++++++++-------- .../ontodriver/owlapi/OwlapiAdapterTest.java | 47 ++++---- .../owlapi/PropertiesHandlerTest.java | 40 +++---- .../owlapi/util/OwlapiUtilsTest.java | 6 + 19 files changed, 231 insertions(+), 202 deletions(-) diff --git a/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/ClassObjectPropertyComputer.java b/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/ClassObjectPropertyComputer.java index 42eeb0f72..c94442668 100644 --- a/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/ClassObjectPropertyComputer.java +++ b/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/ClassObjectPropertyComputer.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; public class ClassObjectPropertyComputer { @@ -53,15 +55,15 @@ public ClassObjectPropertyComputer(final OWLClass clazz, final OWLDataFactory f = merged.getOWLOntologyManager().getOWLDataFactory(); final OWLClass object = filler; + final Set 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(); diff --git a/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/OWL2JavaTransformer.java b/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/OWL2JavaTransformer.java index da6037cb9..3b0bf3463 100644 --- a/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/OWL2JavaTransformer.java +++ b/jopa-owl2java/src/main/java/cz/cvut/kbss/jopa/owl2java/OWL2JavaTransformer.java @@ -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 { diff --git a/ontodriver-owlapi/pom.xml b/ontodriver-owlapi/pom.xml index 305f8cf72..7b9bbe35e 100644 --- a/ontodriver-owlapi/pom.xml +++ b/ontodriver-owlapi/pom.xml @@ -16,7 +16,6 @@ - 4.2.4 0.4.0 diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemover.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemover.java index 0823f05eb..ea9b2c8e5 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemover.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemover.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -26,6 +26,7 @@ import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; class EpistemicAxiomRemover { @@ -65,8 +66,7 @@ void remove(AxiomDescriptor descriptor) { } private Collection removeClassAssertionAxioms(OWLNamedIndividual individual) { - final Collection 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()); } @@ -81,8 +81,8 @@ private Collection removeClassAssertionAxioms(OWLNamedIndivid private Collection removeDataPropertyAssertions(OWLNamedIndividual individual, Assertion assertion) { final OWLDataProperty dataProperty = dataFactory.getOWLDataProperty(IRI.create(assertion.getIdentifier())); - final Collection values = EntitySearcher.getDataPropertyValues(individual, dataProperty, ontology); - return values.stream().map(value -> new MutableRemoveAxiom(ontology, + final Stream values = EntitySearcher.getDataPropertyValues(individual, dataProperty, ontology); + return values.map(value -> new MutableRemoveAxiom(ontology, dataFactory.getOWLDataPropertyAssertionAxiom(dataProperty, individual, value))) .collect(Collectors.toList()); } @@ -102,9 +102,8 @@ private Collection removeDataPropertyAssertions(OWL private Collection removeObjectPropertyAssertions(OWLNamedIndividual individual, Assertion assertion) { final OWLObjectProperty objProperty = dataFactory.getOWLObjectProperty(IRI.create(assertion.getIdentifier())); - final Collection values = EntitySearcher - .getObjectPropertyValues(individual, objProperty, ontology); - return values.stream().filter(OWLIndividual::isNamed).map(value -> new MutableRemoveAxiom(ontology, + final Stream values = EntitySearcher.getObjectPropertyValues(individual, objProperty, ontology); + return values.filter(OWLIndividual::isNamed).map(value -> new MutableRemoveAxiom(ontology, dataFactory.getOWLObjectPropertyAssertionAxiom(objProperty, individual, value))) .collect(Collectors.toList()); } @@ -125,9 +124,9 @@ private Collection removeAnnotationAssertions(OWLNa Assertion assertion) { final OWLAnnotationProperty annProperty = dataFactory .getOWLAnnotationProperty(IRI.create(assertion.getIdentifier())); - final Collection values = EntitySearcher - .getAnnotationAssertionAxioms(individual.getIRI(), ontology); - return values.stream().filter(axiom -> axiom.getProperty().equals(annProperty)) + final Stream values = + EntitySearcher.getAnnotationAssertionAxioms(individual.getIRI(), ontology); + return values.filter(axiom -> axiom.getProperty().equals(annProperty)) .map(value -> new MutableRemoveAxiom(ontology, value)).collect(Collectors.toList()); } diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/ExplicitAxiomLoader.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/ExplicitAxiomLoader.java index d9408565d..a1298c7fc 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/ExplicitAxiomLoader.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/ExplicitAxiomLoader.java @@ -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 { @@ -56,21 +57,18 @@ public Collection> loadAxioms(NamedResource subject, Set 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 dpAssertions = ontology.getDataPropertyAssertionAxioms( - individual); + final Stream dpAssertions = ontology.dataPropertyAssertionAxioms(individual); axioms.addAll(dataPropertyValuesToAxioms(subject, dpAssertions)); - final Collection opAssertions = ontology.getObjectPropertyAssertionAxioms( - individual); + final Stream opAssertions = ontology.objectPropertyAssertionAxioms(individual); axioms.addAll(objectPropertyValuesToAxioms(subject, opAssertions)); - final Collection apAssertions = ontology.getAnnotationAssertionAxioms( - individual.getIRI()); + final Stream apAssertions = ontology.annotationAssertionAxioms(individual.getIRI()); axioms.addAll(annotationPropertyValuesToAxioms(subject, apAssertions)); return axioms; } private Collection> dataPropertyValuesToAxioms(NamedResource subject, - Collection axioms) { - return axioms.stream().filter(this::shouldLoadDataPropertyValue) + Stream axioms) { + return axioms.filter(this::shouldLoadDataPropertyValue) .map(axiom -> axiomAdapter.toAxiom(subject, axiom, false)) .collect(Collectors.toList()); } @@ -95,16 +93,16 @@ private boolean doesPropertyExist(IRI o) { } private Collection> objectPropertyValuesToAxioms(NamedResource subject, - Collection axioms) { - return axioms.stream().filter(axiom -> + Stream axiomStream) { + return axiomStream.filter(axiom -> doesPropertyExist(axiom.getProperty().asOWLObjectProperty().getIRI())) .map(axiom -> axiomAdapter.toAxiom(subject, axiom, false)) .collect(Collectors.toList()); } private Collection> annotationPropertyValuesToAxioms(NamedResource subject, - Collection axioms) { - return axioms.stream().filter(this::shouldLoadAnnotationPropertyValue) + Stream axioms) { + return axioms.filter(this::shouldLoadAnnotationPropertyValue) .map(axiom -> axiomAdapter.toAxiom(subject, axiom, false)) .collect(Collectors.toList()); } @@ -127,11 +125,11 @@ private boolean shouldLoadAnnotationPropertyValue(OWLAnnotationAssertionAxiom ax public Collection> loadPropertyAxioms(NamedResource subject) { final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory); final Collection> 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; } diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/InferredAxiomLoader.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/InferredAxiomLoader.java index d60858ee8..1938afa06 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/InferredAxiomLoader.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/InferredAxiomLoader.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -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 { @@ -92,9 +93,9 @@ private OWLDataProperty dataProperty(Assertion dataPropertyAssertion) { } private Collection> inferObjectPropertyValues(OWLNamedIndividual individual, Assertion opAssertion) { - final Set individuals = reasoner.getObjectPropertyValues(individual, - objectProperty(opAssertion)).getFlattened(); - return individuals.stream().map( + final Stream individuals = + reasoner.getObjectPropertyValues(individual, objectProperty(opAssertion)).entities(); + return individuals.map( target -> axiomAdapter.createAxiom(subject, opAssertion, NamedResource.create(target.getIRI().toURI()))) .collect( Collectors.toList()); @@ -108,21 +109,19 @@ private OWLObjectProperty objectProperty(Assertion objectPropertyAssertion) { public Collection> loadPropertyAxioms(NamedResource subject) { final Collection> axioms = new ArrayList<>(); final OWLNamedIndividual individual = OwlapiUtils.getIndividual(subject, dataFactory); - for (OWLDataProperty dp : ontology.getDataPropertiesInSignature()) { + ontology.dataPropertiesInSignature().forEach(dp -> { final Set 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 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; } } diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/TypesHandler.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/TypesHandler.java index 432f240d8..f2a81e3e4 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/TypesHandler.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/TypesHandler.java @@ -54,7 +54,7 @@ Set> getTypes(NamedResource subject, URI context, boolean includeInfe } private Collection loadExplicitClasses(NamedResource subject) { - return EntitySearcher.getTypes(getIndividual(subject), ontology); + return EntitySearcher.getTypes(getIndividual(subject), ontology).collect(Collectors.toSet()); } private OWLNamedIndividual getIndividual(NamedResource subject) { @@ -70,7 +70,7 @@ private Set> owlClassesToAxioms(NamedResource subject, boolean inferr private Collection 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 types) { diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredReferencedListIterator.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredReferencedListIterator.java index f09dea214..f5965448c 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredReferencedListIterator.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredReferencedListIterator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -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; @@ -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 { @@ -55,8 +56,9 @@ public boolean hasNext() { @Override void doStep() { - final Collection nextNodes = reasoner - .getObjectPropertyValues(currentNode, currentNextNodeProperty).getFlattened(); + final Collection nextNodes = + reasoner.getObjectPropertyValues(currentNode, currentNextNodeProperty).entities() + .collect(Collectors.toSet()); if (nextNodes.isEmpty()) { this.next = Collections.emptyList(); return; @@ -64,7 +66,8 @@ void doStep() { 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 diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredSimpleListIterator.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredSimpleListIterator.java index b2270e167..d8aaf9fec 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredSimpleListIterator.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/InferredSimpleListIterator.java @@ -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 @@ -63,7 +64,7 @@ public boolean hasNext() { @Override void doStep() { final NodeSet 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; diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListHandler.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListHandler.java index 855063199..532a2932e 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListHandler.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListHandler.java @@ -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; diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListIterator.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListIterator.java index f2177406e..91a0296c2 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListIterator.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/ReferencedListIterator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -26,6 +26,8 @@ import org.semanticweb.owlapi.search.EntitySearcher; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; class ReferencedListIterator extends OwlapiListIterator { @@ -63,12 +65,14 @@ class ReferencedListIterator extends OwlapiListIterator { @Override public boolean hasNext() { - return !EntitySearcher.getObjectPropertyValues(currentNode, currentNextNodeProperty, ontology).isEmpty(); + return EntitySearcher.getObjectPropertyValues(currentNode, currentNextNodeProperty, ontology) + .anyMatch(e -> true); } void doStep() { - final Collection nextNodes = EntitySearcher - .getObjectPropertyValues(currentNode, currentNextNodeProperty, ontology); + final Collection nextNodes = + EntitySearcher.getObjectPropertyValues(currentNode, currentNextNodeProperty, ontology) + .collect(Collectors.toSet()); if (nextNodes.isEmpty()) { this.next = Collections.emptyList(); return; @@ -80,7 +84,8 @@ void doStep() { checkIsNamed(node); this.previousNode = currentNode; this.currentNode = node; - this.next = EntitySearcher.getObjectPropertyValues(node, hasContentProperty, ontology); + this.next = + EntitySearcher.getObjectPropertyValues(node, hasContentProperty, ontology).collect(Collectors.toSet()); } @Override @@ -122,12 +127,10 @@ List removeWithoutReconnect() { } private OWLIndividual getNextNode() { - final Collection nextOnes = EntitySearcher - .getObjectPropertyValues(currentNode, currentNextNodeProperty, ontology); - if (nextOnes.isEmpty()) { - return null; - } - return nextOnes.iterator().next(); + final Stream nextOnes = + EntitySearcher.getObjectPropertyValues(currentNode, currentNextNodeProperty, ontology); + final Iterator it = nextOnes.iterator(); + return it.hasNext() ? it.next() : null; } @Override diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/SimpleListIterator.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/SimpleListIterator.java index 5b081e916..6ee401997 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/SimpleListIterator.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/list/SimpleListIterator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -26,10 +26,8 @@ import org.semanticweb.owlapi.model.*; import org.semanticweb.owlapi.search.EntitySearcher; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.NoSuchElementException; +import java.util.*; +import java.util.stream.Collectors; class SimpleListIterator extends OwlapiListIterator { @@ -60,11 +58,12 @@ class SimpleListIterator extends OwlapiListIterator { @Override public boolean hasNext() { - return !EntitySearcher.getObjectPropertyValues(currentNode, currentProperty, ontology).isEmpty(); + return EntitySearcher.getObjectPropertyValues(currentNode, currentProperty, ontology).anyMatch(v -> true); } void doStep() { - this.next = EntitySearcher.getObjectPropertyValues(currentNode, currentProperty, ontology); + this.next = EntitySearcher.getObjectPropertyValues(currentNode, currentProperty, ontology) + .collect(Collectors.toSet()); this.previousProperty = currentProperty; this.currentProperty = hasNextProperty; this.previousNode = this.currentNode; @@ -143,11 +142,8 @@ private OWLOntologyChange connectToNextNode(OWLNamedIndividual newNode) { } private OWLIndividual getNextNode() { - final Collection nextOnes = EntitySearcher - .getObjectPropertyValues(currentNode, currentProperty, ontology); - if (nextOnes.isEmpty()) { - return null; - } - return nextOnes.iterator().next(); + final Iterator nextOnes = + EntitySearcher.getObjectPropertyValues(currentNode, currentProperty, ontology).iterator(); + return nextOnes.hasNext() ? nextOnes.next() : null; } } diff --git a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtils.java b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtils.java index db29e59a0..a855fc539 100644 --- a/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtils.java +++ b/ontodriver-owlapi/src/main/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtils.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -15,7 +15,10 @@ package cz.cvut.kbss.ontodriver.owlapi.util; import cz.cvut.kbss.ontodriver.model.NamedResource; -import org.semanticweb.owlapi.model.*; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; import org.semanticweb.owlapi.vocab.OWL2Datatype; import java.net.URI; @@ -95,6 +98,7 @@ public static Object owlLiteralToValue(final OWLLiteral literal) { return Float.parseFloat(literal.getLiteral()); case XSD_STRING: case RDF_XML_LITERAL: + case RDF_LANG_STRING: return literal.getLiteral(); case XSD_BOOLEAN: return Boolean.parseBoolean(literal.getLiteral()); @@ -126,11 +130,7 @@ public static Object owlLiteralToValue(final OWLLiteral literal) { public static boolean doesLanguageMatch(OWLLiteral literal, String language) { assert literal != null; - final OWLDatatype datatype = literal.getDatatype(); - if (datatype.isBuiltIn() && datatype.isString() || datatype.isRDFPlainLiteral()) { - return language == null || literal.getLang().isEmpty() || literal.getLang().equals(language); - } - return true; + return language == null || literal.getLang().isEmpty() || literal.getLang().equals(language); } /** diff --git a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/AxiomAdapterTest.java b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/AxiomAdapterTest.java index d748e7dad..0a4773abf 100644 --- a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/AxiomAdapterTest.java +++ b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/AxiomAdapterTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -14,7 +14,6 @@ */ package cz.cvut.kbss.ontodriver.owlapi; -import com.google.common.base.Optional; import cz.cvut.kbss.ontodriver.model.*; import cz.cvut.kbss.ontodriver.owlapi.environment.Generator; import org.junit.Before; @@ -26,6 +25,7 @@ import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import java.net.URI; +import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemoverTest.java b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemoverTest.java index b8d5833b7..f3f85e708 100644 --- a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemoverTest.java +++ b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/EpistemicAxiomRemoverTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -31,6 +31,7 @@ import java.net.URI; import java.util.*; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -82,7 +83,7 @@ public void removeAxiomsByDescriptorWithClassAssertions() { descriptor.addAssertion(clsAssertion); initClassAssertions(); axiomRemover.remove(descriptor); - assertTrue(ontology.getClassAssertionAxioms(individual).isEmpty()); + assertTrue(ontology.classAssertionAxioms(individual).collect(Collectors.toSet()).isEmpty()); final ArgumentCaptor captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List changes = captor.getValue(); @@ -107,7 +108,8 @@ public void removeAxiomsByDescriptorWithDataPropertyAssertions() { final OWLDataProperty odp = dataFactory.getOWLDataProperty(IRI.create(dpAssertion.getIdentifier())); descriptor.addAssertion(dpAssertion); initDataPropertyAssertions(odp); - final int count = EntitySearcher.getDataPropertyValues(individual, odp, ontology).size(); + final int count = + EntitySearcher.getDataPropertyValues(individual, odp, ontology).collect(Collectors.toSet()).size(); axiomRemover.remove(descriptor); final ArgumentCaptor captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); @@ -141,7 +143,8 @@ public void removeAxiomsByDescriptorWithObjectPropertyAssertions() { final OWLObjectProperty oop = dataFactory.getOWLObjectProperty(IRI.create(opAssertion.getIdentifier())); descriptor.addAssertion(opAssertion); initObjectPropertyAssertions(oop); - final int count = EntitySearcher.getObjectPropertyValues(individual, oop, ontology).size(); + final int count = + EntitySearcher.getObjectPropertyValues(individual, oop, ontology).collect(Collectors.toSet()).size(); axiomRemover.remove(descriptor); final ArgumentCaptor captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); @@ -168,10 +171,13 @@ public void removeRetainsValuesOfAssertionsNotPresentInDescriptor() { final OWLObjectProperty opOne = dataFactory.getOWLObjectProperty(IRI.create(opAssertion.getIdentifier())); final OWLObjectProperty opTwo = dataFactory.getOWLObjectProperty(IRI.create(opAssertionTwo.getIdentifier())); initObjectPropertyAssertions(opOne, opTwo); - final int countTwo = EntitySearcher.getObjectPropertyValues(individual, opTwo, ontology).size(); + final int countTwo = + EntitySearcher.getObjectPropertyValues(individual, opTwo, ontology).collect(Collectors.toSet()).size(); axiomRemover.remove(descriptor); - final int resultCountOne = EntitySearcher.getObjectPropertyValues(individual, opOne, ontology).size(); - final int resultCountTwo = EntitySearcher.getObjectPropertyValues(individual, opTwo, ontology).size(); + final int resultCountOne = + EntitySearcher.getObjectPropertyValues(individual, opOne, ontology).collect(Collectors.toSet()).size(); + final int resultCountTwo = + EntitySearcher.getObjectPropertyValues(individual, opTwo, ontology).collect(Collectors.toSet()).size(); assertEquals(0, resultCountOne); assertEquals(countTwo, resultCountTwo); } @@ -184,7 +190,9 @@ public void removeAxiomsByDescriptorWithAnnotationPropertyAssertions() { descriptor.addAssertion(apAssertion); initAnnotationAssertions(oap); axiomRemover.remove(descriptor); - assertEquals(0, EntitySearcher.getAnnotationAssertionAxioms(individual.getIRI(), ontology).size()); + assertEquals(0, + EntitySearcher.getAnnotationAssertionAxioms(individual.getIRI(), ontology).collect(Collectors.toSet()) + .size()); final ArgumentCaptor captor = ArgumentCaptor.forClass(List.class); verify(adapterMock).addTransactionalChanges(captor.capture()); final List changes = captor.getValue(); @@ -268,15 +276,15 @@ public void removeAxiomsRemovesCorrespondingAssertions() { for (Object change : changes) { final RemoveAxiom ax = (RemoveAxiom) change; final Assertion a; - if (!ax.getAxiom().getAnnotationPropertiesInSignature().isEmpty()) { + if (ax.getAxiom().annotationPropertiesInSignature().anyMatch(x -> true)) { a = Assertion.createPropertyAssertion( - ax.getAxiom().getAnnotationPropertiesInSignature().iterator().next().getIRI().toURI(), false); - } else if (!ax.getAxiom().getDataPropertiesInSignature().isEmpty()) { + ax.getAxiom().annotationPropertiesInSignature().iterator().next().getIRI().toURI(), false); + } else if (ax.getAxiom().dataPropertiesInSignature().anyMatch(x -> true)) { a = Assertion.createPropertyAssertion( - ax.getAxiom().getDataPropertiesInSignature().iterator().next().getIRI().toURI(), false); - } else if (!ax.getAxiom().getObjectPropertiesInSignature().isEmpty()) { + ax.getAxiom().dataPropertiesInSignature().iterator().next().getIRI().toURI(), false); + } else if (ax.getAxiom().objectPropertiesInSignature().anyMatch(x -> true)) { a = Assertion.createPropertyAssertion( - ax.getAxiom().getObjectPropertiesInSignature().iterator().next().getIRI().toURI(), false); + ax.getAxiom().objectPropertiesInSignature().iterator().next().getIRI().toURI(), false); } else { a = Assertion.createPropertyAssertion(URI.create(Vocabulary.RDF_TYPE), false); } diff --git a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/MainAxiomLoaderTest.java b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/MainAxiomLoaderTest.java index de3f6a2c6..dc8e62ab1 100644 --- a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/MainAxiomLoaderTest.java +++ b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/MainAxiomLoaderTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -36,6 +36,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -77,16 +78,16 @@ public void setUp() throws Exception { } @Test - public void returnsEmptyCollectionWhenIndividualIsNotInOntology() throws Exception { + public void returnsEmptyCollectionWhenIndividualIsNotInOntology() { when(ontologyMock.containsIndividualInSignature(individual.getIRI())).thenReturn(false); assertTrue(axiomLoader.findAxioms(descriptor()).isEmpty()); - verify(ontologyMock, never()).getDataPropertyAssertionAxioms(any(OWLIndividual.class)); - verify(ontologyMock, never()).getObjectPropertyAssertionAxioms(any(OWLIndividual.class)); - verify(ontologyMock, never()).getAnnotationAssertionAxioms(any(IRI.class)); + verify(ontologyMock, never()).dataPropertyAssertionAxioms(any(OWLIndividual.class)); + verify(ontologyMock, never()).objectPropertyAssertionAxioms(any(OWLIndividual.class)); + verify(ontologyMock, never()).annotationAssertionAxioms(any(IRI.class)); } @Test - public void loadsExplicitDataPropertyValuesForAssertions() throws Exception { + public void loadsExplicitDataPropertyValuesForAssertions() { final URI assertionProperty = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion dp = Assertion.createDataPropertyAssertion(assertionProperty, false); final Set axioms = new HashSet<>(); @@ -95,10 +96,12 @@ public void loadsExplicitDataPropertyValuesForAssertions() throws Exception { individual, 158)); axioms.add(dataFactory.getOWLDataPropertyAssertionAxiom( dataFactory.getOWLDataProperty(IRI.create("http://krizik.felk.cvut.cz/PropertyTwo")), individual, 200)); - when(ontologyMock.getDataPropertyAssertionAxioms(individual)).thenReturn(axioms); + when(ontologyMock.dataPropertyAssertionAxioms(individual)).thenReturn(axioms.stream()); + when(ontologyMock.annotationAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); final Collection> result = axiomLoader.findAxioms(descriptor(dp)); - verify(ontologyMock).getDataPropertyAssertionAxioms(individual); + verify(ontologyMock).dataPropertyAssertionAxioms(individual); for (Axiom ax : result) { assertEquals(dp, ax.getAssertion()); } @@ -113,7 +116,7 @@ private AxiomDescriptor descriptor(Assertion... assertions) { } @Test - public void loadsExplicitObjectPropertyValuesForAssertions() throws Exception { + public void loadsExplicitObjectPropertyValuesForAssertions() { final URI assertionPropertyOne = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion opOne = Assertion.createObjectPropertyAssertion(assertionPropertyOne, false); final URI assertionPropertyTwo = URI.create("http://krizik.felk.cvut.cz/PropertyTwo"); @@ -129,17 +132,19 @@ public void loadsExplicitObjectPropertyValuesForAssertions() throws Exception { axioms.add(dataFactory.getOWLObjectPropertyAssertionAxiom( dataFactory.getOWLObjectProperty(IRI.create("http://krizik.felk.cvut.cz/otherProperty")), individual, otherIndividual)); - when(ontologyMock.getObjectPropertyAssertionAxioms(individual)).thenReturn(axioms); + when(ontologyMock.objectPropertyAssertionAxioms(individual)).thenReturn(axioms.stream()); + when(ontologyMock.dataPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.annotationAssertionAxioms(any())).thenReturn(Stream.empty()); final Collection> result = axiomLoader.findAxioms(descriptor(opOne, opTwo)); - verify(ontologyMock).getObjectPropertyAssertionAxioms(individual); + verify(ontologyMock).objectPropertyAssertionAxioms(individual); for (Axiom ax : result) { assertTrue(ax.getAssertion().equals(opOne) || ax.getAssertion().equals(opTwo)); } } @Test - public void loadsExplicitAnnotationPropertyValuesForAssertions() throws Exception { + public void loadsExplicitAnnotationPropertyValuesForAssertions() { final URI assertionProperty = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion dp = Assertion.createAnnotationPropertyAssertion(assertionProperty, false); final Set axioms = new HashSet<>(); @@ -149,22 +154,27 @@ public void loadsExplicitAnnotationPropertyValuesForAssertions() throws Exceptio axioms.add(dataFactory.getOWLAnnotationAssertionAxiom( dataFactory.getOWLAnnotationProperty(IRI.create("http://krizik.felk.cvut.cz/PropertyTwo")), individual.getIRI(), dataFactory.getOWLLiteral(200))); - when(ontologyMock.getAnnotationAssertionAxioms(individual.getIRI())).thenReturn(axioms); + when(ontologyMock.annotationAssertionAxioms(individual.getIRI())).thenReturn(axioms.stream()); + when(ontologyMock.dataPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); final Collection> result = axiomLoader.findAxioms(descriptor(dp)); - verify(ontologyMock).getAnnotationAssertionAxioms(individual.getIRI()); + verify(ontologyMock).annotationAssertionAxioms(individual.getIRI()); for (Axiom ax : result) { assertEquals(dp, ax.getAssertion()); } } @Test - public void loadsExplicitTypesWhenClassAssertionIsInTheDescriptor() throws Exception { + public void loadsExplicitTypesWhenClassAssertionIsInTheDescriptor() { final Assertion classAssertion = Assertion.createClassAssertion(false); final TypesHandler typesMock = mock(TypesHandler.class); when(adapterMock.getTypesHandler()).thenReturn(typesMock); when(typesMock.getTypes(SUBJECT, null, false)).thenReturn(Collections .singleton(new AxiomImpl<>(SUBJECT, classAssertion, new Value<>(URI.create("http://typeA"))))); + when(ontologyMock.annotationAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.dataPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); final Collection> result = axiomLoader.findAxioms(descriptor(classAssertion)); verify(typesMock).getTypes(SUBJECT, null, false); @@ -173,26 +183,29 @@ public void loadsExplicitTypesWhenClassAssertionIsInTheDescriptor() throws Excep } @Test - public void loadsExplicitValuesForUntypedAssertion() throws Exception { + public void loadsExplicitValuesForUntypedAssertion() { final URI assertionUri = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion assertion = Assertion.createPropertyAssertion(assertionUri, false); - when(ontologyMock.getDataPropertyAssertionAxioms(individual)) - .thenReturn(Collections.singleton(dataFactory.getOWLDataPropertyAssertionAxiom( + when(ontologyMock.dataPropertyAssertionAxioms(individual)) + .thenReturn(Stream.of(dataFactory.getOWLDataPropertyAssertionAxiom( dataFactory.getOWLDataProperty(IRI.create("http://krizik.felk.cvut.cz/PropertyOne")), individual, 200))); - when(ontologyMock.getAnnotationAssertionAxioms(individual.getIRI())) - .thenReturn(Collections.singleton(dataFactory.getOWLAnnotationAssertionAxiom( + when(ontologyMock.annotationAssertionAxioms(individual.getIRI())) + .thenReturn(Stream.of(dataFactory.getOWLAnnotationAssertionAxiom( dataFactory.getOWLAnnotationProperty(IRI.create("http://krizik.felk.cvut.cz/PropertyOne")), individual.getIRI(), dataFactory.getOWLLiteral(200)))); + when(ontologyMock.dataPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + final Collection> result = axiomLoader.findAxioms(descriptor(assertion)); assertFalse(result.isEmpty()); - verify(ontologyMock).getDataPropertyAssertionAxioms(individual); - verify(ontologyMock).getObjectPropertyAssertionAxioms(individual); - verify(ontologyMock).getAnnotationAssertionAxioms(individual.getIRI()); + verify(ontologyMock).dataPropertyAssertionAxioms(individual); + verify(ontologyMock).objectPropertyAssertionAxioms(individual); + verify(ontologyMock).annotationAssertionAxioms(individual.getIRI()); } @Test - public void loadsInferredDataPropertyValues() throws Exception { + public void loadsInferredDataPropertyValues() { final URI dpOneUri = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion dpOne = Assertion.createDataPropertyAssertion(dpOneUri, true); final OWLDataProperty owlDpOne = dataFactory.getOWLDataProperty(IRI.create(dpOneUri)); @@ -215,7 +228,7 @@ public void loadsInferredDataPropertyValues() throws Exception { } @Test - public void loadsInferredObjectPropertyValues() throws Exception { + public void loadsInferredObjectPropertyValues() { final URI opUri = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion op = Assertion.createObjectPropertyAssertion(opUri, true); final OWLObjectProperty owlOp = dataFactory.getOWLObjectProperty(IRI.create(opUri)); @@ -230,7 +243,7 @@ public void loadsInferredObjectPropertyValues() throws Exception { } @Test - public void loadsInferredTypes() throws Exception { + public void loadsInferredTypes() { final Assertion classAssertion = Assertion.createClassAssertion(true); final Set> types = new HashSet<>(); types.add(new AxiomImpl<>(SUBJECT, classAssertion, @@ -249,7 +262,7 @@ public void loadsInferredTypes() throws Exception { } @Test(expected = ReasonerNotAvailableException.class) - public void throwsExceptionWhenReasonerIsNotAvailableForInferredAssertions() throws Exception { + public void throwsExceptionWhenReasonerIsNotAvailableForInferredAssertions() { final URI opUri = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion op = Assertion.createObjectPropertyAssertion(opUri, true); final OntologySnapshot snapshot = new OntologySnapshot(ontologyMock, managerMock, dataFactory, null); @@ -259,7 +272,7 @@ public void throwsExceptionWhenReasonerIsNotAvailableForInferredAssertions() thr } @Test - public void skipsExplicitAssertionValueIfThereIsTheSameAssertionAlsoWithInference() throws Exception { + public void skipsExplicitAssertionValueIfThereIsTheSameAssertionAlsoWithInference() { final URI opUri = URI.create("http://krizik.felk.cvut.cz/PropertyOne"); final Assertion opAsserted = Assertion.createObjectPropertyAssertion(opUri, false); final Assertion opInferred = Assertion.createObjectPropertyAssertion(opUri, true); @@ -272,10 +285,11 @@ public void skipsExplicitAssertionValueIfThereIsTheSameAssertionAlsoWithInferenc dataFactory.getOWLNamedIndividual(IRI.create("http://krizik.felk.cvut.cz/IndividialTwo")))); final NodeSet individuals = new OWLNamedIndividualNodeSet(indSet); when(reasonerMock.getObjectPropertyValues(individual, owlOp)).thenReturn(individuals); - final Set axioms = Collections - .singleton(dataFactory.getOWLObjectPropertyAssertionAxiom( + final Stream axioms = Stream.of(dataFactory.getOWLObjectPropertyAssertionAxiom( dataFactory.getOWLObjectProperty(IRI.create(opUri)), individual, commonInd)); - when(ontologyMock.getObjectPropertyAssertionAxioms(individual)).thenReturn(axioms); + when(ontologyMock.objectPropertyAssertionAxioms(individual)).thenReturn(axioms); + when(ontologyMock.dataPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.annotationAssertionAxioms(any())).thenReturn(Stream.empty()); final Collection> result = axiomLoader.findAxioms(descriptor(opAsserted, opInferred)); assertEquals(indSet.size(), result.size()); @@ -285,7 +299,7 @@ public void skipsExplicitAssertionValueIfThereIsTheSameAssertionAlsoWithInferenc } @Test - public void loadsStringLiteralValueForExplicitAnnotationPropertyWithCorrectLanguageTag() throws Exception { + public void loadsStringLiteralValueForExplicitAnnotationPropertyWithCorrectLanguageTag() { initExplicitAnnotationPropertyStringsWithLanguageTag(); final Collection> result = axiomLoader @@ -301,7 +315,9 @@ private void initExplicitAnnotationPropertyStringsWithLanguageTag() { dataFactory.getOWLLiteral("a", LANG))); axioms.add(dataFactory.getOWLAnnotationAssertionAxiom(property, individual.getIRI(), dataFactory.getOWLLiteral("b", "cs"))); - when(ontologyMock.getAnnotationAssertionAxioms(individual.getIRI())).thenReturn(axioms); + when(ontologyMock.annotationAssertionAxioms(individual.getIRI())).thenReturn(axioms.stream()); + when(ontologyMock.dataPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); } private void checkLoadedAxiomsForStringValue(Collection> result, String expected) { @@ -311,7 +327,7 @@ private void checkLoadedAxiomsForStringValue(Collection> result, String } @Test - public void loadsStringLiteralValueForExplicitDataPropertyWithCorrectLanguageTag() throws Exception { + public void loadsStringLiteralValueForExplicitDataPropertyWithCorrectLanguageTag() { final String propertyUri = "http://krizik.felk.cvut.cz/dataPropertyOne"; initExplicitDataPropertyStringsWithLanguageTag(propertyUri); @@ -328,11 +344,13 @@ private void initExplicitDataPropertyStringsWithLanguageTag(String propertyUri) .getOWLDataPropertyAssertionAxiom(property, individual, dataFactory.getOWLLiteral("a", LANG))); axioms.add(dataFactory .getOWLDataPropertyAssertionAxiom(property, individual, dataFactory.getOWLLiteral("b", "cs"))); - when(ontologyMock.getDataPropertyAssertionAxioms(individual)).thenReturn(axioms); + when(ontologyMock.dataPropertyAssertionAxioms(individual)).thenReturn(axioms.stream()); + when(ontologyMock.annotationAssertionAxioms(any())).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(any())).thenReturn(Stream.empty()); } @Test - public void loadsStringLiteralValueForInferredDataPropertyWithCorrectLanguageTag() throws Exception { + public void loadsStringLiteralValueForInferredDataPropertyWithCorrectLanguageTag() { final OWLDataProperty dp = dataFactory.getOWLDataProperty(IRI.create(RDFS_LABEL)); final Set values = new HashSet<>(); values.add(dataFactory.getOWLLiteral("a", LANG)); @@ -345,8 +363,7 @@ public void loadsStringLiteralValueForInferredDataPropertyWithCorrectLanguageTag } @Test - public void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInExplicitDataPropertyAssertion() - throws Exception { + public void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInExplicitDataPropertyAssertion() { final String propertyUri = "http://krizik.felk.cvut.cz/dataPropertyOne"; initExplicitDataPropertyStringsWithLanguageTag(propertyUri); final Assertion dpa = Assertion.createDataPropertyAssertion(URI.create(propertyUri), "cs", false); @@ -355,8 +372,7 @@ public void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInExplicitD } @Test - public void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInExplicitAnnotationPropertyAssertion() - throws Exception { + public void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInExplicitAnnotationPropertyAssertion() { initExplicitAnnotationPropertyStringsWithLanguageTag(); final Assertion apa = Assertion.createAnnotationPropertyAssertion(URI.create(RDFS_LABEL), "cs", false); final Collection> result = axiomLoader.findAxioms(descriptor(apa)); @@ -364,7 +380,7 @@ public void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInExplicitA } @Test - public void loadsStringLiteralWithAllLanguagesWhenLanguageTagIsExplicitlySetToNull() throws Exception { + public void loadsStringLiteralWithAllLanguagesWhenLanguageTagIsExplicitlySetToNull() { initExplicitAnnotationPropertyStringsWithLanguageTag(); final Assertion apa = Assertion.createAnnotationPropertyAssertion(URI.create(RDFS_LABEL), null, false); final Collection> result = axiomLoader.findAxioms(descriptor(apa)); @@ -375,7 +391,7 @@ public void loadsStringLiteralWithAllLanguagesWhenLanguageTagIsExplicitlySetToNu } @Test - public void loadsStringLiteralWithCorrectLanguageTagWhenSpecifiedOnUnspecifiedDataProperty() throws Exception { + public void loadsStringLiteralWithCorrectLanguageTagWhenSpecifiedOnUnspecifiedDataProperty() { final String propertyUri = "http://krizik.felk.cvut.cz/dataPropertyOne"; initExplicitDataPropertyStringsWithLanguageTag(propertyUri); final Assertion assertion = Assertion.createUnspecifiedPropertyAssertion("cs", false); @@ -384,8 +400,7 @@ public void loadsStringLiteralWithCorrectLanguageTagWhenSpecifiedOnUnspecifiedDa } @Test - public void loadsStringLiteralWithCorrectLanguageTagWhenSpecifiedOnUnspecifiedAnnotationProperty() - throws Exception { + public void loadsStringLiteralWithCorrectLanguageTagWhenSpecifiedOnUnspecifiedAnnotationProperty() { initExplicitAnnotationPropertyStringsWithLanguageTag(); final Assertion assertion = Assertion.createUnspecifiedPropertyAssertion("cs", false); final Collection> result = axiomLoader.findAxioms(descriptor(assertion)); @@ -393,7 +408,7 @@ public void loadsStringLiteralWithCorrectLanguageTagWhenSpecifiedOnUnspecifiedAn } @Test - public void loadsStringLiteralWithCorrectLanguageTagSpecifiedOnInferredDataProperty() throws Exception { + public void loadsStringLiteralWithCorrectLanguageTagSpecifiedOnInferredDataProperty() { final String propertyUri = "http://krizik.felk.cvut.cz/dataPropertyOne"; final OWLDataProperty dp = dataFactory.getOWLDataProperty(IRI.create(propertyUri)); final Set values = new HashSet<>(); diff --git a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/OwlapiAdapterTest.java b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/OwlapiAdapterTest.java index 54196f07d..e300649ea 100644 --- a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/OwlapiAdapterTest.java +++ b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/OwlapiAdapterTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -14,7 +14,6 @@ */ package cz.cvut.kbss.ontodriver.owlapi; -import com.google.common.base.Optional; import com.google.common.collect.Multimap; import cz.cvut.kbss.ontodriver.Connection; import cz.cvut.kbss.ontodriver.OntologyStorageProperties; @@ -39,10 +38,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -105,7 +102,7 @@ public void rollbackCausesChangesToEmpty() throws Exception { } @Test - public void testIsConsistentWithCorrectContext() throws Exception { + public void testIsConsistentWithCorrectContext() { final URI uri = getOntologyUri(); when(reasonerMock.isConsistent()).thenReturn(Boolean.TRUE); @@ -115,11 +112,11 @@ public void testIsConsistentWithCorrectContext() throws Exception { private URI getOntologyUri() { final Optional iri = ontology.getOntologyID().getOntologyIRI(); - return iri.get().toURI(); + return iri.isPresent() ? iri.get().toURI() : null; } @Test - public void isConsistentIgnoresContextInfo() throws Exception { + public void isConsistentIgnoresContextInfo() { when(reasonerMock.isConsistent()).thenReturn(Boolean.TRUE); final URI ctx = URI.create("http://krizik.felk.cvut.cz/differentContext"); assertTrue(adapter.isConsistent(ctx)); @@ -127,7 +124,7 @@ public void isConsistentIgnoresContextInfo() throws Exception { } @Test - public void testGetContexts() throws Exception { + public void testGetContexts() { final URI uri = getOntologyUri(); final List res = adapter.getContexts(); @@ -136,7 +133,7 @@ public void testGetContexts() throws Exception { } @Test - public void testContainsUnknownContext() throws Exception { + public void testContainsUnknownContext() { final Axiom axiom = initAxiomForContains(Assertion.AssertionType.CLASS, false); final URI context = URI.create("http://krizik.felk.cvut.cz/jopa/different"); boolean res = adapter.containsAxiom(axiom, context); @@ -208,7 +205,7 @@ private void addAxiomToOntology(Axiom ax) { } @Test - public void testContainsClassAssertionAxiomNoContext() throws Exception { + public void testContainsClassAssertionAxiomNoContext() { final Axiom axiom = initAxiomForContains(Assertion.AssertionType.CLASS, false); addAxiomToOntology(axiom); boolean res = adapter.containsAxiom(axiom, null); @@ -218,14 +215,14 @@ public void testContainsClassAssertionAxiomNoContext() throws Exception { verify(ontology).containsAxiom(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.CLASS_ASSERTION)); - final Set types = ax.getClassesInSignature(); + final Set types = ax.classesInSignature().collect(Collectors.toSet()); assertEquals(1, types.size()); final OWLClass cls = types.iterator().next(); assertEquals(axiom.getValue().getValue(), cls.getIRI().toURI()); } @Test - public void testContainsObjectPropertyAssertionInferred() throws Exception { + public void testContainsObjectPropertyAssertionInferred() { final Axiom axiom = initAxiomForContains(Assertion.AssertionType.OBJECT_PROPERTY, true); final URI ctx = getOntologyUri(); when(reasonerMock.isEntailed(any(OWLAxiom.class))).thenReturn(Boolean.TRUE); @@ -236,17 +233,17 @@ public void testContainsObjectPropertyAssertionInferred() throws Exception { verify(reasonerMock).isEntailed(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.OBJECT_PROPERTY_ASSERTION)); - final Set individuals = ax.getIndividualsInSignature(); + final Set individuals = ax.individualsInSignature().collect(Collectors.toSet()); assertEquals(2, individuals.size()); assertTrue(individuals.contains(factory.getOWLNamedIndividual(IRI.create(axiom.getSubject().toString())))); assertTrue(individuals.contains(factory.getOWLNamedIndividual(IRI.create(axiom.getValue().stringValue())))); - final Set objProperties = ax.getObjectPropertiesInSignature(); + final Set objProperties = ax.objectPropertiesInSignature().collect(Collectors.toSet()); assertEquals(1, objProperties.size()); assertEquals(axiom.getAssertion().getIdentifier(), objProperties.iterator().next().getIRI().toURI()); } @Test - public void testContainsDataProperty() throws Exception { + public void testContainsDataProperty() { final Axiom axiom = initAxiomForContains(Assertion.AssertionType.DATA_PROPERTY, false); addAxiomToOntology(axiom); boolean res = adapter.containsAxiom(axiom, null); @@ -256,10 +253,10 @@ public void testContainsDataProperty() throws Exception { verify(ontology).containsAxiom(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.DATA_PROPERTY_ASSERTION)); - final Set dataProperties = ax.getDataPropertiesInSignature(); + final Set dataProperties = ax.dataPropertiesInSignature().collect(Collectors.toSet()); assertEquals(1, dataProperties.size()); assertEquals(axiom.getAssertion().getIdentifier(), dataProperties.iterator().next().getIRI().toURI()); - final Set individuals = ax.getIndividualsInSignature(); + final Set individuals = ax.individualsInSignature().collect(Collectors.toSet()); assertEquals(1, individuals.size()); assertEquals(axiom.getSubject().getIdentifier(), individuals.iterator().next().getIRI().toURI()); assertTrue(ax instanceof OWLDataPropertyAssertionAxiom); @@ -267,7 +264,7 @@ public void testContainsDataProperty() throws Exception { } @Test - public void testContainsAnnotationPropertyInferred() throws Exception { + public void testContainsAnnotationPropertyInferred() { final Axiom axiom = initAxiomForContains(Assertion.AssertionType.ANNOTATION_PROPERTY, true); when(reasonerMock.isEntailed(any(OWLAxiom.class))).thenReturn(Boolean.TRUE); boolean res = adapter.containsAxiom(axiom, null); @@ -277,7 +274,8 @@ public void testContainsAnnotationPropertyInferred() throws Exception { verify(reasonerMock).isEntailed(captor.capture()); final OWLAxiom ax = captor.getValue(); assertTrue(ax.isOfType(AxiomType.ANNOTATION_ASSERTION)); - final Set annotationProperties = ax.getAnnotationPropertiesInSignature(); + final Set annotationProperties = + ax.annotationPropertiesInSignature().collect(Collectors.toSet()); assertEquals(1, annotationProperties.size()); assertEquals(axiom.getAssertion().getIdentifier(), annotationProperties.iterator().next().getIRI().toURI()); assertTrue(ax instanceof OWLAnnotationAssertionAxiom); @@ -287,7 +285,7 @@ public void testContainsAnnotationPropertyInferred() throws Exception { } @Test - public void persistIndividualInMultipleClassesIsLegal() throws Exception { + public void persistIndividualInMultipleClassesIsLegal() { final AxiomValueDescriptor descriptorOne = new AxiomValueDescriptor(INDIVIDUAL); final String typeA = "http://krizik.felk.cvut.cz/typeA"; descriptorOne.addAssertionValue(Assertion.createClassAssertion(false), new Value<>(URI.create(typeA))); @@ -306,7 +304,8 @@ public void persistIndividualInMultipleClassesIsLegal() throws Exception { adapter.persist(descriptorTwo); final OWLNamedIndividual individual = factory.getOWLNamedIndividual(IRI.create(INDIVIDUAL.getIdentifier())); - final Collection classes = EntitySearcher.getTypes(individual, ontology); + final Collection classes = + EntitySearcher.getTypes(individual, ontology).collect(Collectors.toSet()); assertTrue(classes.contains(factory.getOWLClass(IRI.create(typeA)))); assertTrue(classes.contains(factory.getOWLClass(IRI.create(typeB)))); final Multimap properties = diff --git a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/PropertiesHandlerTest.java b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/PropertiesHandlerTest.java index 402bca9b5..57a61b3cc 100644 --- a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/PropertiesHandlerTest.java +++ b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/PropertiesHandlerTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* 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. - * + *

* 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 @@ -34,6 +34,7 @@ import java.net.URL; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -81,20 +82,21 @@ public void getPropertiesLoadsExplicitPropertiesFromOntology() throws Exception final Collection> axioms = propertiesHandler.getProperties(INDIVIDUAL, false); assertFalse(axioms.isEmpty()); final OWLNamedIndividual individual = dataFactory.getOWLNamedIndividual(IRI.create(PK)); - verify(ontologyMock).getDataPropertyAssertionAxioms(individual); - verify(ontologyMock).getObjectPropertyAssertionAxioms(individual); - verify(ontologyMock).getAnnotationAssertionAxioms(individual.getIRI()); + verify(ontologyMock).dataPropertyAssertionAxioms(individual); + verify(ontologyMock).objectPropertyAssertionAxioms(individual); + verify(ontologyMock).annotationAssertionAxioms(individual.getIRI()); verifyAxioms(axioms, Assertion.AssertionType.DATA_PROPERTY, dataValues); verifyAxioms(axioms, Assertion.AssertionType.OBJECT_PROPERTY, objectValues); } private void initSampleProperties() { final OWLNamedIndividual individual = dataFactory.getOWLNamedIndividual(IRI.create(PK)); - when(ontologyMock.getDataPropertyAssertionAxioms(individual)).thenReturn(initSampleDataProperties()); - when(ontologyMock.getObjectPropertyAssertionAxioms(individual)).thenReturn(initSampleObjectProperties()); + when(ontologyMock.dataPropertyAssertionAxioms(individual)).thenReturn(initSampleDataProperties()); + when(ontologyMock.objectPropertyAssertionAxioms(individual)).thenReturn(initSampleObjectProperties()); + when(ontologyMock.annotationAssertionAxioms(any())).thenReturn(Stream.empty()); } - private Set initSampleDataProperties() { + private Stream initSampleDataProperties() { final OWLNamedIndividual individual = dataFactory.getOWLNamedIndividual(IRI.create(PK)); final OWLDataProperty dpOne = dataFactory.getOWLDataProperty(IRI.create(DP_ONE)); final Set dpValues = new HashSet<>(); @@ -107,16 +109,16 @@ private Set initSampleDataProperties() { dataValues.add("Test"); dpValues.add(dataFactory.getOWLDataPropertyAssertionAxiom(dpTwo, individual, "TestTwo")); dataValues.add("TestTwo"); - return dpValues; + return dpValues.stream(); } - private Set initSampleObjectProperties() { + private Stream initSampleObjectProperties() { final OWLNamedIndividual individual = dataFactory.getOWLNamedIndividual(IRI.create(PK)); final OWLObjectProperty op = dataFactory.getOWLObjectProperty(IRI.create(OP_ONE)); objectValues.add(INDIVIDUAL); final Set opValues = new HashSet<>(); opValues.add(dataFactory.getOWLObjectPropertyAssertionAxiom(op, individual, individual)); - return opValues; + return opValues.stream(); } private void verifyAxioms(Collection> axioms, Assertion.AssertionType assertionType, @@ -146,20 +148,20 @@ public void getPropertiesReturnsEmptyCollectionsForNonExistingIndividual() throw } private void initEmptyOntology(OWLNamedIndividual individual) { - when(ontologyMock.getDataPropertyAssertionAxioms(individual)).thenReturn(Collections.emptySet()); - when(ontologyMock.getObjectPropertyAssertionAxioms(individual)).thenReturn(Collections.emptySet()); - when(ontologyMock.getAnnotationAssertionAxioms(individual.getIRI())).thenReturn(Collections.emptySet()); + when(ontologyMock.dataPropertyAssertionAxioms(individual)).thenReturn(Stream.empty()); + when(ontologyMock.objectPropertyAssertionAxioms(individual)).thenReturn(Stream.empty()); + when(ontologyMock.annotationAssertionAxioms(individual.getIRI())).thenReturn(Stream.empty()); } @Test public void getPropertiesWithInferenceGetsInferredProperties() throws Exception { final OWLNamedIndividual individual = dataFactory.getOWLNamedIndividual(IRI.create(PK)); initEmptyOntology(individual); - when(ontologyMock.getDataPropertiesInSignature()).thenReturn(new HashSet<>( - Arrays.asList(dataFactory.getOWLDataProperty(IRI.create(DP_ONE)), - dataFactory.getOWLDataProperty(IRI.create(DP_TWO))))); - when(ontologyMock.getObjectPropertiesInSignature()) - .thenReturn(Collections.singleton(dataFactory.getOWLObjectProperty(IRI.create(OP_ONE)))); + when(ontologyMock.dataPropertiesInSignature()) + .thenReturn(Stream.of(dataFactory.getOWLDataProperty(IRI.create(DP_ONE)), + dataFactory.getOWLDataProperty(IRI.create(DP_TWO)))); + when(ontologyMock.objectPropertiesInSignature()) + .thenReturn(Stream.of(dataFactory.getOWLObjectProperty(IRI.create(OP_ONE)))); when(reasonerMock.getDataPropertyValues(eq(individual), any(OWLDataProperty.class))) .thenReturn(Collections.emptySet()); when(reasonerMock.getObjectPropertyValues(eq(individual), diff --git a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtilsTest.java b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtilsTest.java index 17a08359b..6e96a62db 100644 --- a/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtilsTest.java +++ b/ontodriver-owlapi/src/test/java/cz/cvut/kbss/ontodriver/owlapi/util/OwlapiUtilsTest.java @@ -50,4 +50,10 @@ public void doesLanguageMatchReturnsTrueWhenLiteralHasNoLanguageTag() { final OWLLiteral literal = dataFactory.getOWLLiteral("test"); assertTrue(OwlapiUtils.doesLanguageMatch(literal, LANG)); } + + @Test + public void doesLanguageMatchReturnsTrueForNonString() { + final OWLLiteral literal = dataFactory.getOWLLiteral(117); + assertTrue(OwlapiUtils.doesLanguageMatch(literal, LANG)); + } } \ No newline at end of file