| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-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 | #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/ |
| 21 | |
| 22 | #ifdef RKG_USE_SORTED_REASONINGcxx . . $ `Kernel/globaldef.h:40:9`! |
| 23 | |
| 24 | #include "RoleMaster.h"cxx . . $ `<file>/Kernel/RoleMaster.h`/ |
| 25 | #include "dlDag.h"cxx . . $ `<file>/Kernel/dlDag.h`/ |
| 26 | #include "logging.h"cxx . . $ `<file>/Kernel/logging.h`/ |
| 27 | |
| 28 | /// merge label of given role and all its super-roles |
| 29 | void TRolecxx . . $ TRole# :: mergeSupersDomaincxx . . $ TRole#mergeSupersDomain(49f6e7a06ebc5aa8). ( void ) |
| 30 | { |
| 31 | for ( const auto& sup: ancestorscxx . . $ TRole#ancestors(5c1fd3e4e1fb59f2).() ) |
| 32 | domLabelcxx . . $ TRole#domLabel..mergecxx . . $ mergeableLabel#merge(e3a03ee78af03ab7).(sup->domLabelcxx . . $ TRole#domLabel.); |
| 33 | |
| 34 | // for reflexive role -- merge domain and range labels |
| 35 | if ( isReflexivecxx . . $ TRole#isReflexive(50ce9a9e25b4a850).() ) |
| 36 | domLabelcxx . . $ TRole#domLabel..mergecxx . . $ mergeableLabel#merge(e3a03ee78af03ab7).(getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).()); |
| 37 | |
| 38 | // for R1*R2*...*Rn [= R, merge dom(R) with dom(R1) and ran(R) with ran(Rn) |
| 39 | for ( stdcxx . . $ std/::vectorcxx . . $ std/vector#<TRoleVec>::iteratorcxx . . $ std/vector#iterator# q = subCompositionscxx . . $ TRole#subCompositions..begincxx . . $ std/vector#begin(33b10a496a38335b).(), q_end = subCompositionscxx . . $ TRole#subCompositions..endcxx . . $ std/vector#end(33b10a496a38335b).(); q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). q_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 40 | if ( !q->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 41 | { |
| 42 | domLabelcxx . . $ TRole#domLabel..mergecxx . . $ mergeableLabel#merge(e3a03ee78af03ab7).((*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).begincxx . . $ std/vector#begin(33b10a496a38335b).())->domLabelcxx . . $ TRole#domLabel.); |
| 43 | getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).().mergecxx . . $ mergeableLabel#merge(e3a03ee78af03ab7).(q->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).backcxx . . $ std/vector#back(feee51535944b307).()->getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /// merge sorts for a given role |
| 48 | void DLDagcxx . . $ DLDag# :: mergeSortscxx . . $ DLDag#mergeSorts(3d6e099a537f0595). ( TRolecxx . . $ TRole#* R ) |
| 49 | { |
| 50 | // associate role domain labels |
| 51 | R->mergeSupersDomaincxx . . $ TRole#mergeSupersDomain(49f6e7a06ebc5aa8).(); |
| 52 | mergecxx . . $ DLDag#merge(b399d136bc0b5cf7). ( R->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).(), R->getBPDomaincxx . . $ TRole#getBPDomain(455f465bc33b4cdf).() ); |
| 53 | // also associate functional nodes (if any) |
| 54 | for ( const auto& topf: R->topfuncscxx . . $ TRole#topfuncs(5c1fd3e4e1fb59f2).() ) |
| 55 | mergecxx . . $ DLDag#merge(b399d136bc0b5cf7). ( R->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).(), topf->getFunctionalcxx . . $ TRole#getFunctional(455f465bc33b4cdf).() ); |
| 56 | } |
| 57 | |
| 58 | /// merge sorts for a given vertex |
| 59 | void DLDagcxx . . $ DLDag# :: mergeSortscxx . . $ DLDag#mergeSorts(fc1f73a461d00dd2). ( DLVertexcxx . . $ DLVertex#& v ) |
| 60 | { |
| 61 | switch ( v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() ) |
| 62 | { |
| 63 | case dtLEcxx . . $ dtLE.: // set R&D for role |
| 64 | case dtForallcxx . . $ dtForall.: |
| 65 | v.mergecxx . . $ DLVertexSort#merge(e3a03ee78af03ab7).(const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).()); // domain(role)=cur |
| 66 | mergecxx . . $ DLDag#merge(b399d136bc0b5cf7). ( const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).(), v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).() ); |
| 67 | break; |
| 68 | case dtProjcxx . . $ dtProj.: // projection: equate R&D of R and ProjR, and D(R) with C |
| 69 | v.mergecxx . . $ DLVertexSort#merge(e3a03ee78af03ab7).(const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).()); |
| 70 | v.mergecxx . . $ DLVertexSort#merge(e3a03ee78af03ab7).(const_cast<TRolecxx . . $ TRole#*>(v.getProjRolecxx . . $ DLVertex#getProjRole(69f26110a94b259f).())->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).()); |
| 71 | mergecxx . . $ DLDag#merge(b399d136bc0b5cf7). ( const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).(), v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).() ); |
| 72 | const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).().mergecxx . . $ mergeableLabel#merge(e3a03ee78af03ab7).(const_cast<TRolecxx . . $ TRole#*>(v.getProjRolecxx . . $ DLVertex#getProjRole(69f26110a94b259f).())->getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).()); |
| 73 | break; |
| 74 | case dtIrrcxx . . $ dtIrr.: // equate R&D for role |
| 75 | v.mergecxx . . $ DLVertexSort#merge(e3a03ee78af03ab7).(const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).()); |
| 76 | v.mergecxx . . $ DLVertexSort#merge(e3a03ee78af03ab7).(const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).())->getRangeLabelcxx . . $ TRole#getRangeLabel(e1d2169d387f9f72).()); |
| 77 | break; |
| 78 | case dtAndcxx . . $ dtAnd.: |
| 79 | for ( DLVertexcxx . . $ DLVertex#::const_iteratorcxx . . $ DLVertex#const_iterator# q = v.begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(), q_end = v.endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); q <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). q_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 80 | mergecxx . . $ DLDag#merge(b399d136bc0b5cf7). ( v.getSortcxx . . $ DLVertexSort#getSort(e1d2169d387f9f72).(), *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q ); |
| 81 | break; |
| 82 | case dtNSingletoncxx . . $ dtNSingleton.: |
| 83 | case dtPSingletoncxx . . $ dtPSingleton.: |
| 84 | case dtPConceptcxx . . $ dtPConcept.: |
| 85 | case dtNConceptcxx . . $ dtNConcept.: // merge with description |
| 86 | case dtChoosecxx . . $ dtChoose.: |
| 87 | mergecxx . . $ DLDag#merge(b399d136bc0b5cf7). ( v.getSortcxx . . $ DLVertexSort#getSort(e1d2169d387f9f72).(), v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).() ); |
| 88 | break; |
| 89 | |
| 90 | case dtDataTypecxx . . $ dtDataType.: // nothing to do |
| 91 | case dtDataValuecxx . . $ dtDataValue.: |
| 92 | case dtDataExprcxx . . $ dtDataExpr.: |
| 93 | case dtNNcxx . . $ dtNN.: |
| 94 | break; |
| 95 | case dtTopcxx . . $ dtTop.: |
| 96 | default: |
| 97 | fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /// build the sort system for given TBox |
| 102 | void DLDagcxx . . $ DLDag# :: determineSortscxx . . $ DLDag#determineSorts(553262e3595539a7). ( RoleMastercxx . . $ RoleMaster#& ORM, RoleMastercxx . . $ RoleMaster#& DRM ) |
| 103 | { |
| 104 | sortArraySizecxx . . $ DLDag#sortArraySize. = Heapcxx . . $ DLDag#Heap..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 105 | |
| 106 | RoleMastercxx . . $ RoleMaster#::iteratorcxx . . $ RoleMaster#iterator# pcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(49f6e7a06ebc5aa8)., p_endcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(49f6e7a06ebc5aa8).; |
| 107 | HeapTypecxx . . $ DLDag#HeapType#::iteratorcxx . . $ std/vector#iterator# icxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(49f6e7a06ebc5aa8)., i_end = Heapcxx . . $ DLDag#Heap..endcxx . . $ std/vector#end(33b10a496a38335b).(); |
| 108 | |
| 109 | // init roles R&D sorts |
| 110 | for ( p =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). ORM.begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99).(), p_end =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). ORM.endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 111 | if ( !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() ) |
| 112 | mergeSortscxx . . $ DLDag#mergeSorts(3d6e099a537f0595).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p); |
| 113 | for ( p =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). DRM.begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99).(), p_end =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). DRM.endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 114 | if ( !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() ) |
| 115 | mergeSortscxx . . $ DLDag#mergeSorts(3d6e099a537f0595).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p); |
| 116 | |
| 117 | for ( i =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(1547a748127585e7). Heapcxx . . $ DLDag#Heap..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).2; i <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). i_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).i ) |
| 118 | mergeSortscxx . . $ DLDag#mergeSorts(fc1f73a461d00dd2).(**cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i); |
| 119 | |
| 120 | unsigned int sum = 0; |
| 121 | for ( i =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(1547a748127585e7). Heapcxx . . $ DLDag#Heap..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).2; i <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). i_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).i ) |
| 122 | { |
| 123 | mergeableLabelcxx . . $ mergeableLabel#& lab = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i)->getSortcxx . . $ DLVertexSort#getSort(e1d2169d387f9f72).(); |
| 124 | lab.resolvecxx . . $ mergeableLabel#resolve(c3ec66b4ea6a8ad9).(); |
| 125 | if ( lab.isSamplecxx . . $ mergeableLabel#isSample(50ce9a9e25b4a850).() ) |
| 126 | ++sum; |
| 127 | } |
| 128 | |
| 129 | for ( p =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). ORM.begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99).(), p_end =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). ORM.endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 130 | if ( !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() ) |
| 131 | { |
| 132 | mergeableLabelcxx . . $ mergeableLabel#& lab = const_cast<TRolecxx . . $ TRole#*>(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).(); |
| 133 | lab.resolvecxx . . $ mergeableLabel#resolve(c3ec66b4ea6a8ad9).(); |
| 134 | if ( lab.isSamplecxx . . $ mergeableLabel#isSample(50ce9a9e25b4a850).() ) |
| 135 | ++sum; |
| 136 | } |
| 137 | for ( p =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). DRM.begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99).(), p_end =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(632e63ee1b1acbca). DRM.endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 138 | if ( !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() ) |
| 139 | { |
| 140 | mergeableLabelcxx . . $ mergeableLabel#& lab = const_cast<TRolecxx . . $ TRole#*>(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getDomainLabelcxx . . $ TRole#getDomainLabel(e1d2169d387f9f72).(); |
| 141 | lab.resolvecxx . . $ mergeableLabel#resolve(c3ec66b4ea6a8ad9).(); |
| 142 | if ( lab.isSamplecxx . . $ mergeableLabel#isSample(50ce9a9e25b4a850).() ) |
| 143 | ++sum; |
| 144 | } |
| 145 | |
| 146 | CHECK_LL_RETURNcxx . . $ `Kernel/LeveLogger.h:60:9`!(llAlways); |
| 147 | // we added a temp concept here; don't count it |
| 148 | if ( sum > 0 ) |
| 149 | sum--; |
| 150 | |
| 151 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nThere are "; |
| 152 | if ( sum > 1 ) |
| 153 | LLcxx . . $ LL. <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). sum; |
| 154 | else |
| 155 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "no"; |
| 156 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " different sorts in TBox\n"; |
| 157 | } |
| 158 | |
| 159 | #endif // RKG_USE_SORTED_REASONING |