File: CTriggeredImplicationBinaryAbsorberPreProcess.h

package info (click to toggle)
konclude 0.6.2~dfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 26,992 kB
  • sloc: cpp: 250,898; xml: 54,573; makefile: 37; sh: 17; ansic: 3
file content (392 lines) | stat: -rw-r--r-- 18,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*
 *		Copyright (C) 2013, 2014, 2015 by the Konclude Developer Team.
 *
 *		This file is part of the reasoning system Konclude.
 *		For details and support, see <http://konclude.com/>.
 *
 *		Konclude is free software: you can redistribute it and/or modify it under
 *		the terms of version 2.1 of the GNU Lesser General Public License (LGPL2.1)
 *		as published by the Free Software Foundation.
 *
 *		You should have received a copy of the GNU Lesser General Public License
 *		along with Konclude. If not, see <http://www.gnu.org/licenses/>.
 *
 *		Konclude is distributed in the hope that it will be useful,
 *		but WITHOUT ANY WARRANTY; without even the implied warranty of
 *		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more
 *		details, see GNU Lesser General Public License.
 *
 */

#ifndef KONCLUDE_REASONER_PREPROCESS_CTRIGGEREDIMPLICATIONBINARYABSORBERPREPROCESS_H
#define KONCLUDE_REASONER_PREPROCESS_CTRIGGEREDIMPLICATIONBINARYABSORBERPREPROCESS_H

// Libraries includes
#include <QSet>

// Namespace includes
#include "CConcreteOntologyPreProcess.h"
#include "CConceptRoleIndividualLocator.h"
#include "CConceptTriggerLinker.h"
#include "CConceptRoleIndividualLocator.h"
#include "CNominalSchemaAbsorptionPathLinker.h"
#include "CNominalSchemaAbsorptionBranchLinker.h"


// Other includes
#include "Utilities/CDynamicExpandingMemoryManager.hpp"
#include "Utilities/CSortedNegLinker.hpp"

#include "Config/CConfigDataReader.h"

#include "Reasoner/Generator/CConcreteOntologyInverseRoleBuilder.h"

#include "Reasoner/Ontology/CConceptTextFormater.h"
#include "Reasoner/Ontology/COntologyTextFormater.h"
#include "Reasoner/Ontology/CNominalSchemaTemplate.h"
#include "Reasoner/Ontology/CNominalSchemaTemplateVector.h"

// Logger includes
#include "Logger/CLogger.h"



namespace Konclude {

	using namespace Config;

	namespace Reasoner {

		using namespace Generator;
		using namespace Ontology;

		namespace Preprocess {

			/*! 
			 *
			 *		\class		CTriggeredImplicationBinaryAbsorberPreProcess
			 *		\author		Andreas Steigmiller
			 *		\version	0.1
			 *		\brief		TODO
			 *
			 */
			class CTriggeredImplicationBinaryAbsorberPreProcess : public CConcreteOntologyPreProcess {
				// public methods
				public:
					//! Constructor
					CTriggeredImplicationBinaryAbsorberPreProcess();

					//! Destructor
					virtual ~CTriggeredImplicationBinaryAbsorberPreProcess();

					virtual CConcreteOntology *preprocess(CConcreteOntology *ontology, CPreProcessContext* context);


				// protected methods
				protected:
					typedef QPair<CConcept*,bool> TConceptNegationPair;
					typedef QPair<bool,bool> TOccuredAbsorbablePair;
					typedef QPair<CConcept*,CConcept*> TConceptPair;
					typedef QPair<CNominalSchemaAbsorptionBranchLinker*,CNominalSchemaAbsorptionBranchLinker*> TAbsorptionBranchPair;



					void asorbForallsToRanges(CConcept* topConcept);

					bool collectConjunctions(CConcept* concept, bool negated, QList< TConceptNegationPair >& conjList);

					void collectPositiveConcepts(CConcept* concept, bool negated, QSet<TConceptNegationPair>* positiveConceptSet);

					CConcept* getRoleDomainTriggerConcept(CRole* role);

