<commit_before>/*
 * The ELepHant Reasoner
 *
 * Copyright (C) <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include "../model/datatypes.h"
#include "../model/model.h"
#include "../model/limits.h"
#include "../hashing/hash_map.h"
#include "utils.h"

/*
// The list of subclass axioms that are generated during  preprocessing
SubClassAxiom** generated_subclass_axioms = NULL;
int generated_subclass_axiom_count = 0;

// The list of subrole axioms that are generated during  preprocessing
SubRoleAxiom** generated_subrole_axioms = NULL;
int generated_subrole_axiom_count = 0;

// The hash of nominals that are generated during preprocessing.
KeyValueHashTable* generated_nominals = NULL;
// id of the last generated nominal
// int last_generated_nominal_id = 0;

// The hash of existential restrictions that are generated during preprocessing.
// They are generated from preprocessing role assertions.
KeyValueHashTable* generated_exists_restrictions = NULL;
int generated_exists_restriction_count = 0;
*/

// Preprocess axioms that are syntactic shortcuts, like equivalent classes/roles, disjoint classes and
// transtive roles. Translate them to subclass axioms for saturation.
void preprocess_tbox(KB* kb) {
	TBox* tbox = kb->tbox;

	// Initialize the hash of generated nominals
	// TODO: think about the size. maybe take the number of individuals?
	kb->generated_nominals = hash_map_create(DEFAULT_NOMINALS_HASH_SIZE);

	// Initialize the hash of existential restrictions that are generated as a result of
	// translating role assertions.
	// TODO: think about the size. maybe take the number of target individuals?
	kb->generated_exists_restrictions = hash_map_create(DEFAULT_EXISTS_RESTRICTIONS_HASH_SIZE);

	int i;

	// Convert equivalent classes axioms to subclass axioms
	for (i = 0; i < tbox->eqclass_axiom_count; ++i) {
		add_generated_subclass_axiom(kb, create_subclass_axiom(tbox->eqclass_axioms[i]->lhs, tbox->eqclass_axioms[i]->rhs));
		add_generated_subclass_axiom(kb, create_subclass_axiom(tbox->eqclass_axioms[i]->rhs, tbox->eqclass_axioms[i]->lhs));
	}

	// Convert equivalent roles axioms to subrole axioms
	for (i = 0; i < tbox->eqrole_axiom_count; ++i) {
		add_generated_subrole_axiom(kb, create_subrole_axiom(tbox->eqrole_axioms[i]->lhs, tbox->eqrole_axioms[i]->rhs));
		add_generated_subrole_axiom(kb, create_subrole_axiom(tbox->eqrole_axioms[i]->rhs, tbox->eqrole_axioms[i]->lhs));
	}

	// Process the transitive role axioms
	ObjectPropertyExpression* composition;
	for (i = 0; i < tbox->transitive_role_axiom_count; ++i) {
		composition = get_create_role_composition_binary(tbox->transitive_role_axioms[i]->r, tbox->transitive_role_axioms[i]->r, tbox);
		add_generated_subrole_axiom(kb, create_subrole_axiom(composition, tbox->transitive_role_axioms[i]->r));
	}

	// Process the disjointclasses axioms.
	// We express that the concept pairs imply bottom.
	// Note that this generates n^2 new subclass axioms for a disjointness axiom with n concepts.
	// TODO: optimize!
	int j, k;
	ClassExpression* conjunction;
	for (i = 0; i < tbox->disjointclasses_axiom_count; ++i)
		for (j = 0; j < tbox->disjointclasses_axioms[i]->classes.size - 1; ++j)
			for (k = j + 1; k < tbox->disjointclasses_axioms[i]->classes.size ; ++k) {
				// TODO: what about the conjunction created here? It modifies the model!
				conjunction = get_create_conjunction_binary(<commit_msg>Minor comment on the preprocessing of disjointclasses axioms.<commit_after>/*
 * The ELepHant Reasoner
 *
 * Copyright (C) <NAME> (<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include "../model/datatypes.h"
#include "../model/model.h"
#include "../model/limits.h"
#include "../hashing/hash_map.h"
#include "utils.h"

/*
// The list of subclass axioms that are generated during  preprocessing
SubClassAxiom** generated_subclass_axioms = NULL;
int generated_subclass_axiom_count = 0;

// The list of subrole axioms that are generated during  preprocessing
SubRoleAxiom** generated_subrole_axioms = NULL;
int generated_subrole_axiom_count = 0;

// The hash of nominals that are generated during preprocessing.
KeyValueHashTable* generated_nominals = NULL;
// id of the last generated nominal
// int last_generated_nominal_id = 0;

// The hash of existential restrictions that are generated during preprocessing.
// They are generated from preprocessing role assertions.
KeyValueHashTable* generated_exists_restrictions = NULL;
int generated_exists_restriction_count = 0;
*/

// Preprocess axioms that are syntactic shortcuts, like equivalent classes/roles, disjoint classes and
// transtive roles. Translate them to subclass axioms for saturation.
void preprocess_tbox(KB* kb) {
	TBox* tbox = kb->tbox;

	// Initialize the hash of generated nominals
	// TODO: think about the size. maybe take the number of individuals?
	kb->generated_nominals = hash_map_create(DEFAULT_NOMINALS_HASH_SIZE);

	// Initialize the hash of existential restrictions that are generated as a result of
	// translating role assertions.
	// TODO: think about the size. maybe take the number of target individuals?
	kb->generated_exists_restrictions = hash_map_create(DEFAULT_EXISTS_RESTRICTIONS_HASH_SIZE);

	int i;

	// Convert equivalent classes axioms to subclass axioms
	for (i = 0; i < tbox->eqclass_axiom_count; ++i) {
		add_generated_subclass_axiom(kb, create_subclass_axiom(tbox->eqclass_axioms[i]->lhs, tbox->eqclass_axioms[i]->rhs));
		add_generated_subclass_axiom(kb, create_subclass_axiom(tbox->eqclass_axioms[i]->rhs, tbox->eqclass_axioms[i]->lhs));
	}

	// Convert equivalent roles axioms to subrole axioms
	for (i = 0; i < tbox->eqrole_axiom_count; ++i) {
		add_generated_subrole_axiom(kb, create_subrole_axiom(tbox->eqrole_axioms[i]->lhs, tbox->eqrole_axioms[i]->rhs));
		add_generated_subrole_axiom(kb, create_subrole_axiom(tbox->eqrole_axioms[i]->rhs, tbox->eqrole_axioms[i]->lhs));
	}

	// Process the transitive role axioms
	ObjectPropertyExpression* composition;
	for (i = 0; i < tbox->transitive_role_axiom_count; ++i) {
		composition = get_create_role_composition_binary(tbox->transitive_role_axioms[i]->r, tbox->transitive_role_axioms[i]->r, tbox);
		add_generated_subrole_axiom(kb, create_subrole_axiom(composition, tbox->transitive_role_axioms[i]->r));
	}

	// Process the disjointclasses axioms.
	// We express that the concept pairs imply bottom.
	// Note that this generates n^2 new subclass axioms for a disjointness axiom with n concepts.
	// TODO: optimize!
	int j, k;
	ClassExpression* conjunction;
	for (i = 0; i < tbox->disjointclasses_axiom_count; ++i)
		for (j = 0; j < tbox->disjointclasses_axioms[i]->classes.size - 1; ++j)
			for (k = j + 1; k < tbox->disjointclasses_axioms[i]->classes.size ; ++k) {
				// Possibly a new conjunction is generated here, which modifies the model.
				// This is not a problem since the extended ontology (that is the ontology extended with the
				// new conjunction), will be indexed after the preprocessing step. So the new conjunction
				// will also be considered in the indexing information.
				conjunction = get_create_conjunction_binary(
{'fraction_non_alphanumeric': 0.10020800195766548, 'fraction_numerical': 0.003915330967820874, 'mean_word_length': 4.813655761024182, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2211410', 'n_tokens_mistral': 2726, 'n_tokens_neox': 2563, 'n_words': 797}