Reading ontologies

Readers

Ontologies can be read from files, memory buffers or input streams (see UIStream) through the CowlManager object. Cowl can attempt ontology deserialization via multiple readers, and you can control which reader is used in a number of ways:

  • At compile-time: readers included in the compiled library can be selected by setting the COWL_READERS CMake variable. Built-in readers are exposed through cowl_reader_*() functions.

  • At run-time, globally: you can set the default reader by calling cowl_set_reader().

  • At run-time, locally: you can specify which reader you want CowlManager to use via cowl_manager_set_reader().

You can integrate additional readers by providing suitably populated CowlReader instances. When implementing one, use the provided CowlIStream object to handle detected OWL constructs. If you need to manage prefixed IRIs, you can do so through the CowlSymTable instance available by calling cowl_istream_get_sym_table(). Refer to the built-in readers if you need guidance.

struct CowlReader

Defines a reader.

Public Members

char const *name

Name of the reader.

cowl_ret (*read)(UIStream *istream, CowlIStream *stream)

Pointer to a function that reads an ontology from an input stream.

Note

This member is mandatory.

Param state:

Reader state.

Param istream:

Input stream.

Param stream:

Ontology input stream.

Return:

Return code.

CowlReader cowl_reader_functional(void)

Returns the functional syntax reader.

Returns:

Functional syntax reader.

Handling imports

Cowl delegates locating and loading imported ontologies to the end user via the CowlImportLoader interface. Import loaders can be either provided locally to specific objects (such as via cowl_manager_set_import_loader()), or you can opt to specify a global import loader via cowl_set_import_loader(). If you do both, Cowl prioritizes local loaders, as you would expect.

struct CowlImportLoader

Provides a mechanism for generic handling of ontology imports.

The load_ontology function should return the ontology that has the specified CowlIRI. Imports retrieval and loading is deliberately left to the implementor.

Public Members

void *ctx

Loader context, can be anything.

CowlOntology *(*load_ontology)(void *ctx, CowlIRI *iri)

Pointer to a function that returns the ontology having the specified IRI.

Param ctx:

Loader context.

Param iri:

IRI of the ontology to load.

Return:

The imported ontology, or NULL on error.

void (*free)(void *ctx)

Pointer to a resource deallocator function for the context.

Note

Can be NULL if the context does not need to release resources.

Param ctx:

Loader context.

Reading ontologies as axiom streams

Other than deserializing ontologies into CowlOntology objects, Cowl supports a more lightweight abstraction to access ontology contents by means of CowlIStream instances, which can be obtained by calling cowl_manager_get_istream(). You must provide a suitably populated CowlIStreamHandlers object, which tells the library how each OWL construct detected in the byte stream should be handled.

struct CowlIStream

Ontology input stream.

A lightweight way to access knowledge without deserializing ontologies into CowlOntology objects.

Pseudo-extends: CowlObject

See also

CowlReader

CowlManager *cowl_istream_get_manager(CowlIStream *stream)

Gets the manager of this ontology input stream.

Parameters:
  • stream – The ontology input stream.

Returns:

The manager.

CowlSymTable *cowl_istream_get_sym_table(CowlIStream *stream)

Gets the symbol table of this ontology input stream.

Parameters:
  • stream – The ontology input stream.

Returns:

The symbol table.

cowl_ret cowl_istream_handle_iri(CowlIStream *stream, CowlIRI *iri)

Handles the specified ontology IRI.

Parameters:
  • stream – The ontology input stream.

  • iri – The ontology IRI.

Returns:

Return code.

cowl_ret cowl_istream_handle_version(CowlIStream *stream, CowlIRI *version)

Handles the specified ontology version IRI.

Parameters:
  • stream – The ontology input stream.

  • version – The version IRI.

Returns:

Return code.

cowl_ret cowl_istream_handle_import(CowlIStream *stream, CowlIRI *import)

Handles the specified import IRI.

Parameters:
  • stream – The ontology input stream.

  • import – The import IRI.

Returns:

Return code.

cowl_ret cowl_istream_handle_annot(CowlIStream *stream, CowlAnnotation *annot)

Handles the specified ontology annotation.

Parameters:
  • stream – The ontology input stream.

  • annot – The annotation.

Returns:

Return code.

cowl_ret cowl_istream_handle_axiom(CowlIStream *stream, CowlAnyAxiom *axiom)

Handles the specified axiom.

Parameters:
  • stream – The ontology input stream.

  • axiom – The axiom.

Returns:

Return code.

cowl_ret cowl_istream_process_path(CowlIStream *stream, UString path)

Streams through the ontology at the specified path.

Parameters:
  • stream – The ontology input stream.

  • path – The file path.

Returns:

Return code.

cowl_ret cowl_istream_process_file(CowlIStream *stream, FILE *file)

Streams through the ontology read from the specified file.

Parameters:
  • stream – The ontology input stream.

  • file – The file.

Returns:

Return code.

cowl_ret cowl_istream_process_string(CowlIStream *stream, UString const *string)

Streams through the ontology read from the specified string.

Parameters:
  • stream – The ontology input stream.

  • string – The string.

Returns:

Return code.

cowl_ret cowl_istream_process_stream(CowlIStream *stream, UIStream *istream)

Streams through the ontology read from the specified input stream.

Parameters:
  • stream – The ontology input stream.

  • istream – The input stream.

Returns:

Return code.

cowl_ret cowl_istream_process_ontology(CowlIStream *stream, CowlOntology *ontology)

Streams through the specified ontology.

Parameters:
  • stream – The ontology input stream.

  • ontology – The ontology.

Returns:

Return code.

struct CowlIStreamHandlers

Ontology input stream handlers.

Public Members

void *ctx

Stream context, can be anything.

cowl_ret (*iri)(void *ctx, CowlIRI *iri)

Pointer to a function that handles the specified ontology IRI.

Param ctx:

Stream context.

Param iri:

The ontology IRI.

Return:

Return code.

cowl_ret (*version)(void *ctx, CowlIRI *version)

Pointer to a function that handles the specified version IRI.

Param ctx:

Stream context.

Param version:

The version IRI.

Return:

Return code.

cowl_ret (*import)(void *ctx, CowlIRI *import)

Pointer to a function that handles the specified import IRI.

Param ctx:

Stream context.

Param import:

The import IRI.

Return:

Return code.

cowl_ret (*annot)(void *ctx, CowlAnnotation *annot)

Pointer to a function that handles the specified annotation.

Param ctx:

Stream context.

Param annot:

The annotation.

Return:

Return code.

cowl_ret (*axiom)(void *ctx, CowlAnyAxiom *axiom)

Pointer to a function that handles the specified axiom.

Param ctx:

Stream context.

Param axiom:

The axiom.

Return:

Return code.