From 3d7cd8500c2314382198f5c6f3acb797482aafb0 Mon Sep 17 00:00:00 2001 From: Ivano Bilenchi Date: Fri, 30 Aug 2024 21:17:18 +0200 Subject: [PATCH] Account for owl:Thing and rdfs:Literal when iterating over quantifiers --- src/cowl_data_quant.c | 11 ++++++++++- src/cowl_data_quant_private.h | 21 +++++++++++++++++++++ src/cowl_obj_quant.c | 11 ++++++++++- src/cowl_obj_quant_private.h | 21 +++++++++++++++++++++ src/cowl_object.c | 6 ++++++ test/tests/cowl_ontology_tests.c | 2 +- 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/cowl_data_quant_private.h create mode 100644 src/cowl_obj_quant_private.h diff --git a/src/cowl_data_quant.c b/src/cowl_data_quant.c index 4f4f800..a01286b 100644 --- a/src/cowl_data_quant.c +++ b/src/cowl_data_quant.c @@ -8,11 +8,14 @@ * @file */ -#include "cowl_data_quant.h" #include "cowl_any.h" +#include "cowl_data_quant_private.h" #include "cowl_impl.h" +#include "cowl_iterator.h" #include "cowl_macros.h" +#include "cowl_object.h" #include "cowl_object_type.h" +#include "cowl_primitive_flags.h" #include "cowl_quant_type.h" #include "cowl_rdfs_vocab.h" #include @@ -28,3 +31,9 @@ CowlDataRange *cowl_data_quant_get_range(CowlDataQuant *restr) { CowlDataRange *range = cowl_get_opt_field(restr); return range ? range : (CowlDataRange *)cowl_rdfs_vocab()->dt.literal; } + +bool cowl_data_quant_iterate_primitives(CowlDataQuant *restr, CowlPrimitiveFlags flags, + CowlIterator *iter) { + return (cowl_iterate_primitives(cowl_data_quant_get_prop(restr), flags, iter) && + cowl_iterate_primitives(cowl_data_quant_get_range(restr), flags, iter)); +} diff --git a/src/cowl_data_quant_private.h b/src/cowl_data_quant_private.h new file mode 100644 index 0000000..076ce99 --- /dev/null +++ b/src/cowl_data_quant_private.h @@ -0,0 +1,21 @@ +/** + * @author Ivano Bilenchi + * + * @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari + * @copyright + * @copyright SPDX-License-Identifier: EPL-2.0 + * + * @file + */ + +#ifndef COWL_DATA_QUANT_PRIVATE_H +#define COWL_DATA_QUANT_PRIVATE_H + +#include "cowl_data_quant.h" // IWYU pragma: export +#include "cowl_iterator.h" +#include "cowl_primitive_flags.h" + +bool cowl_data_quant_iterate_primitives(CowlDataQuant *restr, CowlPrimitiveFlags flags, + CowlIterator *iter); + +#endif // COWL_DATA_QUANT_PRIVATE_H diff --git a/src/cowl_obj_quant.c b/src/cowl_obj_quant.c index 77fb330..8c66c3a 100644 --- a/src/cowl_obj_quant.c +++ b/src/cowl_obj_quant.c @@ -8,12 +8,15 @@ * @file */ -#include "cowl_obj_quant.h" #include "cowl_any.h" #include "cowl_impl.h" +#include "cowl_iterator.h" #include "cowl_macros.h" +#include "cowl_obj_quant_private.h" +#include "cowl_object.h" #include "cowl_object_type.h" #include "cowl_owl_vocab.h" +#include "cowl_primitive_flags.h" #include "cowl_quant_type.h" #include @@ -27,3 +30,9 @@ CowlClsExp *cowl_obj_quant_get_filler(CowlObjQuant *restr) { CowlClsExp *filler = cowl_get_opt_field(restr); return filler ? filler : (CowlClsExp *)cowl_owl_vocab()->cls.thing; } + +bool cowl_obj_quant_iterate_primitives(CowlObjQuant *restr, CowlPrimitiveFlags flags, + CowlIterator *iter) { + return (cowl_iterate_primitives(cowl_obj_quant_get_prop(restr), flags, iter) && + cowl_iterate_primitives(cowl_obj_quant_get_filler(restr), flags, iter)); +} diff --git a/src/cowl_obj_quant_private.h b/src/cowl_obj_quant_private.h new file mode 100644 index 0000000..8baf484 --- /dev/null +++ b/src/cowl_obj_quant_private.h @@ -0,0 +1,21 @@ +/** + * @author Ivano Bilenchi + * + * @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari + * @copyright + * @copyright SPDX-License-Identifier: EPL-2.0 + * + * @file + */ + +#ifndef COWL_OBJ_QUANT_PRIVATE_H +#define COWL_OBJ_QUANT_PRIVATE_H + +#include "cowl_iterator.h" +#include "cowl_obj_quant.h" // IWYU pragma: export +#include "cowl_primitive_flags.h" + +bool cowl_obj_quant_iterate_primitives(CowlObjQuant *restr, CowlPrimitiveFlags flags, + CowlIterator *iter); + +#endif // COWL_OBJ_QUANT_PRIVATE_H diff --git a/src/cowl_object.c b/src/cowl_object.c index 83ebcbd..2e03cbd 100644 --- a/src/cowl_object.c +++ b/src/cowl_object.c @@ -13,6 +13,7 @@ #include "cowl_anon_ind_private.h" #include "cowl_any.h" #include "cowl_axiom.h" +#include "cowl_data_quant_private.h" #include "cowl_entity.h" #include "cowl_entity_private.h" #include "cowl_iri.h" @@ -21,6 +22,7 @@ #include "cowl_iterator.h" #include "cowl_literal_private.h" #include "cowl_manager_private.h" +#include "cowl_obj_quant_private.h" #include "cowl_object_flags.h" #include "cowl_object_private.h" #include "cowl_object_type.h" @@ -426,6 +428,10 @@ bool cowl_iterate_primitives(CowlAny *object, CowlPrimitiveFlags flags, CowlIter case COWL_OT_I_NAMED: return iterate_pf(COWL_PF_NAMED_IND, object, flags, iter); case COWL_OT_I_ANONYMOUS: return iterate_pf(COWL_PF_ANON_IND, object, flags, iter); case COWL_OT_OPE_OBJ_PROP: return iterate_pf(COWL_PF_OBJ_PROP, object, flags, iter); + case COWL_OT_CE_OBJ_SOME: + case COWL_OT_CE_OBJ_ALL: return cowl_obj_quant_iterate_primitives(object, flags, iter); + case COWL_OT_CE_DATA_SOME: + case COWL_OT_CE_DATA_ALL: return cowl_data_quant_iterate_primitives(object, flags, iter); case COWL_OT_ONTOLOGY: return cowl_ontology_iterate_primitives(object, flags, iter, false); default: return iterate_impl(type, object, flags, iter); } diff --git a/test/tests/cowl_ontology_tests.c b/test/tests/cowl_ontology_tests.c index 10ade6a..9f4c5e7 100644 --- a/test/tests/cowl_ontology_tests.c +++ b/test/tests/cowl_ontology_tests.c @@ -28,7 +28,7 @@ static CowlOntology *onto = NULL; static ulib_uint const test_onto_imports_count = 1; static ulib_uint const test_onto_axiom_count = 571; -static ulib_uint const test_primitives_count[] = { 105, 48, 72, 27, 18, 1, 46, 12 }; +static ulib_uint const test_primitives_count[] = { 106, 48, 72, 27, 18, 1, 46, 12 }; static ulib_uint const test_primitive_axiom_count[] = { 16, 4, 4, 2, 2, 1, 2, 8 }; static ulib_uint axiom_counts_by_type[COWL_AT_COUNT] = { 0 };