					bool addConceptToImplied(CConcept* impliedConcept, CConcept* concept, bool negated);
					bool addSubClassConcept(CConcept* subclassConcept, CConcept* addedConcept, bool negated);
					bool addRoleDomainConcept(CRole* role, CConcept* addedConcept, bool negated);
					bool addRoleRangeConcept(CRole* role, CConcept* addedConcept, bool negated);
					CConcept* createCandidateEquivalentConcept(CConcept* eqConcept);
					CConcept* createImpliedConcept();
					CConcept* createImplicationConcept(CConcept* impliedConcept, bool negated);
					CConcept* createImplicationTriggerConcept(CConcept* impConcept, bool negated);
					bool addImplicationTrigger(CConcept* implConcept, CConcept* triggerConcept, bool negated);
					CConcept* createTriggerPropagationConcept(CConcept* destConcept, CRole* backwardPropRole);

					bool isEquivalenceConceptTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated, cint64* notAbsorbableOperandsCount = nullptr);
					bool isEquivalenceConceptCandidateExtractable(CConcept* orConcept, bool negated);
					CConcept* getEquivalenceConceptCandidateTriggeredImplication(CConcept* eqConcept, bool negated);
					bool isGCIConceptTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated, cint64* notAbsorbableOperandsCount = nullptr);
					bool isConceptImplicationTriggerable(CConcept* concept, bool negated, QHash<CConcept*,TOccuredAbsorbablePair>* conceptEqConAbsorbed);
					bool isConceptImplicationTriggerable(CConcept* concept, bool negated, QHash<CConcept*,TOccuredAbsorbablePair>* conceptEqConAbsorbed, cint64* openMultipleOccurCount, QList<TConceptNegationPair>** dependingCacheList);
					bool isConceptSimpleImplicationTriggerable(CConcept* concept, bool negated);
					void createEquivalenceAbsorbedTriggeredImplication(CConcept* eqConcept, bool negated, CSortedNegLinker<CConcept*>* absorpOpLinker);
					CConcept* createDisjunctionAbsorbedTriggeredImplication(CConcept* orConcept, bool negated);
					CConcept* createDisjunctionAbsorbedTriggeredImplication(CConcept* orConcept, bool negated, QList<TConceptNegationPair>& absorbList, QList<TConceptNegationPair>& candList);


					void mergeDependingCacheList(QList<TConceptNegationPair>** dependingCacheList, QList<TConceptNegationPair>** subDependingCacheList);



					CConceptTriggerLinker* getTriggersForConcept(CConcept* concept, bool negated);
					CConceptTriggerLinker* createTriggerLinker();
					CConceptTriggerLinker* copyTriggerLinkers(CConceptTriggerLinker* triggers);
					void releaseTriggerLinkers(CConceptTriggerLinker* triggers);


					CDatatypeValueSpaceConceptTriggerLinker* createValueSpaceConceptTriggerLinker();

					CConcept* getImplicationImpliedConcept(CConcept* implicationConcept);
					CConceptTriggerLinker* getImplicationTriggeredConceptForTriggers(CConceptTriggerLinker* triggers, CConcept** firstImplicationConcept);

					CConceptTriggerLinker* getUpdatedTriggerComplexities(CConceptTriggerLinker* triggers);

					bool findAndReplaceImplicationFromTriggers(CConceptTriggerLinker* trigger, CConceptTriggerLinker*& otherTriggers);


					CConcept* createTriggerConcept(bool branchTrigger = false);
					void addUnfoldingConceptForConcept(CConcept* concept, CConcept* addingUnfoldingConcept, bool addingNegation);
					void addUnfoldingConceptForImplicationConcept(CConcept* implicationConcept, CConcept* addingUnfoldingConcept, bool addingNegation);

					CConceptTriggerLinker* getPartialTriggersForConcept(CConcept* concept, bool negated);
					CConceptRoleBranchingTrigger* getSimpleBranchTriggersForConcept(CConcept* concept, bool negated);

					CConceptRoleBranchingTrigger* getBranchTiggers(CConceptTriggerLinker* triggers);

					CRole* getInverseRole(CRole* role);

