| 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"cxx . . $ `<file>/Kernel/Kernel.h`/ |
| 23 | #include "dlCompletionTree.h"cxx . . $ `<file>/Kernel/dlCompletionTree.h`/ |
| 24 | #include "DataReasoning.h"cxx . . $ `<file>/Kernel/DataReasoning.h`/ |
| 25 | |
| 26 | static bool |
| 27 | checkDataRelationcxx . . $ checkDataRelation(e6093bdaf4d27692). ( const DataTypeReasonercxx . . $ DataTypeReasoner#& Op1, const DataTypeReasonercxx . . $ DataTypeReasoner#& Op2, int op ) |
| 28 | { |
| 29 | switch (op) |
| 30 | { |
| 31 | case 0: // = |
| 32 | return Op1 ==cxx . . $ DataTypeReasoner#`operator==`(ea11ccc8d5f8e779). Op2; |
| 33 | case 1: // != |
| 34 | return !(Op1 ==cxx . . $ DataTypeReasoner#`operator==`(ea11ccc8d5f8e779). Op2); |
| 35 | case 2: // < |
| 36 | return Op1 <cxx . . $ DataTypeReasoner#`operator<`(ea11ccc8d5f8e779). Op2; |
| 37 | case 3: // <= |
| 38 | return Op1 <cxx . . $ DataTypeReasoner#`operator<`(ea11ccc8d5f8e779). Op2 || Op1 ==cxx . . $ DataTypeReasoner#`operator==`(ea11ccc8d5f8e779). Op2; |
| 39 | case 4: // > |
| 40 | return Op2 <cxx . . $ DataTypeReasoner#`operator<`(ea11ccc8d5f8e779). Op1; |
| 41 | case 5: // >= |
| 42 | return Op2 <cxx . . $ DataTypeReasoner#`operator<`(ea11ccc8d5f8e779). Op1 || Op2 ==cxx . . $ DataTypeReasoner#`operator==`(ea11ccc8d5f8e779). Op1; |
| 43 | default: |
| 44 | throw EFaCTPlusPluscxx . . $ EFaCTPlusPlus#("Illegal operation in checkDataRelation()"); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | static bool |
| 49 | fillDTReasonercxx . . $ fillDTReasoner(4e4fcdc334cfb477). ( DataTypeReasonercxx . . $ DataTypeReasoner#& DTR, const DlCompletionTreecxx . . $ DlCompletionTree#* node ) |
| 50 | { |
| 51 | DTR.clearcxx . . $ DataTypeReasoner#clear(49f6e7a06ebc5aa8).(); |
| 52 | // data node may contain only "simple" concepts in there |
| 53 | for ( DlCompletionTreecxx . . $ DlCompletionTree#::const_label_iteratorcxx . . $ DlCompletionTree#const_label_iterator# p = node->beginl_sccxx . . $ DlCompletionTree#beginl_sc(e55d760a93e9f197).(), p_end = node->endl_sccxx . . $ DlCompletionTree#endl_sc(e55d760a93e9f197).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 54 | if ( DTR.addDataEntrycxx . . $ DataTypeReasoner#addDataEntry(cbd92d0fb85c8e0). ( p->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).(), p->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).getDepcxx . . $ ConceptWDep#getDep(bce6462a16d96b29).() ) ) // 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 | ReasoningKernelcxx . . $ ReasoningKernel# :: getDataRelatedIndividualscxx . . $ ReasoningKernel#getDataRelatedIndividuals(919cd40eaba59545). ( TDRoleExprcxx . . $ ReasoningKernel#TDRoleExpr#* R, TDRoleExprcxx . . $ ReasoningKernel#TDRoleExpr#* S, int op, IndividualSetcxx . . $ ReasoningKernel#IndividualSet#& Result ) |
| 62 | { |
| 63 | preprocessKBcxx . . $ ReasoningKernel#preprocessKB(49f6e7a06ebc5aa8).(); // ensure KB is ready to answer the query |
| 64 | Result.clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 65 | const TRolecxx . . $ TRole#* r = getRolecxx . . $ ReasoningKernel#getRole(ed2e21ac85945398). ( R, "Role expression expected in the getDataRelatedIndividuals()" ); |
| 66 | const TRolecxx . . $ TRole#* s = getRolecxx . . $ ReasoningKernel#getRole(ed2e21ac85945398). ( S, "Role expression expected in the getDataRelatedIndividuals()" ); |
| 67 | |
| 68 | // prepare DT reasoners |
| 69 | const DLDagcxx . . $ DLDag#& dag = getTBoxcxx . . $ ReasoningKernel#getTBox(e1a36bcbc166a7c5).()->getDagcxx . . $ TBox#getDag(9e19445b34a9809a).(); |
| 70 | const DataTypeCentercxx . . $ DataTypeCenter#& dtc = getTBoxcxx . . $ ReasoningKernel#getTBox(e1a36bcbc166a7c5).()->getDataTypeCentercxx . . $ TBox#getDataTypeCenter(dd641241804ece05).(); |
| 71 | |
| 72 | DataTypeReasonercxx . . $ DataTypeReasoner# Op1cxx . . $ DataTypeReasoner#DataTypeReasoner(dd585ec903520274).(dag); |
| 73 | DataTypeReasonercxx . . $ DataTypeReasoner# Op2cxx . . $ DataTypeReasoner#DataTypeReasoner(dd585ec903520274).(dag); |
| 74 | dtc.initDataTypeReasonercxx . . $ DataTypeCenter#initDataTypeReasoner(2eaf9760777a0523).(Op1); |
| 75 | dtc.initDataTypeReasonercxx . . $ DataTypeCenter#initDataTypeReasoner(2eaf9760777a0523).(Op2); |
| 76 | |
| 77 | // vector of individuals |
| 78 | typedef TDLNAryExpressioncxx . . $ TDLNAryExpression#<TDLIndividualExpressioncxx . . $ TDLIndividualExpression#> IndVeccxx . . $ ReasoningKernel#getDataRelatedIndividuals(919cd40eaba59545).IndVec#; |
| 79 | IndVeccxx . . $ ReasoningKernel#getDataRelatedIndividuals(919cd40eaba59545).IndVec# Individualscxx . . $ TDLNAryExpression#TDLNAryExpression(2fa786934fe80e24). ("individual expression","data related individuals"); |
| 80 | Individuals.addcxx . . $ TDLNAryExpression#add(d9b6f75bcac4e62b).(getExpressionManagercxx . . $ ReasoningKernel#getExpressionManager(867f96a8caac8aab).()->getArgListcxx . . $ TExpressionManager#getArgList(ea12e55bef799de0).()); |
| 81 | for ( const TIndividualExprcxx . . $ ReasoningKernel#TIndividualExpr#* individual : Individuals ) |
| 82 | { |
| 83 | const TIndividualcxx . . $ TIndividual#* ind = getIndividualcxx . . $ ReasoningKernel#getIndividual(d410642517b2f838). ( individual, "individual name expected in getDataRelatedIndividuals()" ); |
| 84 | const DlCompletionTreecxx . . $ DlCompletionTree#* vR = nullptr; |
| 85 | const DlCompletionTreecxx . . $ DlCompletionTree#* vS = nullptr; |
| 86 | for ( DlCompletionTreecxx . . $ DlCompletionTree#::const_edge_iteratorcxx . . $ DlCompletionTree#const_edge_iterator# p = indcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).->nodecxx . . $ TIndividual#node.->begincxx . . $ DlCompletionTree#begin(de7d1c517ae77062).(), p_end = indcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).->nodecxx . . $ TIndividual#node.->endcxx . . $ DlCompletionTree#end(de7d1c517ae77062).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 87 | { |
| 88 | const DlCompletionTreeArccxx . . $ DlCompletionTreeArc#* edge = *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p; |
| 89 | if ( edge->isNeighbourcxx . . $ DlCompletionTreeArc#isNeighbour(81d69a9c8508a392).(r) ) |
| 90 | vR = edge->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).(); |
| 91 | else if ( edge->isNeighbourcxx . . $ DlCompletionTreeArc#isNeighbour(81d69a9c8508a392).(s) ) |
| 92 | vS = edge->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).(); |
| 93 | if ( vR && vS ) |
| 94 | { |
| 95 | if ( fillDTReasonercxx . . $ fillDTReasoner(4e4fcdc334cfb477). ( Op1, vR ) ) |
| 96 | break; |
| 97 | if ( fillDTReasonercxx . . $ fillDTReasoner(4e4fcdc334cfb477). ( Op2, vS ) ) |
| 98 | break; |
| 99 | if ( checkDataRelationcxx . . $ checkDataRelation(e6093bdaf4d27692). ( Op1, Op2, op ) ) |
| 100 | Result.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(ind); |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 |