1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2013-2015 Dmitry Tsarkov and The University of Manchester
Copyright (C) 2015-2016 Dmitry Tsarkov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// extended data range support
#include "Kernel.h"
#include "dlCompletionTree.h"
#include "DataReasoning.h"
static bool
checkDataRelation ( const DataTypeReasoner& Op1, const DataTypeReasoner& Op2, int op )
{
switch (op)
{
case 0: // =
return Op1 == Op2;
case 1: // !=
return !(Op1 == Op2);
case 2: // <
return Op1 < Op2;
case 3: // <=
return Op1 < Op2 || Op1 == Op2;
case 4: // >
return Op2 < Op1;
case 5: // >=
return Op2 < Op1 || Op2 == Op1;
default:
throw new EFaCTPlusPlus("Illegal operation in checkDataRelation()");
}
return false;
}
static bool
fillDTReasoner ( DataTypeReasoner& DTR, const DlCompletionTree* node )
{
DTR.clear();
// data node may contain only "simple" concepts in there
for ( DlCompletionTree::const_label_iterator p = node->beginl_sc(), p_end = node->endl_sc(); p != p_end; ++p )
if ( DTR.addDataEntry ( p->bp(), p->getDep() ) ) // clash found
return true;
return false;
}
/// set RESULT into set of instances of A such that they do have data roles R and S
void
ReasoningKernel :: getDataRelatedIndividuals ( TDRoleExpr* R, TDRoleExpr* S, int op, IndividualSet& Result )
{
preprocessKB(); // ensure KB is ready to answer the query
Result.clear();
const TRole* r = getRole ( R, "Role expression expected in the getDataRelatedIndividuals()" );
const TRole* s = getRole ( S, "Role expression expected in the getDataRelatedIndividuals()" );
// prepare DT reasoners
const DLDag& dag = getTBox()->getDag();
const DataTypeCenter& dtc = getTBox()->getDataTypeCenter();
DataTypeReasoner Op1(dag);
DataTypeReasoner Op2(dag);
dtc.initDataTypeReasoner(Op1);
dtc.initDataTypeReasoner(Op2);
// vector of individuals
typedef TDLNAryExpression<TDLIndividualExpression> IndVec;
IndVec Individuals ("individual expression","data related individuals");
Individuals.add(getExpressionManager()->getArgList());
for ( IndVec::iterator q = Individuals.begin(), q_end = Individuals.end(); q != q_end; ++q )
{
const TIndividual* ind = getIndividual ( *q, "individual name expected in getDataRelatedIndividuals()" );
const DlCompletionTree* vR = NULL;
const DlCompletionTree* vS = NULL;
for ( DlCompletionTree::const_edge_iterator p = ind->node->begin(), p_end = ind->node->end(); p != p_end; ++p )
{
const DlCompletionTreeArc* edge = *p;
if ( edge->isNeighbour(r) )
vR = edge->getArcEnd();
else if ( edge->isNeighbour(s) )
vS = edge->getArcEnd();
if ( vR && vS )
{
if ( fillDTReasoner ( Op1, vR ) )
break;
if ( fillDTReasoner ( Op2, vS ) )
break;
if ( checkDataRelation ( Op1, Op2, op ) )
Result.push_back(ind);
break;
}
}
}
}
|