static bool containsC ( DLTree* C, DLTree* D ) { switch ( C->Element().getToken() ) { case CNAME: return equalTrees ( C, D ); case AND: return containsC ( C->Left(), D ) || containsC ( C->Right(), D ); default: return false; } }
/// add DLTree to an axiom void TAxiom :: add ( DLTree* p ) { if ( InAx::isBot(p) ) // BOT or X == X return; // nothing to do // flatten the disjunctions on the fly if ( InAx::isOr(p) ) { add(clone(p->Left())); add(clone(p->Right())); deleteTree(p); return; } for ( const_iterator i = begin(), i_end = end(); i != i_end; ++i ) if ( equalTrees(p,*i) ) { deleteTree(p); return; } Disjuncts.push_back(p); }
/// add DLTree to an axiom void TAxiom :: add ( DLTree* p ) { if ( InAx::isBot(p) ) // BOT or X == X return; // nothing to do // flatten the disjunctions on the fly if ( InAx::isOr(p) ) { add(clone(p->Left())); add(clone(p->Right())); deleteTree(p); return; } for ( const auto& C: Disjuncts ) if ( equalTrees(p,C) ) { deleteTree(p); return; } Disjuncts.push_back(p); }
/// absorb into BOTTOM; @return true if absorption is performed bool TAxiom :: absorbIntoBottom ( void ) const { absorptionSet Pos, Neg; for ( const_iterator p = begin(), p_end = end(); p != p_end; ++p ) switch ( (*p)->Element().getToken() ) { case BOTTOM: // axiom in the form T [= T or ...; nothing to do Stat::SAbsBApply(); # ifdef RKG_DEBUG_ABSORPTION std::cout << " Absorb into BOTTOM"; # endif return true; case TOP: // skip it here break; case NOT: // something negated: put it into NEG Neg.push_back((*p)->Left()); break; default: // something positive: save in POS Pos.push_back(*p); break; } // now check whether there is a concept in both POS and NEG for ( const_iterator q = Neg.begin(), q_end = Neg.end(); q != q_end; ++q ) for ( const_iterator s = Pos.begin(), s_end = Pos.end(); s != s_end; ++s ) if ( equalTrees ( *q, *s ) ) { Stat::SAbsBApply(); # ifdef RKG_DEBUG_ABSORPTION std::cout << " Absorb into BOTTOM due to (not" << *q << ") and" << *s; # endif return true; } return false; }
/// absorb into BOTTOM; @return true if absorption is performed bool TAxiom :: absorbIntoBottom ( void ) const { absorptionSet Pos, Neg; for ( const auto& C: Disjuncts ) switch ( C->Element().getToken() ) { case BOTTOM: // axiom in the form T [= T or ...; nothing to do Stat::SAbsBApply(); # ifdef RKG_DEBUG_ABSORPTION std::cout << " Absorb into BOTTOM"; # endif return true; case TOP: // skip it here break; case NOT: // something negated: put it into NEG Neg.push_back(C->Left()); break; default: // something positive: save in POS Pos.push_back(C); break; } // now check whether there is a concept in both POS and NEG for ( const auto& neg: Neg ) for ( const auto& pos: Pos ) if ( equalTrees ( neg, pos ) ) { Stat::SAbsBApply(); # ifdef RKG_DEBUG_ABSORPTION std::cout << " Absorb into BOTTOM due to (not" << neg << ") and" << pos; # endif return true; } return false; }