Skip to content

Commit

Permalink
Replace CowlAxiomIndex with CowlAxiomFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanoBilenchi committed Mar 22, 2024
1 parent 4615d95 commit 3fd0a7d
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 256 deletions.
4 changes: 4 additions & 0 deletions docs/api/crud/query_edit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ finding the first construct that matches some condition.
.. doxygengroup:: CowlAxiomFlags_api
:content-only:

.. doxygenstruct:: CowlAxiomFilter
.. doxygengroup:: CowlAxiomFilter
:content-only:

.. _editing:

Editing ontologies
Expand Down
2 changes: 1 addition & 1 deletion include/cowl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "cowl_any.h"
#include "cowl_attrs.h"
#include "cowl_axiom.h"
#include "cowl_axiom_filter.h"
#include "cowl_axiom_flags.h"
#include "cowl_axiom_index.h"
#include "cowl_axiom_type.h"
#include "cowl_card_type.h"
#include "cowl_char_axiom_type.h"
Expand Down
131 changes: 131 additions & 0 deletions include/cowl_axiom_filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* Defines CowlAxiomFilter and declares its API.
*
* @author Ivano Bilenchi
*
* @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari
* @copyright <http://swot.sisinflab.poliba.it>
* @copyright SPDX-License-Identifier: EPL-2.0
*
* @file
*/

#ifndef COWL_AXIOM_FILTER_H
#define COWL_AXIOM_FILTER_H

#include "cowl_axiom_flags.h"
#include "cowl_vector.h"

COWL_BEGIN_DECLS

/// Axiom filter.
typedef struct CowlAxiomFilter {

/// Match axioms of the specified types.
CowlAxiomFlags types;

/// Match axioms referencing all the specified primitives.
UVec(CowlObjectPtr) primitives;

/// Match axioms based on the specified closure.
CowlFilter closure;

} CowlAxiomFilter;

/**
* @defgroup CowlAxiomFilter CowlAxiomFilter API
* @{
*/

/**
* Returns a new axiom filter.
*
* @param types Axiom types.
* @return Axiom filter.
*/
COWL_CONST
COWL_INLINE
CowlAxiomFilter cowl_axiom_filter(CowlAxiomFlags types) {
CowlAxiomFilter ret = { types, uvec(CowlObjectPtr), ulib_struct_init };
return ret;
}

/**
* De-initializes an axiom filter previously initialized via @func{#cowl_axiom_filter()}.
*
* @param filter Axiom filter.
*/
COWL_INLINE
void cowl_axiom_filter_deinit(CowlAxiomFilter *filter) {
uvec_foreach (CowlObjectPtr, &filter->primitives, p) {
cowl_release(*p.item);
}
uvec_deinit(CowlObjectPtr, &filter->primitives);
}

/**
* Adds the specified axiom type to the filter.
*
* @param filter Axiom filter.
* @param type Axiom type.
*/
COWL_INLINE
void cowl_axiom_filter_add_type(CowlAxiomFilter *filter, CowlAxiomType type) {
filter->types = ubit_set(COWL_AF, filter->types, cowl_axiom_flags_from_type(type));
}

/**
* Removes the specified axiom type from the filter.
*
* @param filter Axiom filter.
* @param type Axiom type.
*/
COWL_INLINE
void cowl_axiom_filter_remove_type(CowlAxiomFilter *filter, CowlAxiomType type) {
filter->types = ubit_unset(COWL_AF, filter->types, cowl_axiom_flags_from_type(type));
}

/**
* Adds the specified primitive to the filter.
*
* @param filter Axiom filter.
* @param primitive Primitive.
* @return Return code.
*/
COWL_INLINE
cowl_ret cowl_axiom_filter_add_primitive(CowlAxiomFilter *filter, CowlAnyPrimitive *primitive) {
uvec_ret ret = uvec_push_unique(CowlObjectPtr, &filter->primitives, primitive);
if (ret == UVEC_OK) cowl_retain(primitive);
return ret == UVEC_ERR ? COWL_ERR_MEM : COWL_OK;
}

