TypesHandler { Set<Axiom<URI>> getTypes(NamedResource subject, URI context, boolean includeInferred) { final Collection<? extends OWLClassExpression> owlClasses; if (!includeInferred) { owlClasses = loadExplicitClasses(subject); } else { owlClasses = inferClasses(subject); } return owlClassesToAxioms(subject, includeInferred, owlClasses); } TypesHandler(OwlapiAdapter adapter, OntologySnapshot snapshot);   }
@Test void getTypesLoadsExplicitTypesFromOntology() throws Exception { final OntologySnapshot snapshot = TestUtils.initRealOntology(reasonerMock); final Set<URI> types = initTypes(); addClassAssertionsToOntology(types, snapshot.getOntology(), snapshot.getOntologyManager()); final Set<Axiom<URI>> result = new TypesHandler(adapterMock, snapshot).getTypes(INDIVIDUAL, null, false); assertEquals(types.size(), result.size()); for (Axiom<URI> ax : result) { assertTrue(types.contains(ax.getValue().getValue())); } }
@Test void getTypesLoadsTypesIncludingInferred() { final Set<URI> typeUris = initTypes(); final NodeSet<OWLClass> types = new OWLClassNodeSet(typeUris.stream().map( uri -> new OWLClassNode(dataFactory.getOWLClass(IRI.create(uri)))).collect( Collectors.toSet())); when(reasonerMock.getTypes(dataFactory.getOWLNamedIndividual(IRI.create(PK)), false)).thenReturn(types); final Set<Axiom<URI>> result = typesHandler.getTypes(INDIVIDUAL, null, true); assertEquals(typeUris.size(), result.size()); for (Axiom<URI> ax : result) { assertTrue(typeUris.contains(ax.getValue().getValue())); } }
@Test void getTypesLoadsTypesFromImportedOntologiesAsWell() throws Exception { final OntologySnapshot snapshot = TestUtils.initRealOntology(reasonerMock); final Set<URI> types = initTypes(); final OWLOntologyManager manager = snapshot.getOntologyManager(); final OWLOntology imported = manager.createOntology(IRI.create(Generator.generateUri())); manager.applyChange(new AddImport(snapshot.getOntology(), dataFactory.getOWLImportsDeclaration(imported.getOntologyID().getOntologyIRI().get()))); addClassAssertionsToOntology(types, snapshot.getOntology(), snapshot.getOntologyManager()); final URI typeInImport = Generator.generateUri(); addClassAssertionsToOntology(Collections.singleton(typeInImport), imported, manager); final Set<Axiom<URI>> result = new TypesHandler(adapterMock, snapshot).getTypes(INDIVIDUAL, null, false); final Set<URI> resultTypes = result.stream().map(a -> a.getValue().getValue()).collect(Collectors.toSet()); assertTrue(resultTypes.containsAll(types)); assertTrue(resultTypes.contains(typeInImport)); }