					bool isDisjunctionConceptTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated);
					bool isDisjunctionConceptSimpleTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated);
					
					bool isDisjunctionConceptPartialTriggeredImplicationAbsorbable(CConcept* orConcept, bool negated);

					bool isConceptPartialImplicationTriggerable(CConcept* concept, bool negated, QSet<CConcept*>* conceptEqConAbsorbed);
					

					
					bool absorbGCIConceptsToTriggeredImplications(CConcept* orConcept, bool negated);

					void createGCIAbsorbedTriggeredImplication(CConcept* orConcept, bool negated, QList<TConceptNegationPair>& absorbList, QList<TConceptNegationPair>& candList);


					bool absorbPartialGCIConceptsToTriggeredImplications(CConcept* orConcept, bool negated);
					void createGCIPartialAbsorbedTriggeredImplication(CConcept* orConcept, bool negated, const QList<TConceptNegationPair>& absorbList);

					CConceptRoleBranchingTrigger* createDisjunctionPartialAbsorbedBranchTriggers(CConcept* orConcept, bool negated);
					CConceptRoleBranchingTrigger* createDisjunctionPartialAbsorbedBranchTriggers(CConcept* orConcept, bool negated, const QList<TConceptNegationPair>& absorbList);


					CConcept* createPartialExtendedAbsorbedTriggeredImplication(CConcept* impliedConcept, bool impliedNegation, const QList<TConceptNegationPair>& absorbList);
					CConcept* createPartialExtendedAbsorbedImpliedTriggerCocnept(const QList<TConceptNegationPair>& absorbList);
					CConceptTriggerLinker* createPartialExtendedAbsorbedImpliedTrigger(const QList<TConceptNegationPair>& absorbList);

					bool addAbsorbableDisjunctCandidates(CConcept* orConcept, bool negated, QList<TConceptNegationPair>& list);
					QList<TConceptNegationPair> splitAbsorbableDisjuncts(QList<TConceptNegationPair>& list);
					QList<TConceptNegationPair> getPartialAbsorbableDisjuncts(QList<TConceptNegationPair>& list);


					QString generateDebugGCIConceptString(CConcept* concept, bool conceptNegation);
					QString generateDebugGeneratedAbsorbedImplicationString(cint64 minNewConceptTag, cint64 lastNewConceptTag);


					void optimizeTriggerStructure();
					void replaceTrigger(CConcept* baseConcept, CConcept* replaceConcept, bool negated);
					void replaceOneTrigger(CConcept* baseConcept, CConcept* replaceConcept, bool negated);




					bool absorbNominalSchemaGCIConceptsToTriggeredImplications(CConcept* concept, bool negated);

					void createGCINominalSchemaAbsorbedTriggeredImplication(CConcept* orConcept, bool negated, QList<TConceptNegationPair>& absorbList, QList<TConceptNegationPair>& partialAbsorbList, QList<TConceptNegationPair>& candList, CNominalSchemaTemplate* nsTemplate);

					CNominalSchemaAbsorptionPathLinker* getAbsorbedNominalSchemaPaths(const QSet<TConceptNegationPair>& conceptSet, CNominalSchemaAbsorptionPathLinker* absorptionPathLinker, QHash<CConcept*,CVariable*>* nomSchConceptVariableHash, CNominalSchemaTemplate* nsTemplate);
					void collectNominalSchemaRelatedConcepts(CConcept* concept, bool negated, QSet<TConceptNegationPair>& conceptSet, CNominalSchemaTemplate* nsTemplate);
					void sortNominalSchemaRelatedConcepts(QSet<TConceptNegationPair>& conceptSet, CNominalSchemaTemplate* nsTemplate, QList<TConceptNegationPair>& nomSchConList, QList<TConceptNegationPair>& otherConList, QList<TConceptNegationPair>& orConList);

					CConcept* createBindingImplicationTriggeredConcept(CConcept* triggeredConcept, CConcept* impliedConcept);
					CConcept* createBindingCycleCloseConcept(CConcept* cycleCloseTriggerConcept, CConcept* impliedTriggerConcept);
					CConcept* createBindingTriggerConcept();
					CConcept* createBindingVariableConcept(CConcept* followingConcept, CVariable* variable);
					
					CConcept* createBindingToSuccessorPropagationConcept(CConcept* followingConcept, CRole* role);
					CConcept* createBindingFromSuccessorPropagationConcept(CConcept* followingConcept, CRole* role);


					CConcept* createBindingGroundingConcept(CNominalSchemaTemplate* nsTemplate, cint64 groundOpCode);
					void createBindingGroundConcept(CConcept*& groundingConcept, bool& groundingConNegation, const QList<TConceptNegationPair>& groundConceptList, CNominalSchemaTemplate* nsTemplate, cint64 groundOpCode);

					CNominalSchemaAbsorptionPathLinker* duplicateNominalSchemaAbsorptionPaths(CNominalSchemaAbsorptionPathLinker* abPathLinker, cint64 duplicateCount);




					CNominalSchemaAbsorptionBranchLinker* getAbsorbedJoinedNominalSchemaBranchLinker(CConcept* absorbingConcept, bool absorbingNegation, CConcept* backPropConTrigger, QHash<CConcept*,CVariable*>* nomSchConceptVariableHash, CNominalSchemaTemplate* nsTemplate);
					CNominalSchemaAbsorptionBranchLinker* getAbsorbedJoinedNominalSchemaBranchLinker(const QSet<TConceptNegationPair>& conceptSet, CConcept* backPropConTrigger, QHash<CConcept*,CVariable*>* nomSchConceptVariableHash, CNominalSchemaTemplate* nsTemplate);
					CNominalSchemaAbsorptionBranchLinker* getAbsorbedNominalSchemaBranchLinker(CConcept* absorbingConcept, bool absorbingNegation, CConcept* backPropConTrigger, QHash<CConcept*,CVariable*>* nomSchConceptVariableHash, CNominalSchemaTemplate* nsTemplate);

					CConcept* createBindingBackPropagationActivationTriggerConcept();
					CConcept* createBindingBackPropagationTriggerConcept();
					CConcept* createBindingBackPropagationImplicationTriggeredConcept(CConcept* triggeredConcept, CConcept* impliedConcept);
					bool addBindingBackPropagationTriggeredToImplicationConcept(CConcept* implicationConcept, CConcept* triggeredConcept);
					CConcept* createBindingBackPropagationToSuccessorConcept(CConcept* followingConcept, CRole* role);
					
					CConcept* createVariableBindingPropagationFromSuccessorConcept(CConcept* followingConcept, CRole* role);
					CConcept* createVariableBindingPropagationTriggerConcept();
					CConcept* createVariableBindingPropagationJoiningConcept(CConcept* joinConcept1, CConcept* joinConcept2, CConcept* impliedConcept);
					CConcept* createVariableBindingPropagationBindVariableConcept(CConcept* followingConcept, CVariable* variable);
					CConcept* createVariableBindingPropagationImplicationTriggeredConcept(CConcept* triggeredConcept, CConcept* impliedConcept);

					void createJoiningConceptVariableList(CConcept* joiningConcept, CNominalSchemaAbsorptionBranchLinker* abLinker1, CNominalSchemaAbsorptionBranchLinker* abLinker2);


					void addConceptOperand(CConcept* concept, CConcept* operandConcept, bool operandNegation);
					bool hasNominalSchemaAbsorbableConceptFillHash(CConcept* concept, bool negation, CBOXHASH<CConcept*,CConcept*>* absorbableConceptNominalSchemaConceptHash, CConcept* nominalSchemaConcept, QSet<CConcept*>* testedConceptSet);
					bool hasNominalSchemaConceptFillHash(CConcept* concept, CBOXHASH<CConcept*,CConcept*>* conceptNominalSchemaConceptHash, CConcept* nominalSchemaConcept, QSet<CConcept*>* testedConceptSet);
					void collectNominalSchemaConcepts(CConcept* concept, CBOXSET<CConcept*>* nominalSchemaConceptSet);

				// protected variables
				protected:
					class CAbsorpEquivalentClassItem {
						public:
							CAbsorpEquivalentClassItem(CConcept* eqConcept, CSortedNegLinker<CConcept*>* absorpOpLinker) {
								mEqConcept = eqConcept;
								mAbsorpOpLinker = absorpOpLinker;
							}
							CConcept* mEqConcept;
							CSortedNegLinker<CConcept*>* mAbsorpOpLinker;
					};


					CMemoryAllocationManager* mMemMan;
					CMBox* mMBox;
					CTBox* mTBox;

					QHash<TConceptPair,CConceptTriggerLinker*> mConceptImplicationImpliedHash;
					QHash<TConceptNegationPair,CConceptTriggerLinker*> mConceptTriggerLinkerHash;
					CConceptTriggerLinker* mTmpTriggerLinker;

					QList<CConceptTriggerLinker*> mTriggerContainer;
					QList<CSortedNegLinker<CConcept*>*> mLaterTopConceptTriggerAddList;


					QHash<TConceptNegationPair,CConcept*> mConceptTriggerHash;
					QHash<CConcept*,cint64> mTriggerCountHash;
					CConceptVector* mConceptVec;
					CConcept* mBottomConcept;
					CConcept* mTopConcept;
					CConcreteOntology* mOnto;
					CBranchingTriggerVector* mBranchTriggVec;
					CNominalSchemaTemplateVector* mNomSchemaTemplVec;

					CBOXHASH<CConcept*,CConcept*>* mTriggerImplHash;

					QHash<TConceptNegationPair,bool> mConceptTotalAbsorbableHash;
					QHash<TConceptNegationPair,bool> mConceptPartialAbsorbableHash;
					QSet<CConcept*> mEQNotConceptPartialAbsorbableSet;


					CBOXHASH<CConcept*,CConcept*>* mEquivConCandidateHash;
					CBOXHASH<CConcept*,CConcept*>* mCandidateEquivConHash;
					CBOXSET<CConcept*>* mEquivConNonCandidateSet;


					QHash<CRole*,CConcept*>* mRoleDomainTriggerConceptHash;

					QHash<TConceptNegationPair,CNominalSchemaAbsorptionBranchLinker*> mConceptNomSchAbsorpBranchLinkerHash;
					QHash<TAbsorptionBranchPair,CNominalSchemaAbsorptionBranchLinker*> mAbsorptionBranchPairAbsorptionBranchHash;

					QHash<CRole*,CRole*> mRoleInverseRoleCreateHash;
					CBOXHASH<cint64,CConcept*>* mIndividualTriggerConceptHash;


					cint64 mNextVariableID;

					bool mConfRequiresExistingInverseRole;
					bool mConfAbsorbEqClassDefinitions;
					bool mConfPartialAbsorbEqClassDefinitions;
					bool mConfPartialGCIAbsorption;
					bool mConfAbsorbDisjunctions;
					bool mConfAbsorbSimpleDisjunctions;
					bool mConfPartialDisjunctionsAbsorption;
					bool mConfOnlyPositiveDisjunctionsAbsorption;

					bool mConfNominalSchemaPathPreabsorption;

					bool mConfVariableMultipleTriggeredBackwardChainingAbsorption;

					bool mConfNominalSchemaBackPropagation;
					bool mConfNominalSchemaBackPropagationMultiTrigger;
					bool mConfImplicationsForTriggerReusue;
					bool mConfPunishOftenSameTriggerUse;
					cint64 mConfOftenTriggerUseCountPunishment;

					bool mConfDatatypeAbsorption;


					class CTriggCount {
						public:
							inline CTriggCount() {
								mCount = 0;
							}
							inline void incCount(cint64 count = 1) {
								mCount += count;
							}
							cint64 mCount;
					};

					QHash<CConcept*,CTriggCount> mTriggCountHash;

					class CBackPropTrigHashData {
						public:
							inline CBackPropTrigHashData(CConcept* activationTriggerConcept, CConcept* implicationConcept) {
								mActivationTriggerConcept = activationTriggerConcept;
								mImplicationConcept = implicationConcept;
							}
							CConcept* mActivationTriggerConcept;
							CConcept* mImplicationConcept;
					};


					QHash<CConcept*,CBackPropTrigHashData*> mVarBackPropTrigHash;
					QList<CBackPropTrigHashData*> mVarBackPropTrigContainer;


					cint64 mStatInvRolesGenerated;
					cint64 mStatGCIAbsorbed;
					cint64 mStatGCINormalAbsorbed;
					cint64 mStatGCIPartialAbsorbed;
					cint64 mStatGCIAbsorptionPartialExtended;
					cint64 mStatGCITotal;
					cint64 mStatEqAbsorbed;
					cint64 mStatEqTotal;
					cint64 mStatImplConceptsGenerated;
					cint64 mStatReusedImplications;
					cint64 mStatOptimizedRemovedTriggers;
					cint64 mStatGCINormalSchemaAbsorbed;

					QString mDebugGCIString;
					QString mDebugAbsorbedString;

					QString mDebugLastGCIString;
					QString mDebugLastAbsorbedGCIConceptString;
					QString mDebugLastAbsorbedGCITechniqueString;
					QString mDebugLastAbsorbedGCIString;
					QString mDebugTotalAbsorbedGCIString;
					cint64 mLastNewConceptTag;
					cint64 mFirstNewConceptTag;

				// private methods
				private:

				// private variables
				private:


			};

		}; // end namespace Preprocess

	}; // end namespace Reasoner

}; // end namespace Konclude

#endif // KONCLUDE_REASONER_PREPROCESS_CTRIGGEREDIMPLICATIONBINARYABSORBERPREPROCESS_H