Debian Codegraph @

Kernel/tConcept.h

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 #ifndef TCONCEPT_H
21 #define TCONCEPT_Hcxx . . $ `Kernel/tConcept.h:21:9`!
22
23 #include <set>
24
25 #include "taxNamEntry.h"cxx . . $ `<file>/Kernel/taxNamEntry.h`/
26 #include "tNameSet.h"cxx . . $ `<file>/Kernel/tNameSet.h`/
27 #include "tLabeller.h"cxx . . $ `<file>/Kernel/tLabeller.h`/
28 #include "dltree.h"cxx . . $ `<file>/Kernel/dltree.h`/
29 #include "dlVertex.h"cxx . . $ `<file>/Kernel/dlVertex.h`/
30 #include "LogicFeature.h"cxx . . $ `<file>/Kernel/LogicFeature.h`/
31
32 /// type of concept wrt classifiability
33 enum CTTagcxx . . $ CTTag#
34 {
35 /// not specified
36 cttUnspecifiedcxx . . $ cttUnspecified.,
37 /// concept with all parents -- TCD
38 cttTrueCompletelyDefinedcxx . . $ cttTrueCompletelyDefined.,
39 /// concept w/o any told subsumers
40 cttOrphancxx . . $ cttOrphan.,
41 /// concept with all parents -- LCD, TCD or Orphans
42 cttLikeCompletelyDefinedcxx . . $ cttLikeCompletelyDefined.,
43 /// concept with non-primitive TS
44 cttHasNonPrimitiveTScxx . . $ cttHasNonPrimitiveTS.,
45 /// any other primitive concept
46 cttRegularcxx . . $ cttRegular.,
47 /// any non-primitive concept (except synonyms)
48 cttNonPrimitivecxx . . $ cttNonPrimitive.,
49 };
50
51 inline char getCTTagNamecxx . . $ getCTTagName(b73a14fb0f7cb229). ( CTTagcxx . . $ CTTag# tag )
52 {
53 switch(tag)
54 {
55 case cttUnspecifiedcxx . . $ cttUnspecified.: return 'u';
56 case cttTrueCompletelyDefinedcxx . . $ cttTrueCompletelyDefined.: return 'T';
57 case cttOrphancxx . . $ cttOrphan.: return 'O';
58 case cttLikeCompletelyDefinedcxx . . $ cttLikeCompletelyDefined.: return 'L';
59 case cttHasNonPrimitiveTScxx . . $ cttHasNonPrimitiveTS.: return 'N';
60 case cttRegularcxx . . $ cttRegular.: return 'r';
61 case cttNonPrimitivecxx . . $ cttNonPrimitive.: return 'n';
62 default: return char();
63 }
64 }
65
66 class TRolecxx . . $ TRole#;
67 class SaveLoadManagercxx . . $ SaveLoadManager#;
68
69 /// class for representing concept-like entries
70 class TConceptcxx . . $ TConcept#: public ClassifiableEntrycxx . . $ ClassifiableEntry#
71 {
72 private: // members
73 /// label to use in relevant-only checks
74 TLabellercxx . . $ TLabeller#::LabelTypecxx . . $ TLabeller#LabelType# relcxx . . $ TConcept#rel. = 0;
75
76 protected: // types
77 /// set of extra rules
78 typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<size_tcxx . . $ size_t#> ERSetcxx . . $ TConcept#ERSet#;
79 /// set of roles
80 typedef stdcxx . . $ std/::setcxx . . $ std/set#<const TRolecxx . . $ TRole#*> RoleSSetcxx . . $ TConcept#RoleSSet#;
81
82 public: // type interface
83 /// extra rules iterators
84 typedef ERSetcxx . . $ TConcept#ERSet#::const_iteratorcxx . . $ std/vector#const_iterator# er_iteratorcxx . . $ TConcept#er_iterator#;
85
86 public: // members
87 /// description of a concept
88 DLTreecxx . . $ DLTree#* Descriptioncxx . . $ TConcept#Description. = nullptr;
89 /// classification type of concept: completely defined (true- or like-), no TS, other
90 CTTagcxx . . $ CTTag# classTagcxx . . $ TConcept#classTag. = cttUnspecifiedcxx . . $ cttUnspecified.;
91 /// depth of the concept wrt told subsumers
92 unsigned int tsDepthcxx . . $ TConcept#tsDepth. = 0;
93
94 /// pointer to the entry in DAG with concept name
95 BipolarPointercxx . . $ BipolarPointer# pNamecxx . . $ TConcept#pName. = bpINVALIDcxx . . $ bpINVALID.;
96 /// pointer to the entry in DAG with concept definition
97 BipolarPointercxx . . $ BipolarPointer# pBodycxx . . $ TConcept#pBody. = bpINVALIDcxx . . $ bpINVALID.;
98
99 /// features for C
100 LogicFeaturescxx . . $ LogicFeatures# posFeaturescxx . . $ TConcept#posFeatures.;
101 /// features for ~C
102 LogicFeaturescxx . . $ LogicFeatures# negFeaturescxx . . $ TConcept#negFeatures.;
103
104 /// all extra rules for a given concept
105 ERSetcxx . . $ TConcept#ERSet# erSetcxx . . $ TConcept#erSet.;
106
107 protected: // methods
108 // classification TAGs manipulation
109
110 /// calculate value of classification TAG based on told subsumers. WARNING: no TS cycles allowed
111 CTTagcxx . . $ CTTag# determineClassTagcxx . . $ TConcept#determineClassTag(9839f985a220c015). ( void );
112
113 /// @return true iff description contains references to THIS concept
114 bool hasSelfInDesccxx . . $ TConcept#hasSelfInDesc(4f9ee8c35ac4b1e6). ( const DLTreecxx . . $ DLTree#* p ) const;
115 /// @return copy of P with every entry of THIS replaced with true
116 DLTreecxx . . $ DLTree#* replaceSelfWithConstcxx . . $ TConcept#replaceSelfWithConst(8f188fbd9d5632d6). ( const DLTreecxx . . $ DLTree#* p ) const;
117
118 // told subsumers interface
119
120 /// adds concept as a told subsumer of current one; @return value for CDC analysis
121 bool addToldSubsumercxx . . $ TConcept#addToldSubsumer(3a0d410f9ff34d05). ( TConceptcxx . . $ TConcept#* p )
122 {
123 if ( p != this )
124 {
125 addParentIfNewcxx . . $ ClassifiableEntry#addParentIfNew(866fbb357e35bef0).(p);
126 if ( p->isSingletoncxx . . $ TConcept#isSingleton(50ce9a9e25b4a850).() || p->isHasSPcxx . . $ TConcept#isHasSP(50ce9a9e25b4a850).() )
127 setHasSPcxx . . $ TConcept#setHasSP(49f6e7a06ebc5aa8).(); // this has singleton parent
128 }
129
130 // if non-primitive concept was found in a description, it's not CD
131 return p->isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).();
132 }
133 /// init told subsumers of the concept by given DESCription; @return TRUE iff concept is CD
134 bool initToldSubsumerscxx . . $ TConcept#initToldSubsumers(791c1b764e5b10e1). ( const DLTreecxx . . $ DLTree#* desc, RoleSSetcxx . . $ TConcept#RoleSSet#& RolesProcessed );
135 /// init told subsumers of the concept by given DESCription; @return TRUE iff concept is CD
136 bool initToldSubsumerscxx . . $ TConcept#initToldSubsumers(937bda690ff1bb73). ( const DLTreecxx . . $ DLTree#* desc )
137 {
138 RoleSSetcxx . . $ TConcept#RoleSSet# RolesProcessedcxx . . $ std/set#set(49f6e7a06ebc5aa8).;
139 return initToldSubsumerscxx . . $ TConcept#initToldSubsumers(791c1b764e5b10e1). ( desc, RolesProcessed );
140 }
141 /// find told subsumers by given role's domain
142 void SearchTSbyRolecxx . . $ TConcept#SearchTSbyRole(d7566cf11d0aec48). ( const TRolecxx . . $ TRole#* R, RoleSSetcxx . . $ TConcept#RoleSSet#& RolesProcessed );
143 /// find told subsumers by given role and its supers domains
144 void SearchTSbyRoleAndSuperscxx . . $ TConcept#SearchTSbyRoleAndSupers(d7566cf11d0aec48). ( const TRolecxx . . $ TRole#* R, RoleSSetcxx . . $ TConcept#RoleSSet#& RolesProcessed );
145
146 public: // methods
147 /// the only c'tor
148 explicit TConceptcxx . . $ TConcept#TConcept(9c546c94e5fcce4e). ( const stdcxx . . $ std/::stringcxx . . $ std/string#& name )
149 : ClassifiableEntrycxx . . $ ClassifiableEntry# (name)
150 {
151 setPrimitivecxx . . $ TConcept#setPrimitive(49f6e7a06ebc5aa8).();
152 }
153 /// no copy c'tor
154 TConceptcxx . . $ TConcept#TConcept(1287e42b4084fe4d). ( const TConceptcxx . . $ TConcept#& ) = delete;
155 /// no assignment
156 TConceptcxx . . $ TConcept#& operatorcxx . . $ TConcept#`operator=`(ea8e5250d9e3140e). = ( const TConceptcxx . . $ TConcept#& ) = delete;
157 /// d'tor
158 ~cxx . . $ TConcept#`~TConcept`(49f6e7a06ebc5aa8).TConceptcxx . . $ TConcept#() override { deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(Descriptioncxx . . $ TConcept#Description.); }
159 /// clear all info of the concept. Use it in removeConcept()
160 void clearcxx . . $ TConcept#clear(49f6e7a06ebc5aa8). ( void );
161
162 // simple rules support
163
164 /// add index of a simple rule in TBox to the ER set
165 void addExtraRulecxx . . $ TConcept#addExtraRule(2c44cd906ae4e829). ( size_tcxx . . $ size_t# index )
166 {
167 erSetcxx . . $ TConcept#erSet..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(index);
168 // FIXME!! double check this!
169 setCompletelyDefinedcxx . . $ ClassifiableEntry#setCompletelyDefined(b45ddcbc8423892c).(false);
170 }
171 /// check if a concept is in a disjoint relation with anything
172 bool hasExtraRulescxx . . $ TConcept#hasExtraRules(50ce9a9e25b4a850). ( void ) const { return !erSetcxx . . $ TConcept#erSet..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); }
173 /// iterator for accessing DJ elements
174 er_iteratorcxx . . $ TConcept#er_iterator# er_begincxx . . $ TConcept#er_begin(f9318f544f1b9b20). ( void ) const { return erSetcxx . . $ TConcept#erSet..begincxx . . $ std/vector#begin(359ca5030082c9f).(); }
175 /// iterator for accessing DJ elements
176 er_iteratorcxx . . $ TConcept#er_iterator# er_endcxx . . $ TConcept#er_end(f9318f544f1b9b20). ( void ) const { return erSetcxx . . $ TConcept#erSet..endcxx . . $ std/vector#end(359ca5030082c9f).(); }
177
178 // classification TAGs manipulation
179
180 /// get value of tag as it is
181 CTTagcxx . . $ CTTag# getClassTagcxx . . $ TConcept#getClassTag(863da13868153a34). ( void ) const { return classTagcxx . . $ TConcept#classTag.; }
182 /// get value of a tag; determine it if unset
183 CTTagcxx . . $ CTTag# getClassTagcxx . . $ TConcept#getClassTag(9839f985a220c015). ( void )
184 {
185 if ( classTagcxx . . $ TConcept#classTag. == cttUnspecifiedcxx . . $ cttUnspecified. )
186 classTagcxx . . $ TConcept#classTag. = determineClassTagcxx . . $ TConcept#determineClassTag(9839f985a220c015).();
187 return classTagcxx . . $ TConcept#classTag.;
188 }
189
190 // description manipulation
191
192 /// add concept expression to concept description
193 void addDesccxx . . $ TConcept#addDesc(edf821a2fc5509f9). ( DLTreecxx . . $ DLTree#* Desc );
194 /// @return true iff description contains top-level references to THIS concept
195 bool hasSelfInDesccxx . . $ TConcept#hasSelfInDesc(50ce9a9e25b4a850). ( void ) const { return hasSelfInDesccxx . . $ TConcept#hasSelfInDesc(4f9ee8c35ac4b1e6).(Descriptioncxx . . $ TConcept#Description.); }
196 /// remove concept from its own definition (like in case C [= (or C ...)
197 void removeSelfFromDescriptioncxx . . $ TConcept#removeSelfFromDescription(49f6e7a06ebc5aa8). ( void )
198 {
199 if ( hasSelfInDesccxx . . $ TConcept#hasSelfInDesc(50ce9a9e25b4a850).() )
200 {
201 DLTreecxx . . $ DLTree#* desc = Descriptioncxx . . $ TConcept#Description.;
202 Descriptioncxx . . $ TConcept#Description. = replaceSelfWithConstcxx . . $ TConcept#replaceSelfWithConst(8f188fbd9d5632d6).(desc);
203 deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(desc);
204 }
205 initToldSubsumerscxx . . $ TConcept#initToldSubsumers(49f6e7a06ebc5aa8).();
206 }
207 /// remove concept description (to save space)
208 void removeDescriptioncxx . . $ TConcept#removeDescription(49f6e7a06ebc5aa8). ( void )
209 { // save Synonym value
210 deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(Descriptioncxx . . $ TConcept#Description.);
211 Descriptioncxx . . $ TConcept#Description. = nullptr;
212 }
213 /// check whether it is possible to init this as a non-primitive concept with DESC
214 bool canInitNonPrimcxx . . $ TConcept#canInitNonPrim(38a18fab043f8799). ( DLTreecxx . . $ DLTree#* desc )
215 {
216 if ( Descriptioncxx . . $ TConcept#Description. == nullptr )
217 return true;
218 if ( isNonPrimitivecxx . . $ TConcept#isNonPrimitive(50ce9a9e25b4a850).() && equalTreescxx . . $ equalTrees(d3c03bdc42525896).(Descriptioncxx . . $ TConcept#Description.,desc) )
219 return true;
220 return false;
221 }
222 /// switch primitive concept to non-primitive with new definition; @return old definition
223 DLTreecxx . . $ DLTree#* makeNonPrimitivecxx . . $ TConcept#makeNonPrimitive(1bf715d485c1268). ( DLTreecxx . . $ DLTree#* desc )
224 {
225 DLTreecxx . . $ DLTree#* ret = Descriptioncxx . . $ TConcept#Description.;
226 Descriptioncxx . . $ TConcept#Description. = desc;
227 setPrimitivecxx . . $ TConcept#setPrimitive(b45ddcbc8423892c).(false);
228 return ret;
229 }
230
231 /// init told subsumers of the concept by it's description
232 virtual void initToldSubsumerscxx . . $ TConcept#initToldSubsumers(49f6e7a06ebc5aa8). ( void )
233 {
234 toldSubsumerscxx . . $ ClassifiableEntry#toldSubsumers..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
235 clearHasSPcxx . . $ TConcept#clearHasSP(49f6e7a06ebc5aa8).();
236 // normalise description if the only parent is TOP
237 if ( isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).() && Descriptioncxx . . $ TConcept#Description. && Descriptioncxx . . $ TConcept#Description.->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).() ==cxx . . $ TLexeme#`operator==`(b418e6031985303a). TOPcxx . . $ TOP. )
238 removeDescriptioncxx . . $ TConcept#removeDescription(49f6e7a06ebc5aa8).();
239
240 bool CD = !hasExtraRulescxx . . $ TConcept#hasExtraRules(50ce9a9e25b4a850).() && isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).(); // not a completely defined if there are extra rules
241 if ( Descriptioncxx . . $ TConcept#Description. != nullptr ) // init (additional) told subsumers from definition
242 CD &= initToldSubsumerscxx . . $ TConcept#initToldSubsumers(937bda690ff1bb73).(Descriptioncxx . . $ TConcept#Description.);
243 setCompletelyDefinedcxx . . $ ClassifiableEntry#setCompletelyDefined(b45ddcbc8423892c).(CD);
244 }
245 /// init TOP told subsumer if necessary
246 void setToldTopcxx . . $ TConcept#setToldTop(3f0281ca3ae282d4). ( TConceptcxx . . $ TConcept#* top )
247 {
248 if ( Descriptioncxx . . $ TConcept#Description. == nullptr && !hasToldSubsumerscxx . . $ ClassifiableEntry#hasToldSubsumers(50ce9a9e25b4a850).() )
249 addParentcxx . . $ ClassifiableEntry#addParent(866fbb357e35bef0).(top);
250 }
251 /// calculate depth wrt told subsumers; return the depth
252 unsigned int calculateTSDepthcxx . . $ TConcept#calculateTSDepth(db52760e79bf9054). ( void );
253
254 // used in the start procedure of SAT/SUBSUME tests
255 BipolarPointercxx . . $ BipolarPointer# resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf). ( void ) const; // returns either pName or pBody
256
257 /// register a Primitive flag
258 FPP_ADD_FLAGcxx . . $ TConcept#clearPrimitive(49f6e7a06ebc5aa8).(Primitive,0x10);
259 /// register a HasSingletonParent flag
260 FPP_ADD_FLAGcxx . . $ Flags#getFlag(8de63fdb265b07c1).(HasSP,0x20);
261 /// register a Nominal flag
262 FPP_ADD_FLAGcxx . . $ Flags#clearFlag(cb2f890c2fdad230).(Nominal,0x40);
263 /// register a Singleton flag
264 FPP_ADD_FLAGcxx . . $ Flags#setFlag(ee2069353d7cc01f).(Singleton,0x80);
265
266 // concept non-primitivity methods
267
268 /// check if concept is non-primitive concept
269 bool isNonPrimitivecxx . . $ TConcept#isNonPrimitive(50ce9a9e25b4a850). ( void ) const { return !isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).(); }
270
271 // relevance part
272
273 /// is given concept relevant to given Labeller's state
274 bool isRelevantcxx . . $ TConcept#isRelevant(cb76649e174af24). ( const TLabellercxx . . $ TLabeller#& lab ) const { return lab.isLabelledcxx . . $ TLabeller#isLabelled(7ba91045e28e2316).(relcxx . . $ TConcept#rel.); }
275 /// make given concept relevant to given Labeller's state
276 void setRelevantcxx . . $ TConcept#setRelevant(9ce72ecab6fc8b2b). ( const TLabellercxx . . $ TLabeller#& lab ) { lab.setcxx . . $ TLabeller#set(702af1567bd3bb3c).(relcxx . . $ TConcept#rel.); }
277 /// make given concept irrelevant to given Labeller's state
278 void dropRelevantcxx . . $ TConcept#dropRelevant(9ce72ecab6fc8b2b). ( const TLabellercxx . . $ TLabeller#& lab ) { lab.clearcxx . . $ TLabeller#clear(db0e23f8c3d03d8b).(relcxx . . $ TConcept#rel.); }
279
280 // save/load interface; implementation is in SaveLoad.cpp
281
282 /// save entry
283 void Savecxx . . $ TConcept#Save(aaac402dd6f8bcf7). ( SaveLoadManagercxx . . $ SaveLoadManager#& m ) const override;
284 /// load entry
285 void Loadcxx . . $ TConcept#Load(da67b8e43f9c9b96). ( SaveLoadManagercxx . . $ SaveLoadManager#& m ) override;
286 }; // TConcept
287
288 /// Class for comparison of TConcepts wrt told subsumer depth
289 class TSDepthComparecxx . . $ TSDepthCompare#
290 {
291 public:
292 bool operatorcxx . . $ TSDepthCompare#`operator()`(5bd30aa6be579af8).() ( const TConceptcxx . . $ TConcept#* p, const TConceptcxx . . $ TConcept#* q ) const
293 { return p->tsDepthcxx . . $ TConcept#tsDepth. < q->tsDepthcxx . . $ TConcept#tsDepth.; }
294 }; // TSDepthCompare
295
296 //----------------------------------------------------------------------------
297 //-- implementation
298 //----------------------------------------------------------------------------
299
300 inline BipolarPointercxx . . $ BipolarPointer# TConceptcxx . . $ TConcept# :: resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf). ( void ) const
301 {
302 // check for Top/Bottom
303 if ( pNamecxx . . $ TConcept#pName. == bpINVALIDcxx . . $ bpINVALID. )
304 return pBodycxx . . $ TConcept#pBody.;
305
306 if ( isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() ) // resolve synonyms
307 return resolveSynonymcxx . . $ resolveSynonym(bd9f52c6ae4be57a).(this)->resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf).();
308
309 return pNamecxx . . $ TConcept#pName.; // return concept's name
310 }
311
312 #endif