src/index/index.c
/*
 * Index a given ontology: Collect information about told subsumer, negative occurrence of exists restrictions,
 * and conjuncts of the conjunctions.
 * Returns:
 * 	-1: if the reasoning task is consistency check, and an atomic concept or the top concept is
 * 	subsumed by bottom. In this case it immediately returns, i.e., the rest of the KB is not indexed!
 * 	1: if the reasoning task is consistency check, and bottom does not appear on the rhs of any axiom.
 * 	The KB cannot be inconsistent in this case.
 * 	0: if none of the above holds. (In this case, we need to saturate the ontology for checking consistency)
 */
Index a given ontology: Collect information about told subsumer, negative occurrence of exists restrictions,
and conjuncts of the conjunctions.
Returns:
-1: if the reasoning task is consistency check, and an atomic concept or the top concept is
subsumed by bottom. In this case it immediately returns, i.e., the rest of the KB is not indexed.
1: if the reasoning task is consistency check, and bottom does not appear on the rhs of any axiom.
The KB cannot be inconsistent in this case.
0: if none of the above holds. (In this case, we need to saturate the ontology for checking consistency)
Index a given ontology : Collect information about told subsumer negative occurrence of exists restrictions and conjuncts of the conjunctions . Returns : - 1 : if the reasoning task is consistency check and an atomic concept or the top concept is subsumed by bottom . In this case it immediately returns i . e . the rest of the KB is not indexed . 1 : if the reasoning task is consistency check and bottom does not appear on the rhs of any axiom . The KB cannot be inconsistent in this case . 0 : if none of the above holds . ( In this case we need to saturate the ontology for checking consistency )
char index_tbox(KB* kb, ReasoningTask reasoning_task) {
	int i;
	SetIterator iterator;
	SET_ITERATOR_INIT(&iterator, &(kb->tbox->subclass_of_axioms));
	SubClassOfAxiom* subclass_ax = (SubClassOfAxiom*) SET_ITERATOR_NEXT(&iterator);
	while (subclass_ax) {
		if (subclass_ax->rhs == kb->tbox->bottom_concept) {
			if (subclass_ax->lhs->type == OBJECT_ONE_OF_TYPE || subclass_ax->lhs == kb->tbox->top_concept)
				return -1;
		}
		if (subclass_ax->lhs == kb->tbox->bottom_concept) {
			subclass_ax = (SubClassOfAxiom*) SET_ITERATOR_NEXT(&iterator);
			continue;
		}
		if (subclass_ax->rhs == kb->tbox->top_concept) {
			index_class_expression(subclass_ax->lhs, kb);
			subclass_ax = (SubClassOfAxiom*) SET_ITERATOR_NEXT(&iterator);
			continue;
		}
		ADD_TOLD_SUBSUMER_CLASS_EXPRESSION(subclass_ax->rhs, subclass_ax->lhs);
		index_class_expression(subclass_ax->lhs, kb);
		if (class_expression_contains_bottom(subclass_ax->rhs, kb->tbox) && subclass_ax->lhs != kb->tbox->bottom_concept)
			kb->bottom_occurs_on_rhs = 1;
		subclass_ax = (SubClassOfAxiom*) SET_ITERATOR_NEXT(&iterator);
	}
	for (i = 0; i < kb->generated_subclass_axiom_count; ++i) {
		if (kb->generated_subclass_axioms[i]->rhs == kb->tbox->bottom_concept)  {
			if (kb->generated_subclass_axioms[i]->lhs->type == OBJECT_ONE_OF_TYPE || kb->generated_subclass_axioms[i]->lhs == kb->tbox->top_concept)
				return -1;
		}
		if (kb->generated_subclass_axioms[i]->lhs == kb->tbox->bottom_concept)
			continue;
		if (kb->generated_subclass_axioms[i]->rhs == kb->tbox->top_concept) {
			index_class_expression(kb->generated_subclass_axioms[i]->lhs, kb);
			continue;
		}
		ADD_TOLD_SUBSUMER_CLASS_EXPRESSION(kb->generated_subclass_axioms[i]->rhs, kb->generated_subclass_axioms[i]->lhs);
		index_class_expression(kb->generated_subclass_axioms[i]->lhs, kb);
		if (class_expression_contains_bottom(kb->generated_subclass_axioms[i]->rhs, kb->tbox) && kb->generated_subclass_axioms[i]->lhs != kb->tbox->bottom_concept)
			kb->bottom_occurs_on_rhs = 1;
	}
	if (reasoning_task == CONSISTENCY && kb->bottom_occurs_on_rhs == 0)
		return 1;
	SET_ITERATOR_INIT(&iterator, &(kb->tbox->subobjectproperty_of_axioms));
	SubObjectPropertyOfAxiom* subrole_ax = (SubObjectPropertyOfAxiom*) SET_ITERATOR_NEXT(&iterator);
	while (subrole_ax) {
		ADD_TOLD_SUBSUMER_OBJECT_PROPERTY_EXPRESSION(subrole_ax->rhs, subrole_ax->lhs);
		index_role(subrole_ax->lhs);
		subrole_ax = (SubObjectPropertyOfAxiom*) SET_ITERATOR_NEXT(&iterator);
	}
	for (i = 0; i < kb->generated_subrole_axiom_count; ++i) {
		ADD_TOLD_SUBSUMER_OBJECT_PROPERTY_EXPRESSION(kb->generated_subrole_axioms[i]->rhs, kb->generated_subrole_axioms[i]->lhs);
		index_role(kb->generated_subrole_axioms[i]->lhs);
	}
	return 0;
}
char index_tbox ( KB * kb , ReasoningTask reasoning_task ) { int i ; SetIterator iterator ; SET_ITERATOR_INIT ( & iterator , & ( kb -> tbox -> subclass_of_axioms ) ) ; SubClassOfAxiom * subclass_ax = ( SubClassOfAxiom * ) SET_ITERATOR_NEXT ( & iterator ) ; while ( subclass_ax ) { if ( subclass_ax -> rhs == kb -> tbox -> bottom_concept ) { if ( subclass_ax -> lhs -> type == OBJECT_ONE_OF_TYPE || subclass_ax -> lhs == kb -> tbox -> top_concept ) return -1 ; } if ( subclass_ax -> lhs == kb -> tbox -> bottom_concept ) { subclass_ax = ( SubClassOfAxiom * ) SET_ITERATOR_NEXT ( & iterator ) ; continue ; } if ( subclass_ax -> rhs == kb -> tbox -> top_concept ) { index_class_expression ( subclass_ax -> lhs , kb ) ; subclass_ax = ( SubClassOfAxiom * ) SET_ITERATOR_NEXT ( & iterator ) ; continue ; } ADD_TOLD_SUBSUMER_CLASS_EXPRESSION ( subclass_ax -> rhs , subclass_ax -> lhs ) ; index_class_expression ( subclass_ax -> lhs , kb ) ; if ( class_expression_contains_bottom ( subclass_ax -> rhs , kb -> tbox ) && subclass_ax -> lhs != kb -> tbox -> bottom_concept ) kb -> bottom_occurs_on_rhs = 1 ; subclass_ax = ( SubClassOfAxiom * ) SET_ITERATOR_NEXT ( & iterator ) ; } for ( i = 0 ; i < kb -> generated_subclass_axiom_count ; ++ i ) { if ( kb -> generated_subclass_axioms [ i ] -> rhs == kb -> tbox -> bottom_concept ) { if ( kb -> generated_subclass_axioms [ i ] -> lhs -> type == OBJECT_ONE_OF_TYPE || kb -> generated_subclass_axioms [ i ] -> lhs == kb -> tbox -> top_concept ) return -1 ; } if ( kb -> generated_subclass_axioms [ i ] -> lhs == kb -> tbox -> bottom_concept ) continue ; if ( kb -> generated_subclass_axioms [ i ] -> rhs == kb -> tbox -> top_concept ) { index_class_expression ( kb -> generated_subclass_axioms [ i ] -> lhs , kb ) ; continue ; } ADD_TOLD_SUBSUMER_CLASS_EXPRESSION ( kb -> generated_subclass_axioms [ i ] -> rhs , kb -> generated_subclass_axioms [ i ] -> lhs ) ; index_class_expression ( kb -> generated_subclass_axioms [ i ] -> lhs , kb ) ; if ( class_expression_contains_bottom ( kb -> generated_subclass_axioms [ i ] -> rhs , kb -> tbox ) && kb -> generated_subclass_axioms [ i ] -> lhs != kb -> tbox -> bottom_concept ) kb -> bottom_occurs_on_rhs = 1 ; } if ( reasoning_task == CONSISTENCY && kb -> bottom_occurs_on_rhs == 0 ) return 1 ; SET_ITERATOR_INIT ( & iterator , & ( kb -> tbox -> subobjectproperty_of_axioms ) ) ; SubObjectPropertyOfAxiom * subrole_ax = ( SubObjectPropertyOfAxiom * ) SET_ITERATOR_NEXT ( & iterator ) ; while ( subrole_ax ) { ADD_TOLD_SUBSUMER_OBJECT_PROPERTY_EXPRESSION ( subrole_ax -> rhs , subrole_ax -> lhs ) ; index_role ( subrole_ax -> lhs ) ; subrole_ax = ( SubObjectPropertyOfAxiom * ) SET_ITERATOR_NEXT ( & iterator ) ; } for ( i = 0 ; i < kb -> generated_subrole_axiom_count ; ++ i ) { ADD_TOLD_SUBSUMER_OBJECT_PROPERTY_EXPRESSION ( kb -> generated_subrole_axioms [ i ] -> rhs , kb -> generated_subrole_axioms [ i ] -> lhs ) ; index_role ( kb -> generated_subrole_axioms [ i ] -> lhs ) ; } return 0 ; }
Index a given ontology: Collect information about told subsumer, negative occurrence of exists restrictions,
 and conjuncts of the conjunctions.
Index a given ontology : Collect information about told subsumer negative occurrence of exists restrictions and conjuncts of the conjunctions .
// Check if bottom appears on the rhs. Needed for determining inconsistency already during indexing. // if the top concept or a nominal is subsumed by bottom, the ontology is inconsistent // return inconsistent immediately // no need to add told subsumers of bottom // no need to index the bottom concept // no need to add top as a told subsumer // still index the lhs, but do not add top to the subsumers of lhs // Now index the subclass axioms generated during preprocessing // Check if bottom appears on the rhs. Needed for consistency // if the top concept or a nominal is subsumed by bottom, the kb is inconsistent // return inconsistent immediately // no need to add told subsumers of bottom // no need to index the bottom concept // no need to add top as a told subsumer // still index the lhs, but do not add top to the lhs of rhs // If bottom does not appear on the rhs, the KB cannot be inconcsistent, i.e., it is consistent // Index subobjectpropertyof axioms // Index generated subrole axioms