/** * The standard 'getOntology' from the OWLManager don't really take care of versionning. This function is here to enforce the notion of version * * @param ontologyID with version information * @return the ontology if already load into the given manager. * @since 2.5.1 */ public default Optional<OWLOntology> getOntology(final OWLOntologyID ontologyID) { return OWLGroup.getOntology(getManager(), ontologyID); }
/** * The standard 'getOntology' from the OWLManager don't really take care of versionning. This function is here to enforce the notion of version * * @param ontologyID with version information * @return the ontology if already load into the given manager. * @since 2.5.1 */ public default Optional<OWLOntology> getOntology(final OWLOntologyID ontologyID) { return OWLGroup.getOntology(getManager(), ontologyID); }
/** * The standard 'getOntology' from the OWLManager don't really take care of versionning. This function is here to enforce the notion of version * * @param ontologyID with version information * @return the ontology if already load into the given manager. * @since 2.5.1 */ public default Optional<OWLOntology> getOntology(final OWLOntologyID ontologyID) { return OWLGroup.getOntology(getManager(), ontologyID); }
/** * @return the namespace utils that can resolve prefix. * @since 2.5.1 */ public default Optional<PrefixDocumentFormat> getNamespaces() { final OWLDocumentFormat format = getManager().getOntologyFormat(getOntology()); return (format.isPrefixOWLDocumentFormat()) ? Optional.of((PrefixDocumentFormat) format) : Optional.empty(); }
/** * @return the namespace utils that can resolve prefix. * @since 2.5.1 */ public default Optional<PrefixDocumentFormat> getNamespaces() { final OWLDocumentFormat format = getManager().getOntologyFormat(getOntology()); return (format.isPrefixOWLDocumentFormat()) ? Optional.of((PrefixDocumentFormat) format) : Optional.empty(); }
/** * @return the namespace utils that can resolve prefix. * @since 2.5.1 */ public default Optional<PrefixDocumentFormat> getNamespaces() { final OWLDocumentFormat format = getManager().getOntologyFormat(getOntology()); return (format.isPrefixOWLDocumentFormat()) ? Optional.of((PrefixDocumentFormat) format) : Optional.empty(); }
default void remove(final OWLHelper helper) { helper.dispose(); helper.getManager().removeOntology(helper.getOntology()); } }
default void remove(final OWLHelper helper) { helper.dispose(); helper.getManager().removeOntology(helper.getOntology()); } }
default void remove(final OWLHelper helper) { helper.dispose(); helper.getManager().removeOntology(helper.getOntology()); } }
/** * @return the axioms as a single blob string. * @throws OWLOntologyStorageException if we can't store the ontology. * @throws IOException if there is an problem when reading. * @since 1.2 * @since 2.5.1 */ default public String serializeAxioms() throws OWLOntologyStorageException, IOException { try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { getManager().saveOntology(getOntology(), stream); return stream.toString(); } catch (final OWLOntologyStorageException | IOException e) { getLogger().log(Level.SEVERE, "Problem at serialisation of axioms : " + getOntology().getOntologyID(), e); throw e; } }
/** * @return the axioms as a single blob string. * @throws OWLOntologyStorageException if we can't store the ontology. * @throws IOException if there is an problem when reading. * @since 1.2 * @since 2.5.1 */ default public String serializeAxioms() throws OWLOntologyStorageException, IOException { try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { getManager().saveOntology(getOntology(), stream); return stream.toString(); } catch (final OWLOntologyStorageException | IOException e) { getLogger().log(Level.SEVERE, "Problem at serialisation of axioms : " + getOntology().getOntologyID(), e); throw e; } }
/** * @return the axioms as a single blob string. * @throws OWLOntologyStorageException if we can't store the ontology. * @throws IOException if there is an problem when reading. * @since 1.2 * @since 2.5.1 */ default public String serializeAxioms() throws OWLOntologyStorageException, IOException { try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) { getManager().saveOntology(getOntology(), stream); return stream.toString(); } catch (final OWLOntologyStorageException | IOException e) { getLogger().log(Level.SEVERE, "Problem at serialisation of axioms : " + getOntology().getOntologyID(), e); throw e; } }
/** * Axiom are parsed from the stream then add into the ontology. * * @param input is a stream of axioms * @throws OWLOntologyCreationException if we can't load the ontology. * @throws IOException if there is an problem when reading. * @since 2.5.1 */ default public void deserializeAxiomsInto(final String input) throws OWLOntologyCreationException, IOException { try (final InputStream stream = new ByteArrayInputStream(input.getBytes())) { addAxioms(getManager().loadOntologyFromOntologyDocument(stream).axioms()); } catch (final OWLOntologyAlreadyExistsException e) { if (e.getOntologyID().equals(getOntology().getOntologyID())) { getLogger().severe("The ontology already exists with the name of the Tools : " + e.getOntologyID()); throw e; } else { getManager().removeOntology(e.getOntologyID()); deserializeAxiomsInto(input); // WARN : if the file define 2 ontologies and one is already define, then an infinite loop here can occur. } } }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
/** * Axiom are parsed from the stream then add into the ontology. * * @param input is a stream of axioms * @throws OWLOntologyCreationException if we can't load the ontology. * @throws IOException if there is an problem when reading. * @since 2.5.1 */ default public void deserializeAxiomsInto(final String input) throws OWLOntologyCreationException, IOException { try (final InputStream stream = new ByteArrayInputStream(input.getBytes())) { addAxioms(getManager().loadOntologyFromOntologyDocument(stream).axioms()); } catch (final OWLOntologyAlreadyExistsException e) { if (e.getOntologyID().equals(getOntology().getOntologyID())) { getLogger().severe("The ontology already exists with the name of the Tools : " + e.getOntologyID()); throw e; } else { getManager().removeOntology(e.getOntologyID()); deserializeAxiomsInto(input); // WARN : if the file define 2 ontologies and one is already define, then an infinite loop here can occur. } } }
/** * Axiom are parsed from the stream then add into the ontology. * * @param input is a stream of axioms * @throws OWLOntologyCreationException if we can't load the ontology. * @throws IOException if there is an problem when reading. * @since 2.5.1 */ default public void deserializeAxiomsInto(final String input) throws OWLOntologyCreationException, IOException { try (final InputStream stream = new ByteArrayInputStream(input.getBytes())) { addAxioms(getManager().loadOntologyFromOntologyDocument(stream).axioms()); } catch (final OWLOntologyAlreadyExistsException e) { if (e.getOntologyID().equals(getOntology().getOntologyID())) { getLogger().severe("The ontology already exists with the name of the Tools : " + e.getOntologyID()); throw e; } else { getManager().removeOntology(e.getOntologyID()); deserializeAxiomsInto(input); // WARN : if the file define 2 ontologies and one is already define, then an infinite loop here can occur. } } }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }