Skip to content

Commit

Permalink
Remove 'CowlOntologyId' and add 'cowl_manager_new_ontology'
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanoBilenchi committed Aug 24, 2024
1 parent df2bd88 commit fe5fd4f
Show file tree
Hide file tree
Showing 21 changed files with 113 additions and 207 deletions.
7 changes: 1 addition & 6 deletions docs/api/crud/query_edit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ to retrieve, add, or remove axioms, annotations, and other constructs.
.. doxygengroup:: CowlOntology
:content-only:

.. doxygenstruct:: CowlOntologyId
.. doxygengroup:: CowlOntologyId
:content-only:

.. _querying:

Querying ontologies
Expand Down Expand Up @@ -53,8 +49,7 @@ Editing ontologies

Ontologies can be edited by adding or removing axioms, annotations and other constructs,
as allowed by the :struct:`CowlOntology` API. They can also be created from scratch by calling
:func:`cowl_manager_get_ontology()` and specifying a unique :struct:`CowlOntologyId`
or a ``NULL`` one, in which case an anonymous ontology is created.
:func:`cowl_manager_new_ontology()`.

Access to syntactical details that are not relevant to logic, such as the mapping between
prefixed and full IRIs, is provided by a :struct:`CowlSymTable` instance retrievable by calling
Expand Down
2 changes: 1 addition & 1 deletion examples/07_ostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(void) {
uvec_push(CowlObjectPtr, &imports, import_iri);

CowlOntologyHeader header = {
.id = { iri },
.iri = iri,
.imports = &imports,
};

Expand Down
1 change: 0 additions & 1 deletion include/cowl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
#include "cowl_object_type.h"
#include "cowl_ontology.h"
#include "cowl_ontology_header.h"
#include "cowl_ontology_id.h"
#include "cowl_ostream.h"
#include "cowl_owl_vocab.h"
#include "cowl_position.h"
Expand Down
34 changes: 23 additions & 11 deletions include/cowl_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef COWL_MANAGER_H
#define COWL_MANAGER_H

#include "cowl_attrs.h"
#include "cowl_error_handler.h"
#include "cowl_import_loader.h"
#include "cowl_istream_handlers.h"
Expand All @@ -24,7 +25,6 @@ COWL_BEGIN_DECLS
/// @cond
cowl_struct_decl(CowlIStream);
cowl_struct_decl(CowlOntology);
cowl_struct_decl(CowlOntologyId);
cowl_struct_decl(CowlOStream);
/// @endcond

Expand Down Expand Up @@ -146,29 +146,41 @@ COWL_API
bool cowl_manager_iterate_ontologies(CowlManager *manager, CowlIterator *iter);

/**
* Gets the ontology with the specified identifier.
* If no existing ontology has the specified identifier, a new ontology is returned.
* Returns a new empty ontology.
*
* @param manager The manager.
* @param id The ontology identifier.
* @return Ontology with the specified identifier.
* @return New ontology.
*/
COWL_API
COWL_RETAINED
CowlOntology *cowl_manager_new_ontology(CowlManager *manager);

/**
* Gets the ontology with the specified IRI and version.
* If no existing ontology has the specified IRI and version, a new ontology is returned.
*
* @param manager The manager.
* @param iri The ontology IRI.
* @param version The ontology version.
* @return Ontology with the specified IRI and version.
*
* @note You can pass NULL as the ontology identifier, in which case the function returns
* @note You can pass NULL as the IRI and version, in which case the function returns
* a new anonymous ontology.
*/
COWL_API
COWL_RETAINED
CowlOntology *cowl_manager_get_ontology(CowlManager *manager, CowlOntologyId const *id);
CowlOntology *cowl_manager_get_ontology(CowlManager *manager, CowlIRI *iri, CowlIRI *version);

/**
* Gets the ontology with the specified identifier, if it exists.
* Gets the ontology with the specified IRI and version, if it exists.
*
* @param manager The manager.
* @param id The ontology identifier.
* @return Ontology with the specified identifier, or NULL if it does not exist.
* @param iri The ontology IRI.
* @param version The ontology version.
* @return Ontology with the specified IRI and version, or NULL if it does not exist.
*/
COWL_API
CowlOntology *cowl_manager_retrieve_ontology(CowlManager *manager, CowlOntologyId const *id);
CowlOntology *cowl_manager_retrieve_ontology(CowlManager *manager, CowlIRI *iri, CowlIRI *version);

/**
* Reads an ontology from the file at the specified path.
Expand Down
17 changes: 13 additions & 4 deletions include/cowl_ontology.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "cowl_axiom_type.h"
#include "cowl_iterator.h"
#include "cowl_object.h"
#include "cowl_ontology_id.h"
#include "cowl_position.h"
#include "cowl_ret.h"

Expand Down Expand Up @@ -68,14 +67,14 @@ COWL_PURE
CowlSymTable *cowl_ontology_get_sym_table(CowlOntology *onto);

/**
* Gets the ontology ID.
* Gets the IRI of the ontology.
*
* @param onto The ontology.
* @return The ontology ID.
* @return The ontology IRI.
*/
COWL_API
COWL_PURE
CowlOntologyId cowl_ontology_get_id(CowlOntology *onto);
CowlIRI *cowl_ontology_get_iri(CowlOntology *onto);

/**
* Sets the IRI of the ontology.
Expand All @@ -86,6 +85,16 @@ CowlOntologyId cowl_ontology_get_id(CowlOntology *onto);
COWL_API
void cowl_ontology_set_iri(CowlOntology *onto, CowlIRI *iri);

/**
* Gets the version of the ontology.
*
* @param onto The ontology.
* @return The version IRI.
*/
COWL_API
COWL_PURE
CowlIRI *cowl_ontology_get_version(CowlOntology *onto);

/**
* Sets the version IRI of the ontology.
*
Expand Down
10 changes: 6 additions & 4 deletions include/cowl_ontology_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
#ifndef COWL_ONTOLOGY_HEADER_H
#define COWL_ONTOLOGY_HEADER_H

#include "cowl_ontology_id.h"
#include "cowl_vector.h"

COWL_BEGIN_DECLS

/// Models an ontology header.
typedef struct CowlOntologyHeader {

/// Ontology identifier.
CowlOntologyId id;
/// Ontology IRI.
CowlIRI *iri;

/// Ontology version.
CowlIRI *version;

/// Import IRIs.
UVec(CowlObjectPtr) const *imports;
Expand All @@ -45,7 +47,7 @@ typedef struct CowlOntologyHeader {
COWL_CONST
COWL_INLINE
CowlOntologyHeader cowl_ontology_header_empty(void) {
CowlOntologyHeader header = { cowl_ontology_id_anonymous(), NULL, NULL };
CowlOntologyHeader header = { NULL, NULL, NULL, NULL };
return header;
}

Expand Down
89 changes: 0 additions & 89 deletions include/cowl_ontology_id.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/cowl_error_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cowl_ret cowl_handle_syntax_error(UString desc, CowlAny *origin, CowlErrorLoc lo
bool release_source = false;

if (!loc.source && cowl_get_type(origin) == COWL_OT_ONTOLOGY) {
loc.source = cowl_to_string(cowl_ontology_get_id(origin).iri);
loc.source = cowl_to_string(cowl_ontology_get_iri(origin));
release_source = true;
}

Expand Down
12 changes: 8 additions & 4 deletions src/cowl_istream.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ cowl_ret cowl_istream_process_ontology(CowlIStream *stream, CowlOntology *onto)
cowl_ret ret = COWL_OK;
CowlIStreamHandlers *handle = &stream->handlers;

if (handle->iri || handle->version) {
CowlOntologyId id = cowl_ontology_get_id(onto);
if (handle->iri && (ret = handle->iri(handle->ctx, id.iri))) return ret;
if (handle->version && (ret = handle->version(handle->ctx, id.version))) return ret;
if (handle->iri) {
CowlIRI *iri = cowl_ontology_get_iri(onto);
if (iri && (ret = handle->iri(handle->ctx, iri))) return ret;
}

if (handle->version) {
CowlIRI *version = cowl_ontology_get_version(onto);
if (version && (ret = handle->version(handle->ctx, version))) return ret;
}

if (handle->annot) {
Expand Down
34 changes: 18 additions & 16 deletions src/cowl_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "cowl_object_private.h"
#include "cowl_object_type.h"
#include "cowl_ontology.h"
#include "cowl_ontology_id.h"
#include "cowl_ontology_private.h"
#include "cowl_ostream.h"
#include "cowl_ostream_private.h"
Expand Down Expand Up @@ -232,32 +231,35 @@ bool cowl_manager_iterate_ontologies(CowlManager *manager, CowlIterator *iter) {
return true;
}

CowlOntology *cowl_manager_retrieve_ontology(CowlManager *manager, CowlOntologyId const *id) {
uvec_foreach (CowlObjectPtr, &manager->ontos, onto) {
if (cowl_ontology_id_equals(cowl_ontology_get_id(*onto.item), *id)) {
return *onto.item;
}
}
return NULL;
CowlOntology *cowl_manager_new_ontology(CowlManager *manager) {
return cowl_ontology(manager);
}

CowlOntology *cowl_manager_get_ontology(CowlManager *manager, CowlOntologyId const *id) {
if (id) {
CowlOntology *onto = cowl_manager_retrieve_ontology(manager, id);
CowlOntology *cowl_manager_get_ontology(CowlManager *manager, CowlIRI *iri, CowlIRI *version) {
if (iri) {
CowlOntology *onto = cowl_manager_retrieve_ontology(manager, iri, version);
if (onto) return cowl_retain(onto);
}

CowlOntology *onto = cowl_ontology(manager);
CowlOntology *onto = cowl_manager_new_ontology(manager);
if (!onto) return NULL;

if (id) {
cowl_ontology_set_iri(onto, id->iri);
cowl_ontology_set_version(onto, id->version);
}
if (iri) cowl_ontology_set_iri(onto, iri);
if (version) cowl_ontology_set_version(onto, version);

return onto;
}

CowlOntology *cowl_manager_retrieve_ontology(CowlManager *manager, CowlIRI *iri, CowlIRI *version) {
uvec_foreach (CowlObjectPtr, &manager->ontos, onto) {
if (cowl_ontology_get_iri(*onto.item) == iri &&
cowl_ontology_get_version(*onto.item) == version) {
return *onto.item;
}
}
return NULL;
}

cowl_ret cowl_manager_add_ontology(CowlManager *manager, CowlOntology *onto) {
return uvec_push(CowlObjectPtr, &manager->ontos, onto) ? COWL_ERR_MEM : COWL_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cowl_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ CowlIRI *cowl_get_iri(CowlAny *object) {
CowlObjectType type = cowl_get_type(object);
if (type_is_entity(type)) return cowl_entity_get_iri(object);
if (type == COWL_OT_IRI) return object;
return type == COWL_OT_ONTOLOGY ? cowl_ontology_get_id(object).iri : NULL;
return type == COWL_OT_ONTOLOGY ? cowl_ontology_get_iri(object) : NULL;
}

bool cowl_has_iri(CowlAny *object, CowlIRI *iri) {
Expand Down
Loading

0 comments on commit fe5fd4f

Please sign in to comment.