OWLAPI Documentation

repository·version5·Indexed 21 days ago

https://github.com/owlcs/owlapi

A specialized Java API for the creation, manipulation, and serialization of OWL 2 ontologies. It provides a comprehensive framework including an in-memory reference implementation, support for multiple serialization formats (RDF/XML, OWL/XML, Turtle, etc.), and integration with reasoners such as HermiT, Pellet, and FaCT++. Versions 5.5.0 and later require Java 11.

Tokens
5.9K
Snippets
9
Records
38
Agent score
75%

What's inside OWLAPI

  1. Overview of OWLAPI

    version5

    OWLAPI is a Java API designed for creating, manipulating, and serializing OWL Ontologies. It provides a comprehensive framework for working with OWL 2 ontologies and includes an in-memory reference implementation.

    Key Capabilities:

    • OWL 2 Support: The latest versions are fully compatible with OWL 2.
    • Serialization/Deserialization: Supports multiple formats including RDF/XML, OWL/XML, Functional syntax, Manchester syntax, Turtle, and OBO. It also supports KRSS, DL syntax, and LaTeX for writing, and integrates with RIO for formats like NTriples and JSON.
    • Reasoner Integration: Provides interfaces to work with various reasoners such as FaCT++, HermiT, Pellet, Racer, JFact, and Chainsaw.
    • Licensing: Available under Open Source licenses (LGPL and Apache).
  2. Configure silent missing imports handling on OWLOntologyManager

    version5

    By default, OWLOntologyManager may throw exceptions when imports cannot be found or loaded. You can enable a silent mode to prevent these exceptions from interrupting your workflow.

    When the silent option is set, exceptions are not thrown for missing or un-loadable imports. To ensure you don't lose track of these issues, you can set a listener to be informed whenever an import cannot be found.

  3. Manage ontology imports and namespaces

    version5

    OWLAPI provides several mechanisms for managing namespaces and imports:

    • Namespaces: The Namespaces enum can be extended with common prefixes. Version 3.4.8 added Namespaces.inNamespace.
    • Prefix Management: DefaultPrefixManager can be refactored to expose addPrefixes. In PrefixOWLOntologyFormat, you can override the DefaultPrefixManager to customize prefix handling.
    • Imports: The library handles ontology imports, including support for multiple imports and handling of version IRIs (improved in 3.4.2).
  4. Understand OWLAPI serialization behavior

    version5

    OWLAPI model classes (like OWLObject) are Serializable to support short-term serialization, such as transmitting objects over a network to editors like WebProtege.

    Important Considerations:

    • Version Sensitivity: Serialization is intended for use when both the sender and receiver use the exact same OWLAPI version. Objects are not guaranteed to be deserializable across different versions.
    • Ignored Changes: Changes to serialVersionUID in model classes are ignored in version change reports because they are expected when classes are modified, even if the semantic API remains compatible.
  5. Use OWLOntologyBuilder for dependency injection with Guice

    version5
    OWLAPI 4.0.0 introduced support for Guice dependency injection. You can use OWLOntologyBuilder to allow swapping different OWLOntology implementations via Guice, and use the provided Guice module to create OWLOntologyManager and OWLDataFactory instances.
  6. Configure ontology parsing with OWLOntologyLoaderConfiguration

    version5

    Introduced in version 3.2.3, OWLOntologyLoaderConfiguration allows for ontology-specific parsing configurations. This enables setting different parsing modes for different ontologies.

    Supported Modes:

    • Strict parsing mode
    • Lax parsing mode
  7. Use GZip streams for ontology I/O

    version5

    Starting from version 3.4.8, OWLAPI supports GZip read/write capabilities. You can use compressed gzip input and output streams for ontology operations.

    Important: When using compressed streams, you must ensure that the stream is explicitly closed in your calling code to prevent resource leaks.

    // Note: Ensure you close the stream in your calling code
    // Example pattern for GZip usage
    InputStream gzipStream = new GZIPInputStream(new FileInputStream(file));
    // ... use stream with OWLAPI ...
    gzipStream.close();
  8. Requirements and Compatibility for OWLAPI

    version5

    When choosing a version of OWLAPI, note the following requirements:

    • Java Version: OWLAPI 5.5.0 and later require Java 11 or newer.
    • OWL Version: The latest API versions support OWL 2.
    • Dependencies: Versions 5.5.0+ include dependencies that require Java 9 or newer, necessitating the move to Java 11.
  9. Migrate literal handling from version 3.0.0 to 3.1.0

    version5

    In version 3.1.0, the representation of literals was changed to align with the OWL 2 specification.

    Key Changes:

    • OWLStringLiteral and OWLTypedLiteral have been removed.
    • They are replaced by a single interface: OWLLiteral.
    • All literals are now considered typed. Previously 'string literals' are now OWLLiteral instances with the datatype rdf:PlainLiteral.

    Migration Steps:

    • Replace all occurrences of OWLStringLiteral and OWLTypedLiteral with OWLLiteral.
    • Most method calls do not need to change, as the corresponding methods have been moved to the OWLLiteral interface.
    // Before 3.1.0
    // OWLStringLiteral stringLit = ...
    // OWLTypedLiteral typedLit = ...
    
    // In 3.1.0
    // OWLLiteral lit = ...
    // Note: former string literals now have datatype rdf:PlainLiteral
  10. Migrate OWLReasoner usage from version 3.0.0 to 3.1.0

    version5

    The OWLReasoner interface was updated in version 3.1.0 to provide finer control over reasoning tasks (e.g., classifying only the class hierarchy without performing realisation).

    Breaking Change:

    • The prepareReasoner method has been removed because it was often unnecessary and caused confusion.

    Migration Step:

    • Replace any calls to prepareReasoner with appropriate calls to precomputeInferences.