Debian Codegraph @

Kernel/ExtendedDataRange.cpp

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