Debian Codegraph @

Kernel/Relevance.cpp

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2005-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 <cmath>
21 #include <iostream>
22
23 #include "dlTBox.h"cxx . . $ `<file>/Kernel/dlTBox.h`/
24
25 void TBoxcxx . . $ TBox# :: setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3). ( BipolarPointercxx . . $ BipolarPointer# p )
26 {
27 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( isValid(p) );
28
29 if ( p == bpTOPcxx . . $ bpTOP. || p == bpBOTTOMcxx . . $ bpBOTTOM. )
30 return;
31
32 const DLVertexcxx . . $ DLVertex#& v = DLHeapcxx . . $ TBox#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).p];
33 bool pos = isPositivecxx . . $ isPositive(83c267b20bac841a).(p);
34
35 ++nRelevantBCallscxx . . $ TBox#nRelevantBCalls.;
36 collectLogicFeaturecxx . . $ TBox#collectLogicFeature(65382114aacc8d2c).(v,pos);
37
38 switch ( v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() )
39 {
40 case dtDataTypecxx . . $ dtDataType.: // types and values are not relevant
41 case dtDataValuecxx . . $ dtDataValue.:
42 case dtDataExprcxx . . $ dtDataExpr.:
43 case dtNNcxx . . $ dtNN.: // not appear in any expression => not relevant
44 break;
45
46 case dtPConceptcxx . . $ dtPConcept.: // negated primitive entries -- does nothing
47 case dtPSingletoncxx . . $ dtPSingleton.:
48 // if ( !pos )
49 // break;
50
51 // fall through
52 case dtNConceptcxx . . $ dtNConcept.: // named concepts
53 case dtNSingletoncxx . . $ dtNSingleton.:
54 setRelevantcxx . . $ TBox#setRelevant(3f0281ca3ae282d4).(const_cast<TConceptcxx . . $ TConcept#*>(static_cast<const TConceptcxx . . $ TConcept#*>(v.getConceptcxx . . $ DLVertex#getConcept(1867504d72698304).())));
55 break;
56
57 case dtForallcxx . . $ dtForall.:
58 case dtLEcxx . . $ dtLE.:
59 setRelevantcxx . . $ TBox#setRelevant(3d6e099a537f0595).(const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()));
60 setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3). (v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).());
61 break;
62
63 case dtProjcxx . . $ dtProj.: // no need to set (inverse) roles as it doesn't really matter
64 case dtChoosecxx . . $ dtChoose.:
65 setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3).(v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).());
66 break;
67
68 case dtIrrcxx . . $ dtIrr.:
69 setRelevantcxx . . $ TBox#setRelevant(3d6e099a537f0595).(const_cast<TRolecxx . . $ TRole#*>(v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()));
70 break;
71
72 case dtAndcxx . . $ dtAnd.:
73 for ( DLVertexcxx . . $ DLVertex#::const_iteratorcxx . . $ DLVertex#const_iterator# q = v.begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(); q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). v.endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q )
74 setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q);
75 break;
76
77 default:
78 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error setting relevant vertex of type " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8). () <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
79 fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!();
80 }
81 }
82
83 void TBoxcxx . . $ TBox# :: setRelevant1cxx . . $ TBox#setRelevant1(3f0281ca3ae282d4). ( TConceptcxx . . $ TConcept#* p )
84 {
85 ++nRelevantCCallscxx . . $ TBox#nRelevantCCalls.;
86 p->setRelevantcxx . . $ TConcept#setRelevant(9ce72ecab6fc8b2b).(relevancecxx . . $ TBox#relevance.);
87 collectLogicFeaturecxx . . $ TBox#collectLogicFeature(d1b1787efb22fc2d).(p);
88 setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3). (p->pBodycxx . . $ TConcept#pBody.);
89 }
90
91 void TBoxcxx . . $ TBox# :: setRelevant1cxx . . $ TBox#setRelevant1(3d6e099a537f0595). ( TRolecxx . . $ TRole#* p )
92 {
93 p->setRelevantcxx . . $ TRole#setRelevant(9ce72ecab6fc8b2b).(relevancecxx . . $ TBox#relevance.);
94 collectLogicFeaturecxx . . $ TBox#collectLogicFeature(318ce8d73e657f48).(p);
95
96 // Range and Domain are also relevant
97 setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3). ( p->getBPDomaincxx . . $ TRole#getBPDomain(455f465bc33b4cdf).() );
98 setRelevantcxx . . $ TBox#setRelevant(d4f767463ce0a6b3). ( p->getBPRangecxx . . $ TRole#getBPRange(455f465bc33b4cdf).() );
99
100 // all super-roles are also relevant
101 for ( auto& sup: p->ancestorscxx . . $ TRole#ancestors(5c1fd3e4e1fb59f2).() )
102 setRelevantcxx . . $ TBox#setRelevant(3d6e099a537f0595).(sup);
103 }
104
105 void TBoxcxx . . $ TBox# :: gatherRelevanceInfocxx . . $ TBox#gatherRelevanceInfo(49f6e7a06ebc5aa8). ( void )
106 {
107 nRelevantCCallscxx . . $ TBox#nRelevantCCalls. = 0;
108 nRelevantBCallscxx . . $ TBox#nRelevantBCalls. = 0;
109
110 // gather GCIs features
111 curFeaturecxx . . $ TBox#curFeature. = &GCIFeaturescxx . . $ TBox#GCIFeatures.;
112 markGCIsRelevantcxx . . $ TBox#markGCIsRelevant(49f6e7a06ebc5aa8).();
113 clearRelevanceInfocxx . . $ TBox#clearRelevanceInfo(49f6e7a06ebc5aa8).();
114 KBFeaturescxx . . $ TBox#KBFeatures. |=cxx . . $ LogicFeatures#`operator|=`(9c0e370cfff66a7a). GCIFeaturescxx . . $ TBox#GCIFeatures.;
115
116 // fills in nominal cloud relevance info
117 NCFeaturescxx . . $ TBox#NCFeatures. =cxx . . $ LogicFeatures#`operator=`(9c0e370cfff66a7a). GCIFeaturescxx . . $ TBox#GCIFeatures.;
118
119 // set up relevance info
120 for ( i_iteratorcxx . . $ TBox#i_iterator# pi = i_begincxx . . $ TBox#i_begin(78b5d4d1a9fb506d).(); pi !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). i_endcxx . . $ TBox#i_end(78b5d4d1a9fb506d).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).pi )
121 {
122 setConceptRelevantcxx . . $ TBox#setConceptRelevant(3f0281ca3ae282d4).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).pi);
123 NCFeaturescxx . . $ TBox#NCFeatures. |=cxx . . $ LogicFeatures#`operator|=`(9c0e370cfff66a7a). (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).pi)->posFeaturescxx . . $ TConcept#posFeatures.;
124 }
125
126 // correct NC inverse role information
127 if ( NCFeaturescxx . . $ TBox#NCFeatures..hasSomeAllcxx . . $ LogicFeatures#hasSomeAll(50ce9a9e25b4a850).() && !RelatedIcxx . . $ TBox#RelatedI..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() )
128 NCFeaturescxx . . $ TBox#NCFeatures..setInverseRolescxx . . $ LogicFeatures#setInverseRoles(49f6e7a06ebc5aa8).();
129
130 for ( c_iteratorcxx . . $ TBox#c_iterator# pc = c_begincxx . . $ TBox#c_begin(23ec1c5bda99ac5d).(); pc !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). c_endcxx . . $ TBox#c_end(23ec1c5bda99ac5d).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).pc )
131 setConceptRelevantcxx . . $ TBox#setConceptRelevant(3f0281ca3ae282d4).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).pc);
132 auto cSize = ( c_endcxx . . $ TBox#c_end(23ec1c5bda99ac5d).() -cxx . . $ __gnu_cxx/operator-(a40477c209547c13). c_begincxx . . $ TBox#c_begin(23ec1c5bda99ac5d).() ) + ( i_endcxx . . $ TBox#i_end(78b5d4d1a9fb506d).() -cxx . . $ __gnu_cxx/operator-(a40477c209547c13). i_begincxx . . $ TBox#i_begin(78b5d4d1a9fb506d).() );
133 size_tcxx . . $ size_t# bSize = DLHeapcxx . . $ TBox#DLHeap..sizecxx . . $ DLDag#size(fe4d2d262d4164a8).()-2;
134
135 curFeaturecxx . . $ TBox#curFeature. = nullptr;
136
137 float cRatio, bRatio = 0, logCSize = 1, logBSize = 1, sqCSize = 1, sqBSize = 1;
138 if ( cSize > 10 )
139 {
140 cRatio = ((float)nRelevantCCallscxx . . $ TBox#nRelevantCCalls.)/cSize;
141 sqCSize = sqrtf((float)cSize);
142 if ( cSize > 1 )
143 logCSize = logf((float)cSize);
144 }
145 if ( bSize > 20 )
146 {
147 bRatio = ((float)nRelevantBCallscxx . . $ TBox#nRelevantBCalls.)/bSize;
148 sqBSize = sqrtf((float)bSize);
149 if ( bSize > 1 )
150 logBSize = logf((float)bSize);
151 }
152
153 if (0) // relevance stat
154 {
155 if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) && cSize > 10 )
156 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "There were made " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). nRelevantCCallscxx . . $ TBox#nRelevantCCalls. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " relevance C calls for "
157 <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). cSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " concepts\nRC ratio=" <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). cRatio <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", ratio/logSize="
158 <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). cRatio/logCSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", ratio/sqSize=" <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). cRatio/sqCSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", ratio/size="
159 <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). cRatio/cSize<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n";
160 if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) && bSize > 20 )
161 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "There were made " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). nRelevantBCallscxx . . $ TBox#nRelevantBCalls. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " relevance B calls for "
162 <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). bSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " nodes\nRB ratio=" <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). bRatio <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", ratio/logSize="
163 <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). bRatio/logBSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", ratio/sqSize=" <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). bRatio/sqBSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", ratio/size="
164 <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). bRatio/bSize <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n";
165 }
166
167 // set up GALEN-like flag; based on r/n^{3/2}, add r/n^2<1
168 isLikeGALENcxx . . $ TBox#isLikeGALEN. = (bRatio > sqBSize*20) && (bRatio < bSize);
169
170 // switch off sorted reasoning iff top role appears
171 if ( KBFeaturescxx . . $ TBox#KBFeatures..hasTopRolecxx . . $ LogicFeatures#hasTopRole(50ce9a9e25b4a850).() )
172 useSortedReasoningcxx . . $ TBox#useSortedReasoning. = false;
173 }