Exemple #1
0
void TBox :: addConceptToHeap ( TConcept* pConcept )
{
	// choose proper tag by concept
	DagTag tag = pConcept->isPrimitive() ?
		(pConcept->isSingleton() ? dtPSingleton : dtPConcept):
		(pConcept->isSingleton() ? dtNSingleton : dtNConcept);

	// NSingleton is a nominal
	if ( tag == dtNSingleton && !pConcept->isSynonym() )
		static_cast<TIndividual*>(pConcept)->setNominal();

	// new concept's addition
	DLVertex* ver = new DLVertex(tag);
	ver->setConcept(pConcept);
	pConcept->pName = DLHeap.directAdd(ver);

	BipolarPointer desc = bpTOP;

	// translate body of a concept
	if ( pConcept->Description != NULL )	// complex concept
		desc = tree2dag(pConcept->Description);
	else			// only primivive concepts here
		fpp_assert ( pConcept->isPrimitive() );

	// update concept's entry
	pConcept->pBody = desc;
	ver->setChild(desc);
	if ( !pConcept->isSynonym() && pConcept->index() == 0 )
		setConceptIndex(pConcept);
}
Exemple #2
0
/// fills AND-like vertex V with an AND-like expression T; process result
BipolarPointer
TBox :: and2dag ( const DLTree* t )
{
	BipolarPointer ret = bpBOTTOM;
	DLVertex* v = new DLVertex(dtAnd);

	if ( fillANDVertex ( v, t ) )	// clash found
		delete v;
	else	// AND vertex
		switch ( v->end() - v->begin() )
		{
		case 0:	// and(TOP) = TOP
			delete v;
			return bpTOP;
		case 1:	// and(C) = C
			ret = *v->begin();
			delete v;
			break;
		default:
			ret = DLHeap.add(v);
			break;
		}

	return ret;
}
Exemple #3
0
/// @return true if the DAG in the SL structure is the same that is loaded
static bool
VerifyDag ( const DLDag& dag, SaveLoadManager& m )
{
	unsigned int j, size;
	size = m.loadUInt();

	if ( size != dag.size() )
	{
		std::cout << "DAG verification fail: size " << size << ", expected " << dag.size() << "\n";
		return false;
	}

	for ( j = 2; j < size; ++j )
	{
		DagTag tag = static_cast<DagTag>(m.loadUInt());
		DLVertex* v = new DLVertex(tag);
		v->Load(m);
		if ( *v != dag[j] )
		{
			std::cout << "DAG verification fail: dag entry at " << j << " is ";
			v->Print(std::cout);
			std::cout << ", expected ";
			dag[j].Print(std::cout);
			std::cout << "\n";
			delete v;
			return false;
		}
		delete v;
	}

	return true;
}
void LogicFeatures :: fillDAGData ( const DLVertex& v, bool )
{
	switch ( v.Type () )
	{
	case dtForall:
		setX(lfSomeConstructor);
		break;

	case dtLE:
		setX(lfNConstructor);
		if ( v.getC() != bpTOP )
			setX(lfQConstructor);

		break;

	case dtPSingleton:
	case dtNSingleton:
		setX(lfSingleton);
		break;

	case dtIrr:
		setX(lfSelfRef);
		break;

	default:	// any other vertex -- nothing to do
		break;
	}
}
Exemple #5
0
/// transform splitted concept registered in SPLIT to a dag representation
void
TBox :: split2dag ( TSplitVar* split )
{
	DLVertex* v = new DLVertex(dtSplitConcept);
	for ( TSplitVar::iterator p = split->begin(), p_end = split->end(); p != p_end; ++p )
		v->addChild(p->C->pName);
	split->C->pBody = DLHeap.directAdd(v);
	split->C->setPrimitive(false);
	DLHeap.replaceVertex ( split->C->pName, new DLVertex ( dtNConcept, split->C->pBody ), split->C );
	DLHeap.directAdd(new DLVertex ( dtChoose, split->C->pName ));
}
void
modelCacheIan :: processAutomaton ( const DLVertex& cur )
{
	const RAStateTransitions& RST = cur.getRole()->getAutomaton()[cur.getState()];

	// for every transition starting from a given state,
	// add the role that is accepted by a transition
	for ( RAStateTransitions::const_iterator i = RST.begin(), i_end = RST.end(); i < i_end; ++i )
		for ( RATransition::const_iterator r = (*i)->begin(), r_end = (*i)->end(); r < r_end; ++r )
			forallRoles.insert((*r)->index());
}
Exemple #7
0
void
LoadDLDag ( DLDag& dag, SaveLoadManager& m )
{
	unsigned int j, size;
	size = m.loadUInt();
	for ( j = 2; j < size; ++j )
	{
		DagTag tag = static_cast<DagTag>(m.loadUInt());
		DLVertex* v = new DLVertex(tag);
		v->Load(m);
		dag.directAdd(v);
	}

	// only reasoning now -- no cache
	dag.setFinalSize();
}
Exemple #8
0
/// register data expression in the DAG
BipolarPointer TBox :: addDataExprToHeap ( TDataEntry* p )
{
	if ( isValid(p->getBP()) )	// already registered value
		return p->getBP();

	// determine the type of an entry
	DagTag dt = p->isBasicDataType() ? dtDataType : p->isDataValue() ? dtDataValue : dtDataExpr;
	BipolarPointer hostBP = bpTOP;

	// register host type first (if any)
	if ( p->getType() != NULL )
		hostBP = addDataExprToHeap(const_cast<TDataEntry*>(p->getType()));

	// create new DAG entry for the data value
	DLVertex* ver = new DLVertex ( dt, hostBP );
	ver->setConcept(p);
	p->setBP(DLHeap.directAdd(ver));

	return p->getBP();
}
Exemple #9
0
void
DLDag :: removeQuery ( void )
{
	for ( size_t i = size()-1; i >= finalDagSize; --i )
	{
		DLVertex* v = Heap[i];
		switch ( v->Type() )
		{
		case dtData:
			static_cast<TDataEntry*>(v->getConcept())->setBP(bpINVALID);
			break;
		case dtConcept:
			static_cast<TConcept*>(v->getConcept())->clear();
			break;
		default:
			break;
		}
		delete v;
	}
	Heap.resize(finalDagSize);
}
Exemple #10
0
void modelCacheIan :: processConcept ( const DLVertex& cur, bool pos, bool det )
{
		switch ( cur.Type() )
		{
		case dtTop:			// sanity checks
		case dtDataType:	// data entries can not be cached
		case dtDataValue:
		case dtDataExpr:
			fpp_unreachable();
			break;

		case dtNConcept:	// add concepts to Concepts
		case dtPConcept:
		case dtNSingleton:
		case dtPSingleton:
			(det ? getDConcepts(pos) : getNConcepts(pos)).insert(static_cast<const ClassifiableEntry*>(cur.getConcept())->index());
			break;

		case dtIrr:		// for \neg \ER.Self: add R to AR-set
		case dtForall:	// add AR.C roles to forallRoles
		case dtLE:		// for <= n R: add R to forallRoles
			if ( unlikely ( cur.getRole()->isTop() ) )	// force clash to every other edge
				(pos ? forallRoles : existsRoles).completeSet();
			else if ( pos )	// no need to deal with existentials here: they would be created through edges
			{
				if ( cur.getRole()->isSimple() )
					forallRoles.insert(cur.getRole()->index());
				else
					processAutomaton(cur);
			}
			break;

		default:	// all other -- nothing to do
			break;
		}
}