/**
* Removes the specified primitive from the filter.
*
* @param filter Axiom filter.
* @param primitive Primitive.
*/
COWL_INLINE
void cowl_axiom_filter_remove_primitive(CowlAxiomFilter *filter, CowlAnyPrimitive *primitive) {
if (uvec_remove(CowlObjectPtr, &filter->primitives, primitive)) {
cowl_release(primitive);
}
uvec_shrink(CowlObjectPtr, &filter->primitives);
}

/**
* Sets the filter closure.
*
* @param filter Axiom filter.
* @param closure Filter closure.
*/
COWL_INLINE
void cowl_axiom_filter_set_closure(CowlAxiomFilter *filter, CowlFilter closure) {
filter->closure = closure;
}

/// @}

COWL_END_DECLS

#endif // COWL_AXIOM_FILTER_H
24 changes: 24 additions & 0 deletions include/cowl_axiom_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,30 @@ bool cowl_axiom_flags_has_type(CowlAxiomFlags flags, CowlAxiomType type) {
return ubit_is_set(COWL_AF, flags, ubit_bit(COWL_AF, type));
}

/**
* Checks whether the flags match all axiom types.
*
* @param flags Axiom flags.
* @return True if the flags match all axiom types, false otherwise.
*/
COWL_CONST
COWL_INLINE
bool cowl_axiom_flags_has_all_types(CowlAxiomFlags flags) {
return ubit_is_set(COWL_AF, flags, COWL_AF_ALL);
}

/**
* Checks whether the flags match no axiom types.
*
* @param flags Axiom flags.
* @return True if the flags match no axiom types, false otherwise.
*/
COWL_CONST
COWL_INLINE
bool cowl_axiom_flags_has_no_types(CowlAxiomFlags flags) {
return !ubit_is_any_set(COWL_AF, flags, COWL_AF_ALL);
}

/**
* Iterates over the flags, executing the specified code block for each axiom type.
*
Expand Down
110 changes: 0 additions & 110 deletions include/cowl_axiom_index.h

This file was deleted.

16 changes: 7 additions & 9 deletions include/cowl_ontology.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ COWL_BEGIN_DECLS

/// @cond
cowl_struct_decl(CowlAnnotation);
cowl_struct_decl(CowlAxiomIndex);
cowl_struct_decl(CowlAxiomFilter);
cowl_struct_decl(CowlClass);
cowl_struct_decl(CowlManager);
cowl_struct_decl(CowlSymTable);
Expand Down Expand Up @@ -191,15 +191,13 @@ bool cowl_ontology_remove_axiom(CowlOntology *onto, CowlAnyAxiom *axiom);
* Removes the axioms matching the provided filter function.
*
* @param onto The ontology.
* @param index The index.
* @param filter The filter.
* @return Number of removed axioms.
*
* @note The index must not be used anymore after calling this function.
* @note The filter must not be used anymore after calling this function.
*/
COWL_API
ulib_uint
cowl_ontology_remove_axioms_matching(CowlOntology *onto, CowlAxiomIndex *index, CowlFilter *filter);
ulib_uint cowl_ontology_remove_axioms_matching(CowlOntology *onto, CowlAxiomFilter *filter);

/**
* Gets the number of axioms in the ontology.
Expand Down Expand Up @@ -384,18 +382,18 @@ bool cowl_ontology_iterate_axioms_for_primitive(CowlOntology *onto, CowlAnyPrimi
CowlIterator *iter, bool imports);

/**
* Iterates over the axioms matching the specified index.
* Iterates over the axioms matching the specified filter.
*
* @param onto The ontology.
* @param index The index.
* @param filter The filter.
* @param iter The iterator.
* @param imports If true, the query recurses over imported ontologies.
* @return True if the iteration was completed, false if it was stopped.
*
* @note The index must not be used anymore after calling this function.
* @note The filter must not be used anymore after calling this function.
*/
COWL_API
bool cowl_ontology_iterate_axioms_matching(CowlOntology *onto, CowlAxiomIndex *index,
bool cowl_ontology_iterate_axioms_matching(CowlOntology *onto, CowlAxiomFilter *filter,
CowlIterator *iter, bool imports);

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/ulib
Loading

0 comments on commit 3fd0a7d

Please sign in to comment.