Debian Codegraph @

Kernel/tRole.cpp

raw symbols SCIP
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 <set>
21 #include <fstream>
22 #include <algorithm>
23
24 #include "tRole.h"cxx . . $ `<file>/Kernel/tRole.h`/
25 #include "Taxonomy.h"cxx . . $ `<file>/Kernel/Taxonomy.h`/
26
27 void TRolecxx . . $ TRole# :: fillsCompositioncxx . . $ TRole#fillsComposition(5530ca12088eea1). ( TRoleVeccxx . . $ TRole#TRoleVec#& Composition, const DLTreecxx . . $ DLTree#* tree ) const
28 {
29 if ( tree->Elementcxx . . $ TsTTree#Element(ea465e50d690edfe).() ==cxx . . $ TLexeme#`operator==`(b418e6031985303a). RCOMPOSITIONcxx . . $ RCOMPOSITION. )
30 {
31 fillsCompositioncxx . . $ TRole#fillsComposition(5530ca12088eea1). ( Composition, tree->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).() );
32 fillsCompositioncxx . . $ TRole#fillsComposition(5530ca12088eea1). ( Composition, tree->Rightcxx . . $ TsTTree#Right(f4b2f47551fb31d7).() );
33 }
34 else
35 Composition.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(resolveRolecxx . . $ resolveRole(c256d257f6e22050).(tree));
36 }
37
38 /// copy role information (like transitivity, functionality, R&D etc) to synonym
39 void TRolecxx . . $ TRole# :: addFeaturesToSynonymcxx . . $ TRole#addFeaturesToSynonym(49f6e7a06ebc5aa8). ( void )
40 {
41 if ( !isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() )
42 return;
43
44 TRolecxx . . $ TRole#* syn = resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(this);
45
46 // don't copy parents: they are already copied during ToldSubsumers processing
47
48 // copy functionality
49 if ( isFunctionalcxx . . $ TRole#isFunctional(50ce9a9e25b4a850).() && !syn->isFunctionalcxx . . $ TRole#isFunctional(50ce9a9e25b4a850).() )
50 syn->setFunctionalcxx . . $ TRole#setFunctional(49f6e7a06ebc5aa8).();
51
52 // copy transitivity
53 if ( isTransitivecxx . . $ TRole#isTransitive(50ce9a9e25b4a850).() )
54 syn->setTransitivecxx . . $ TRole#setTransitive(b45ddcbc8423892c). ();
55
56 // copy reflexivity
57 if ( isReflexivecxx . . $ TRole#isReflexive(50ce9a9e25b4a850).() )
58 syn->setReflexivecxx . . $ TRole#setReflexive(b45ddcbc8423892c).();
59
60 // copy data type
61 if ( isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() )
62 syn->setDataRolecxx . . $ TRole#setDataRole(49f6e7a06ebc5aa8).();
63
64 // copy R&D
65 if ( pDomaincxx . . $ TRole#pDomain. != nullptr )
66 syn->setDomaincxx . . $ TRole#setDomain(edf821a2fc5509f9). (clonecxx . . $ clone(ec41a33c52a5614b).(pDomaincxx . . $ TRole#pDomain.));
67
68 // copy disjoint
69 if ( isDisjointcxx . . $ TRole#isDisjoint(50ce9a9e25b4a850).() )
70 syn->Disjointcxx . . $ TRole#Disjoint..insertcxx . . $ std/set#insert(50ef72ff69bc573d). ( Disjointcxx . . $ TRole#Disjoint..begincxx . . $ std/set#begin(a1617ab40ea76896).(), Disjointcxx . . $ TRole#Disjoint..endcxx . . $ std/set#end(a1617ab40ea76896).() );
71
72 // copy subCompositions
73 syn->subCompositionscxx . . $ TRole#subCompositions..insertcxx . . $ std/vector#insert(134ef7853f0b3ebe). ( syncxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).->subCompositionscxx . . $ TRole#subCompositions..endcxx . . $ std/vector#end(33b10a496a38335b).(),
74 subCompositionscxx . . $ TRole#subCompositions..begincxx . . $ std/vector#begin(33b10a496a38335b).(),
75 subCompositionscxx . . $ TRole#subCompositions..endcxx . . $ std/vector#end(33b10a496a38335b).() );
76
77 // syn should be the only parent for synonym
78 toldSubsumerscxx . . $ ClassifiableEntry#toldSubsumers..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
79 addParentcxx . . $ ClassifiableEntry#addParent(866fbb357e35bef0).(syn);
80 }
81
82 // compare 2 TRoles wrt order of synonyms
83 class TRoleComparecxx . . $ TRoleCompare#
84 {
85 public:
86 bool operatorcxx . . $ TRoleCompare#`operator()`(82e67a946546ed2).() ( TRolecxx . . $ TRole#* p, TRolecxx . . $ TRole#* q ) const
87 {
88 int n = p->getIdcxx . . $ TNamedEntry#getId(455f465bc33b4cdf).(), m = q->getIdcxx . . $ TNamedEntry#getId(455f465bc33b4cdf).();
89 if ( n > 0 && m < 0 )
90 return true;
91 if ( n < 0 && m > 0 )
92 return false;
93 return abs(n) < abs(m);
94 }
95 }; // TRoleCompare
96
97 TRolecxx . . $ TRole#* TRolecxx . . $ TRole# :: eliminateToldCyclescxx . . $ TRole#eliminateToldCycles(da3b35d3ecb922e7). ( TRoleSetcxx . . $ TRole#TRoleSet#& RInProcess, TRoleVeccxx . . $ TRole#TRoleVec#& ToldSynonyms )
98 {
99 // skip synonyms
100 if ( isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() )
101 return nullptr;
102
103 // if we found a cycle...
104 if ( RInProcess.findcxx . . $ std/set#find(f8922f46a681e6cc).(this) !=cxx . . $ std/`operator!=`(7e1308a0738ea758). RInProcess.endcxx . . $ std/set#end(a1617ab40ea76896).() )
105 {
106 ToldSynonyms.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(this);
107 return this;
108 }
109
110 TRolecxx . . $ TRole#* ret = nullptr;
111
112 // start processing role
113 RInProcess.insertcxx . . $ std/set#insert(10916b2dbd511ba8).(this);
114
115 // ensure that parents does not contain synonyms
116 removeSynonymsFromParentscxx . . $ ClassifiableEntry#removeSynonymsFromParents(49f6e7a06ebc5aa8).();
117
118 // not involved in cycle -- check all told subsumers
119 for ( auto r: toldcxx . . $ ClassifiableEntry#told(e7230ad44187fae2).() )
120 // if cycle was detected
121 if ( (ret = static_cast<TRolecxx . . $ TRole#*>(r)->eliminateToldCyclescxx . . $ TRole#eliminateToldCycles(da3b35d3ecb922e7). ( RInProcess, ToldSynonyms )) != nullptr )
122 {
123 if ( ret == this )
124 {
125 std::sortcxx . . $ std/sort(4d3091562df4e52e). ( ToldSynonyms.begincxx . . $ std/vector#begin(33b10a496a38335b).(), ToldSynonyms.endcxx . . $ std/vector#end(33b10a496a38335b).(), TRoleComparecxx . . $ TRoleCompare#() );
126 // now first element is representative; save it as RET
127 ret = *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).ToldSynonyms.begincxx . . $ std/vector#begin(33b10a496a38335b).();
128
129 // make all others synonyms of RET
130 for ( std::vectorcxx . . $ std/vector#<TRole*>::iteratorcxx . . $ std/vector#iterator#
131 p = ToldSynonyms.begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).1, p_end = ToldSynonyms.endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
132 {
133 (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->setSynonymcxx . . $ ClassifiableEntry#setSynonym(866fbb357e35bef0).(ret);
134 ret->addParentscxx . . $ ClassifiableEntry#addParents(77d9f17553126ecb).((*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->toldcxx . . $ ClassifiableEntry#told(e7230ad44187fae2).());
135 }
136
137 ToldSynonyms.clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
138 // restart search for the representative
139 RInProcess.erasecxx . . $ std/set#erase(3a53bfe100edb289).(this);
140 return ret->eliminateToldCyclescxx . . $ TRole#eliminateToldCycles(da3b35d3ecb922e7). ( RInProcess, ToldSynonyms );
141 }
142 else // some role inside a cycle: save it and return
143 {
144 ToldSynonyms.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(this);
145 break;
146 }
147 }
148
149 // finish processing role
150 RInProcess.erasecxx . . $ std/set#erase(3a53bfe100edb289).(this);
151 return ret;
152 }
153
154 void TRolecxx . . $ TRole# :: Printcxx . . $ TRole#Print(490063bd7e6d8d5d). ( std::ostreamcxx . . $ std/ostream#& o ) const
155 {
156 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Role \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\"(" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getIdcxx . . $ TNamedEntry#getId(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
157
158 //FIXME!! while it's not necessary
159 // o << " [" << r.nUsageFreq << "]";
160
161 // transitivity
162 if ( isTransitivecxx . . $ TRole#isTransitive(50ce9a9e25b4a850).() )
163 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "T";
164
165 // reflexivity
166 if ( isReflexivecxx . . $ TRole#isReflexive(50ce9a9e25b4a850).() )
167 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "R";
168
169 // functionality
170 if ( isTopFunccxx . . $ TRole#isTopFunc(50ce9a9e25b4a850).() )
171 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "t";
172 if ( isFunctionalcxx . . $ TRole#isFunctional(50ce9a9e25b4a850).() )
173 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "F";
174
175 // data role
176 if ( isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() )
177 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "D";
178
179 if ( isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() )
180 {
181 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " = \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getSynonymcxx . . $ ClassifiableEntry#getSynonym(106bdcbfaabaf9a3).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\"\n";
182 return;
183 }
184
185 if ( !toldSubsumerscxx . . $ ClassifiableEntry#toldSubsumers..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() )
186 {
187 ClassifiableEntrycxx . . $ ClassifiableEntry#::linkSetcxx . . $ ClassifiableEntry#linkSet#::const_iteratorcxx . . $ std/vector#const_iterator# q = toldSubsumerscxx . . $ ClassifiableEntry#toldSubsumers..begincxx . . $ std/vector#begin(359ca5030082c9f).();
188
189 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " parents={\"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q)->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
190
191 for ( ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q; q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). toldSubsumerscxx . . $ ClassifiableEntry#toldSubsumers..endcxx . . $ std/vector#end(359ca5030082c9f).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q )
192 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\", \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q)->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
193
194 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\"}";
195 }
196
197 if ( !Disjointcxx . . $ TRole#Disjoint..emptycxx . . $ std/set#empty(50ce9a9e25b4a850).() )
198 {
199 TRoleSetcxx . . $ TRole#TRoleSet#::const_iteratorcxx . . $ std/set#const_iterator# p = Disjointcxx . . $ TRole#Disjoint..begincxx . . $ std/set#begin(a1617ab40ea76896).(), p_end = Disjointcxx . . $ TRole#Disjoint..endcxx . . $ std/set#end(a1617ab40ea76896).();
200
201 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " disjoint with {\"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(ea465e50d690edfe).p)->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
202
203 for ( ++cxx . . $ std/_Rb_tree_const_iterator#operator++(998dce1072ed46d4).p; p !=cxx . . $ std/`operator!=`(7e1308a0738ea758). p_end; ++cxx . . $ std/_Rb_tree_const_iterator#operator++(998dce1072ed46d4).p )
204 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\", \"" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(ea465e50d690edfe).p)->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
205
206 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\"}";
207 }
208
209 // range/domain
210 if ( getTDomaincxx . . $ TRole#getTDomain(7ba0ba2d2b26f6a8).() != nullptr )
211 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " Domain=(" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getBPDomaincxx . . $ TRole#getBPDomain(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")=" <<cxx . . $ `operator<<`(607b78f3c31ebc02). getTDomaincxx . . $ TRole#getTDomain(7ba0ba2d2b26f6a8).();
212 if ( getTRangecxx . . $ TRole#getTRange(7ba0ba2d2b26f6a8).() != nullptr )
213 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " Range=(" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getBPRangecxx . . $ TRole#getBPRange(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")=" <<cxx . . $ `operator<<`(607b78f3c31ebc02). getTRangecxx . . $ TRole#getTRange(7ba0ba2d2b26f6a8).();
214
215 if ( !isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() )
216 {
217 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nAutomaton (size " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). Acxx . . $ TRole#A..sizecxx . . $ RoleAutomaton#size(fe4d2d262d4164a8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "): " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ( Acxx . . $ TRole#A..isISafecxx . . $ RoleAutomaton#isISafe(50ce9a9e25b4a850).() ? "I" : "i" ) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ( Acxx . . $ TRole#A..isOSafecxx . . $ RoleAutomaton#isOSafe(50ce9a9e25b4a850).() ? "O" : "o" );
218 Acxx . . $ TRole#A..Printcxx . . $ RoleAutomaton#Print(490063bd7e6d8d5d).(o);
219 }
220 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n";
221 }
222
223 // actor to fill vector by traversing taxonomy in a proper direction
224 class AddRoleActorcxx . . $ AddRoleActor#: public WalkerInterfacecxx . . $ WalkerInterface#
225 {
226 protected:
227 TRolecxx . . $ TRole#::TRoleVeccxx . . $ TRole#TRoleVec#& rsetcxx . . $ AddRoleActor#rset.;
228 public:
229 explicit AddRoleActorcxx . . $ AddRoleActor#AddRoleActor(9f78be017486fe7b). ( TRolecxx . . $ TRole#::TRoleVeccxx . . $ TRole#TRoleVec#& v ) : rsetcxx . . $ AddRoleActor#rset.(v) {}
230 bool applycxx . . $ AddRoleActor#apply(9e72d36cb75ed014). ( const TaxonomyVertexcxx . . $ TaxonomyVertex#& v ) override
231 {
232 if ( v.getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).()->getIdcxx . . $ TNamedEntry#getId(455f465bc33b4cdf).() == 0 )
233 return false;
234 rsetcxx . . $ AddRoleActor#rset..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(const_cast<TRolecxx . . $ TRole#*>(static_cast<const TRolecxx . . $ TRole#*>(v.getPrimercxx . . $ TaxonomyVertex#getPrimer(257357278432d96a).())));
235 return true;
236 }
237 }; // AddRoleActor
238
239 /// init ancestors and descendants using Taxonomy
240 void
241 TRolecxx . . $ TRole# :: initADbyTaxonomycxx . . $ TRole#initADbyTaxonomy(739d502f68d79167). ( Taxonomycxx . . $ Taxonomy#* pTax, size_t nRoles )
242 {
243 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( isClassified() ); // safety check
244 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( Ancestor.empty() && Descendant.empty() );
245
246 // Note that Top/Bottom are not connected to taxonomy yet.
247
248 // fills ancestors by the taxonomy
249 AddRoleActorcxx . . $ AddRoleActor# anccxx . . $ AddRoleActor#AddRoleActor(9f78be017486fe7b).(Ancestorcxx . . $ TRole#Ancestor.);
250 pTax->getRelativesInfocxx . . $ Taxonomy#getRelativesInfo(e811dd8058b26e1c).</*needCurrent=*/false, /*onlyDirect=*/false, /*upDirection=*/true> ( getTaxVertexcxx . . $ ClassifiableEntry#getTaxVertex(16f9ca5fa66f7d36).(), anc );
251 // fills descendants by the taxonomy
252 AddRoleActorcxx . . $ AddRoleActor# desccxx . . $ AddRoleActor#AddRoleActor(9f78be017486fe7b).(Descendantcxx . . $ TRole#Descendant.);
253 pTax->getRelativesInfocxx . . $ Taxonomy#getRelativesInfo(e811dd8058b26e1c).</*needCurrent=*/false, /*onlyDirect=*/false, /*upDirection=*/false> ( getTaxVertexcxx . . $ ClassifiableEntry#getTaxVertex(16f9ca5fa66f7d36).(), desc );
254
255 // resize maps for fast access
256 DJRolescxx . . $ TRole#DJRoles..resizecxx . . $ std/vector#resize(62a5225ebb2f873).(nRoles);
257 AncMapcxx . . $ TRole#AncMap..resizecxx . . $ std/vector#resize(62a5225ebb2f873).(nRoles);
258 // init map for fast Anc/Desc access
259 addAncestorsToBitMapcxx . . $ TRole#addAncestorsToBitMap(872a9bef1b2f4afb).(AncMapcxx . . $ TRole#AncMap.);
260 }
261
262 void TRolecxx . . $ TRole# :: postProcesscxx . . $ TRole#postProcess(49f6e7a06ebc5aa8). ( void )
263 {
264 // set Topmost-Functional field
265 initTopFunccxx . . $ TRole#initTopFunc(49f6e7a06ebc5aa8).();
266 // init DJ roles map
267 if ( isDisjointcxx . . $ TRole#isDisjoint(50ce9a9e25b4a850).() )
268 initDJMapcxx . . $ TRole#initDJMap(49f6e7a06ebc5aa8).();
269 }
270
271 /// check if the role is topmost-functional (internal-use only)
272 // not very efficient, but good enough
273 bool TRolecxx . . $ TRole# :: isRealTopFunccxx . . $ TRole#isRealTopFunc(50ce9a9e25b4a850). ( void ) const
274 {
275 if ( !isFunctionalcxx . . $ TRole#isFunctional(50ce9a9e25b4a850).() ) // all REAL top-funcs have their self-ref in TopFunc already
276 return false;
277 // if any of the parent is self-proclaimed top-func -- this one is not top-func
278 for ( const auto& sup: ancestorscxx . . $ TRole#ancestors(5c1fd3e4e1fb59f2).() )
279 if ( sup->isTopFunccxx . . $ TRole#isTopFunc(50ce9a9e25b4a850).() )
280 return false;
281
282 // functional role with no functional parents is top-most functional
283 return true;
284 }
285
286 /// set up TopFunc member (internal-use only)
287 // not very efficient, but good enough
288 void TRolecxx . . $ TRole# :: initTopFunccxx . . $ TRole#initTopFunc(49f6e7a06ebc5aa8). ( void )
289 {
290 if ( isRealTopFunccxx . . $ TRole#isRealTopFunc(50ce9a9e25b4a850).() ) // TF already set up -- nothing to do
291 return;
292
293 if ( isTopFunccxx . . $ TRole#isTopFunc(50ce9a9e25b4a850).() ) // self-proclaimed TF but not real -- need to be updated
294 TopFunccxx . . $ TRole#TopFunc..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
295
296 // register all real TFs
297 for ( const auto& sup: ancestorscxx . . $ TRole#ancestors(5c1fd3e4e1fb59f2).() )
298 if ( sup->isRealTopFunccxx . . $ TRole#isRealTopFunc(50ce9a9e25b4a850).() )
299 TopFunccxx . . $ TRole#TopFunc..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(sup);
300
301 if ( !TopFunccxx . . $ TRole#TopFunc..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() )
302 Functionalitycxx . . $ TRole#Functionality..setValuecxx . . $ TRole#TKnownValue#setValue(b45ddcbc8423892c).(true);
303 }
304
305 // disjoint-related implementation
306
307 /// check (and correct) case whether R != S for R [= S
308 void TRolecxx . . $ TRole# :: checkHierarchicalDisjointcxx . . $ TRole#checkHierarchicalDisjoint(3d6e099a537f0595). ( TRolecxx . . $ TRole#* R )
309 {
310 // if element is disjoint with itself -- the role is empty
311 if ( Disjointcxx . . $ TRole#Disjoint..countcxx . . $ std/set#count(a9c5b6ffd713dfa6).(R) )
312 {
313 setDomaincxx . . $ TRole#setDomain(edf821a2fc5509f9).(createBottomcxx . . $ createBottom(aa22cc08b69ae2ef).());
314 Disjointcxx . . $ TRole#Disjoint..clearcxx . . $ std/set#clear(49f6e7a06ebc5aa8).();
315 return;
316 }
317
318 // check whether a sub-role is disjoint with the given one
319 for ( auto& sub: R->descendantscxx . . $ TRole#descendants(5c1fd3e4e1fb59f2).() )
320 if ( Disjointcxx . . $ TRole#Disjoint..countcxx . . $ std/set#count(a9c5b6ffd713dfa6).(sub) )
321 {
322 sub->setDomaincxx . . $ TRole#setDomain(edf821a2fc5509f9).(createBottomcxx . . $ createBottom(aa22cc08b69ae2ef).());
323 Disjointcxx . . $ TRole#Disjoint..erasecxx . . $ std/set#erase(3a53bfe100edb289).(sub);
324 sub->Disjointcxx . . $ TRole#Disjoint..clearcxx . . $ std/set#clear(49f6e7a06ebc5aa8).();
325 }
326 }
327
328 /// init map of all disjoint roles (N is a size of a bitmap)
329 void TRolecxx . . $ TRole# :: initDJMapcxx . . $ TRole#initDJMap(49f6e7a06ebc5aa8). ( void )
330 {
331 // role R is disjoint with every role S' [= S such that R != S
332 for ( const TRolecxx . . $ TRole#* role : Disjointcxx . . $ TRole#Disjoint. )
333 DJRolescxx . . $ TRole#DJRoles.[cxx . . $ std/vector#`operator[]`(1450282ea0befc17).role->getIndexcxx . . $ TRole#getIndex(ddd8539a2fcdd4ce).()] =cxx . . $ std/_Bit_reference#`operator=`(2b7708a91196d621). true;
334 }
335
336 // automaton-related implementation
337
338 void
339 TRolecxx . . $ TRole# :: preprocessCompositioncxx . . $ TRole#preprocessComposition(9f78be017486fe7b). ( TRoleVeccxx . . $ TRole#TRoleVec#& RS )
340 {
341 bool same = false;
342 size_t last = RS.sizecxx . . $ std/vector#size(fe4d2d262d4164a8).()-1;
343 size_t i = 0; // current element of the composition
344
345 for ( TRoleVeccxx . . $ TRole#TRoleVec#::iteratorcxx . . $ std/vector#iterator# p = RS.begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = RS.endcxx . . $ std/vector#end(33b10a496a38335b).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p, ++i )
346 {
347 TRolecxx . . $ TRole#* R = resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p);
348
349 if ( R->isBottomcxx . . $ TNamedEntry#isBottom(50ce9a9e25b4a850).() ) // empty role in composition -- nothing to do
350 {
351 RS.clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
352 return;
353 }
354 if ( R == this ) // found R in composition
355 {
356 if ( i != 0 && i != last ) // R in the middle of the composition
357 throw EFPPCycleInRIAcxx . . $ EFPPCycleInRIA#(getNamecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).());
358 if ( same ) // second one
359 {
360 if ( last == 1 ) // transitivity
361 {
362 RS.clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
363 setTransitivecxx . . $ TRole#setTransitive(b45ddcbc8423892c).();
364 return;
365 }
366 else // wrong (undecidable) axiom
367 throw EFPPCycleInRIAcxx . . $ EFPPCycleInRIA#(getNamecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).());
368 }
369 else // first one
370 same = true;
371 }
372
373 *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p = R; // replace possible synonyms
374 }
375 }
376
377 /// complete role automaton
378 void TRolecxx . . $ TRole# :: completeAutomatoncxx . . $ TRole#completeAutomaton(3cce881a86f6be27). ( TRoleSetcxx . . $ TRole#TRoleSet#& RInProcess )
379 {
380 // check whether RA is already complete
381 if ( Acxx . . $ TRole#A..isCompletedcxx . . $ RoleAutomaton#isCompleted(50ce9a9e25b4a850).() )
382 return;
383
384 // if we found a cycle...
385 if ( RInProcess.findcxx . . $ std/set#find(f8922f46a681e6cc).(this) !=cxx . . $ std/`operator!=`(7e1308a0738ea758). RInProcess.endcxx . . $ std/set#end(a1617ab40ea76896).() )
386 throw EFPPCycleInRIAcxx . . $ EFPPCycleInRIA#(getNamecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).());
387
388 // start processing role
389 RInProcess.insertcxx . . $ std/set#insert(10916b2dbd511ba8).(this);
390
391 // make sure that all sub-roles already have completed automata
392 for ( auto& sub: descendantscxx . . $ TRole#descendants(5c1fd3e4e1fb59f2).() )
393 sub->completeAutomatoncxx . . $ TRole#completeAutomaton(3cce881a86f6be27).(RInProcess);
394
395 // add automata for complex role inclusions
396 for ( auto& subComp: subCompositionscxx . . $ TRole#subCompositions. )
397 addSubCompositionAutomatoncxx . . $ TRole#addSubCompositionAutomaton(4f4bf62c685b677). ( subComp, RInProcess );
398
399 // check for the transitivity
400 if ( isTransitivecxx . . $ TRole#isTransitive(50ce9a9e25b4a850).() )
401 Acxx . . $ TRole#A..addTransitionSafecxx . . $ RoleAutomaton#addTransitionSafe(ee5932827597e1f9). ( Acxx . . $ TRole#A..finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce).(), RATransitioncxx . . $ RATransition#(Acxx . . $ TRole#A..initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).()) );
402
403 // here automaton is complete
404 Acxx . . $ TRole#A..setCompletedcxx . . $ RoleAutomaton#setCompleted(49f6e7a06ebc5aa8).();
405
406 if ( likelycxx . . $ `Kernel/globaldef.h:28:10`!(!isBottom()) ) // FIXME!! for now; need better Top/Bot synonyms processing
407 for ( auto& p: toldcxx . . $ ClassifiableEntry#told(e7230ad44187fae2).() )
408 {
409 TRolecxx . . $ TRole#* R = resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(static_cast<TRolecxx . . $ TRole#*>(p));
410 if ( R->isTopcxx . . $ TNamedEntry#isTop(50ce9a9e25b4a850).() ) // do not propagate anything to a top-role
411 continue;
412 R->addSubRoleAutomatoncxx . . $ TRole#addSubRoleAutomaton(67b1ad1f11addbc2).(this);
413 if ( hasSpecialDomaincxx . . $ TRole#hasSpecialDomain(50ce9a9e25b4a850).() )
414 R->SpecialDomaincxx . . $ TRole#SpecialDomain. = true;
415 }
416
417 // finish processing role
418 RInProcess.erasecxx . . $ std/set#erase(3a53bfe100edb289).(this);
419 }
420
421 /// add automaton for a role composition
422 void
423 TRolecxx . . $ TRole# :: addSubCompositionAutomatoncxx . . $ TRole#addSubCompositionAutomaton(4f4bf62c685b677). ( TRoleVeccxx . . $ TRole#TRoleVec#& RS, TRoleSetcxx . . $ TRole#TRoleSet#& RInProcess )
424 {
425 // first preprocess the role chain
426 preprocessCompositioncxx . . $ TRole#preprocessComposition(9f78be017486fe7b).(RS);
427
428 if ( RS.emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) // fallout from transitivity axiom
429 return;
430
431 // here we need a special treatment for R&D
432 SpecialDomaincxx . . $ TRole#SpecialDomain. = true;
433
434 // tune iterators and states
435 auto p = RS.begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_last = RS.endcxx . . $ std/vector#end(33b10a496a38335b).() -cxx . . $ __gnu_cxx/__normal_iterator#operator-(d0cb2d2ebd313f38). 1;
436 RAStatecxx . . $ RAState# from = Acxx . . $ TRole#A..initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).(), to = Acxx . . $ TRole#A..finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce).();
437
438 if ( RS.frontcxx . . $ std/vector#front(feee51535944b307).() == this )
439 {
440 ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p;
441 from = Acxx . . $ TRole#A..finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce).();
442 }
443 else if ( RS.backcxx . . $ std/vector#back(feee51535944b307).() == this )
444 {
445 --cxx . . $ __gnu_cxx/__normal_iterator#operator--(93f2e9c3bc4efc49).p_last;
446 to = Acxx . . $ TRole#A..initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).();
447 }
448
449 // make sure the role chain contain at least one element
450 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( p <= p_last );
451
452 // create a chain
453 bool oSafe = false; // we couldn't assume that the current role automaton is i- or o-safe
454 Acxx . . $ TRole#A..initChaincxx . . $ RoleAutomaton#initChain(cb2f890c2fdad230).(from);
455 for ( ; p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). p_last; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p )
456 oSafe = Acxx . . $ TRole#A..addToChaincxx . . $ RoleAutomaton#addToChain(cdf2e7af082d3283). ( completeAutomatonByRolecxx . . $ TRole#completeAutomatonByRole(e4ba9dab185a60c5). ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p, RInProcess ), oSafe );
457
458 // add the last automaton to chain
459 Acxx . . $ TRole#A..addToChaincxx . . $ RoleAutomaton#addToChain(43b07b70767d9338). ( completeAutomatonByRolecxx . . $ TRole#completeAutomatonByRole(e4ba9dab185a60c5). ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p, RInProcess ), oSafe, to );
460 }