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 throughcowl_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 viacowl_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.
-
void *ctx
Reader context.
-
cowl_ret (*read)(void *ctx, UIStream *istream, CowlIStream *stream)
Pointer to a function that reads an ontology from an input stream.
Note
This member is mandatory.
- Param ctx:
Reader context.
- Param istream:
Input stream.
- Param stream:
Ontology input stream.
- Return:
Return code.
-
void (*free)(void *ctx)
Pointer to a function that frees the reader context.
Note
This member is optional. If not set, the reader context will not be freed.
- Param ctx:
Reader context.
-
char const *name
-
void cowl_reader_free_ctx(CowlReader *reader)
Frees the reader context.
- Parameters:
reader – The reader.
-
CowlReader cowl_reader_functional(void)
Returns the functional syntax reader.
- Returns:
Functional syntax reader.
-
CowlReader cowl_reader_default(void)
Returns the default reader.
- Returns:
Default reader.
Handling imports
Cowl delegates locating and loading imported ontologies to the end user via the
CowlImportResolver
interface. Import resolvers can be provided to CowlManager
instances via cowl_manager_set_import_resolver()
. By default, CowlManager
will
attempt to resolve imports based on the IRIs of ontologies it is currently responsible for,
i.e. those that have been loaded or created through it.
-
struct CowlImportResolver
Provides a mechanism for generic handling of ontology imports.
The
resolve_import
function should return the ontology associated to the specifiedCowlIRI
. Imports retrieval and loading is deliberately left to the implementor.Public Members
-
void *ctx
Resolver context, can be anything.
-
CowlOntology *(*resolve_import)(void *ctx, CowlIRI *iri)
Pointer to a function that returns the ontology associated to the specified IRI.
Note
The returned ontology must be retained.
- Param ctx:
Resolver context.
- Param iri:
The IRI.
- Return:
Imported ontology, or NULL on error.
-
void (*free)(void *ctx)
Pointer to a function that frees the resolver context.
Note
This member is optional. If not set, the resolver context will not be freed.
- Param ctx:
Resolver context.
-
void *ctx
-
void cowl_import_resolver_free_ctx(CowlImportResolver *resolver)
Frees the import resolver context.
- Parameters:
resolver – The resolver.
-
CowlOntology *cowl_import_resolver_resolve_import(CowlImportResolver const *resolver, CowlIRI *iri)
Returns the ontology associated to the specified IRI.
Note
You must release the returned object via
cowl_release()
.- Parameters:
resolver – The resolver.
iri – The IRI.
- Returns:
Imported ontology, or NULL on error.
-
CowlImportResolver cowl_import_resolver_default(CowlManager *manager)
Default import resolver, which looks for the ontology with the specified IRI in the manager’s ontologies.
Note
The manager is set as the resolver context, but it is not retained.
- Parameters:
manager – The manager.
- Returns:
Default import resolver.
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
-
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 *onto)
Streams through the specified ontology.
- Parameters:
stream – The ontology input stream.
onto – 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.
-
void *ctx