/
GIAcxlConversion.cpp
702 lines (591 loc) · 28.3 KB
/
GIAcxlConversion.cpp
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
/*******************************************************************************
*
* License: GNU Affero General Public License version 3 (AGPLv3)
*
*******************************************************************************/
/*******************************************************************************
*
* File Name: GIAcxlConversion.cpp
* Author: Richard Bruce Baxter - Copyright (c) 2005-2022 Baxter AI (baxterai.com)
* Project: General Intelligence Algorithm
* Project Version: 3r1a 05-June-2022
* Description: CXL Conversion - Converts GIA network nodes into a CXL file
* NB this function creates entity idActiveListReorderdIDforXMLsave values upon write to speed up linking process (does not use original idActiveList values)
* /
*******************************************************************************/
#include "GIAcxlConversion.hpp"
bool GIAcxlConversionClass::writeCmapToolsCXLFileOptimised(string xmlFileName, vector<GIAentityNode*>* entityNodesActiveListComplete, unordered_map<string,GIAentityNode*>* networkIndexEntityNodesListMap)
{
vector<GIAentityNode*>* entityNodesActiveListNetworkIndexes = new vector<GIAentityNode*>;
for(unordered_map<string,GIAentityNode*>::iterator networkIndexEntityNodesListMapIter = networkIndexEntityNodesListMap->begin(); networkIndexEntityNodesListMapIter != networkIndexEntityNodesListMap->end(); networkIndexEntityNodesListMapIter++)
{
GIAentityNode* entityNode = networkIndexEntityNodesListMapIter->second;
entityNodesActiveListNetworkIndexes->push_back(entityNode);
}
bool result;
result = writeCmapToolsCXLfile(xmlFileName, entityNodesActiveListComplete, entityNodesActiveListNetworkIndexes);
delete entityNodesActiveListNetworkIndexes;
return result;
}
bool GIAcxlConversionClass::writeCmapToolsCXLfile(string xmlFileName, vector<GIAentityNode*>* entityNodesActiveListComplete, const vector<GIAentityNode*>* entityNodesActiveListNetworkIndexes)
{
bool result = true;
XMLparserTag* firstTagInXMLFile = new XMLparserTag(); //the firstTagInXMLFile object must be initialised here (in ANNXMLconversion.cpp scope). if it is initialised in XMLparserClass.cpp else it will be come corrupted,
XMLparserTag* currentTagL0 = firstTagInXMLFile;
currentTagL0->name = NET_CXL_TAG_cmap;
XMLparserTag* newTag0 = new XMLparserTag(); //had to add a null tag
currentTagL0->nextTag = newTag0;
XMLparserAttribute* currentAttribute = currentTagL0->firstAttribute;
currentAttribute->name = NET_CXL_ATTRIBUTE_xmlns;
currentAttribute->value = NET_CXL_ATTRIBUTE_xmlns_DEFAULT_VALUE;
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
currentAttribute->name = NET_CXL_ATTRIBUTE_xmlnsdc;
currentAttribute->value = NET_CXL_ATTRIBUTE_xmlnsdc_DEFAULT_VALUE;
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
XMLparserTag* firstTagL1 = new XMLparserTag();
currentTagL0->firstLowerLevelTag = firstTagL1;
XMLparserTag* currentTagL1 = currentTagL0->firstLowerLevelTag;
XMLparserTag* newTag1 = new XMLparserTag(); //had to add a null tag
currentTagL1->nextTag = newTag1;
currentTagL1->name = NET_CXL_TAG_map;
XMLparserTag* firstTagL2 = new XMLparserTag();
currentTagL1->firstLowerLevelTag = firstTagL2;
XMLparserTag* currentTagL2 = currentTagL1->firstLowerLevelTag;
XMLparserTag* newTag2 = new XMLparserTag(); //had to add a null tag
currentTagL2->nextTag = newTag2;
int64_t currentCmapNodeIDinCmapNodeList;
#ifdef GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ_OLD
currentCmapNodeIDinCmapNodeList = 0;
for(int entityType=0; entityType<GIA_ENTITY_NUMBER_OF_TYPES; entityType++)
{
resetIDsForNodeList2(entityNodesActiveListComplete, ¤tCmapNodeIDinCmapNodeList, entityType);
}
#endif
currentCmapNodeIDinCmapNodeList = 0;
int64_t firstCmapNodeIDInNetworkIndexList = currentCmapNodeIDinCmapNodeList;
if(!generateCXLentityNodeTagList(currentTagL2, entityNodesActiveListComplete, entityNodesActiveListNetworkIndexes, ¤tCmapNodeIDinCmapNodeList, true, false))
{
result = false;
}
currentTagL2 = currentTagL2->nextTag;
newTag2 = new XMLparserTag(); //had to add a null tag
currentTagL2->nextTag = newTag2;
int64_t firstCmapNodeIDInLinkingPhraseList = currentCmapNodeIDinCmapNodeList; //NOT NECESSARY: redundant
if(!generateCXLentityNodeTagList(currentTagL2, entityNodesActiveListComplete, entityNodesActiveListNetworkIndexes, ¤tCmapNodeIDinCmapNodeList, false, false))
{
result = false;
}
XMLparserTag* firstTagInLinkingPhraseList = currentTagL2->firstLowerLevelTag;
currentTagL2 = currentTagL2->nextTag;
newTag2 = new XMLparserTag(); //had to add a null tag
currentTagL2->nextTag = newTag2;
currentCmapNodeIDinCmapNodeList = firstCmapNodeIDInNetworkIndexList;
if(!generateCXLentityNodeTagList(currentTagL2, entityNodesActiveListComplete, entityNodesActiveListNetworkIndexes, ¤tCmapNodeIDinCmapNodeList, true, true))
{
result = false;
}
currentTagL2 = currentTagL2->nextTag;
newTag2 = new XMLparserTag(); //had to add a null tag
currentTagL2->nextTag = newTag2;
currentCmapNodeIDinCmapNodeList = firstCmapNodeIDInLinkingPhraseList; //NOT NECESSARY: redundant
if(!generateCXLentityNodeTagList(currentTagL2, entityNodesActiveListComplete, entityNodesActiveListNetworkIndexes, ¤tCmapNodeIDinCmapNodeList, false, true))
{
result = false;
}
XMLparserTag* firstTagInLinkingPhraseAppearanceList = currentTagL2->firstLowerLevelTag;
currentTagL2 = currentTagL2->nextTag;
newTag2 = new XMLparserTag(); //had to add a null tag
currentTagL2->nextTag = newTag2;
XMLparserTag* currentTagInLinkingPhraseList = firstTagInLinkingPhraseList;
XMLparserTag* currentTagInLinkingPhraseAppearanceList = firstTagInLinkingPhraseAppearanceList;
while(currentTagInLinkingPhraseList->nextTag != NULL)
{
currentTagInLinkingPhraseList = currentTagInLinkingPhraseList->nextTag;
}
while(currentTagInLinkingPhraseAppearanceList->nextTag != NULL)
{
currentTagInLinkingPhraseAppearanceList = currentTagInLinkingPhraseAppearanceList->nextTag;
}
XMLparserTag* lastTagInLinkingPhraseList = currentTagInLinkingPhraseList;
XMLparserTag* lastTagInLinkingPhraseAppearanceList = currentTagInLinkingPhraseAppearanceList;
if(!generateCXLconnectionNodeTagList(currentTagL2, entityNodesActiveListComplete, entityNodesActiveListNetworkIndexes, ¤tCmapNodeIDinCmapNodeList, lastTagInLinkingPhraseList, lastTagInLinkingPhraseAppearanceList))
{
result = false;
}
if(!XMLparserClass.writeXMLfile(xmlFileName, firstTagInXMLFile))
{
result = false;
}
delete firstTagInXMLFile;
return result;
}
//generateCXLentityNodeTagList{}: generates and fills <networkIndex-list>, <networkIndex-appearance-list>, <linking-phrase-list> and <linking-phrase-appearance-list> tags.
bool GIAcxlConversionClass::generateCXLentityNodeTagList(XMLparserTag* firstTagInMap, vector<GIAentityNode*>* entityNodesActiveListComplete, const vector<GIAentityNode*>* entityNodesActiveListNetworkIndexes, int64_t* currentCmapNodeIDinCmapNodeList, bool networkIndexOrLinkingPhraseList, bool appearanceList)
{
bool result = true;
XMLparserTag* currentTagL0 = firstTagInMap;
if(networkIndexOrLinkingPhraseList)
{
if(!appearanceList)
{
currentTagL0->name = NET_CXL_TAG_networkIndexList;
}
else
{
currentTagL0->name = NET_CXL_TAG_networkIndexAppearanceList;
}
}
else
{
if(!appearanceList)
{
currentTagL0->name = NET_CXL_TAG_linkingPhraseList;
}
else
{
currentTagL0->name = NET_CXL_TAG_linkingPhraseAppearanceList;
}
}
XMLparserTag* newTag0 = new XMLparserTag(); //had to add a null tag
currentTagL0->nextTag = newTag0;
XMLparserTag* firstTagL1 = new XMLparserTag();
currentTagL0->firstLowerLevelTag = firstTagL1;
XMLparserTag* currentTagL1 = currentTagL0->firstLowerLevelTag;
XMLparserTag* newTag1 = new XMLparserTag(); //had to add a null tag
currentTagL1->nextTag = newTag1;
#ifdef GIA_CMAP_CONVERSION_SANITISED
if(networkIndexOrLinkingPhraseList)
{
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, GIA_ENTITY_TYPE_SUBSTANCE);
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, GIA_ENTITY_TYPE_CONCEPT);
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, GIA_ENTITY_TYPE_NETWORK_INDEX);
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, GIA_ENTITY_TYPE_QUALITY);
}
else
{
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, GIA_ENTITY_TYPE_ACTION); //required for timeCondition node printing
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, GIA_ENTITY_TYPE_CONDITION); //required for timeCondition node printing
}
#else
for(int entityType=0; entityType<GIA_ENTITY_NUMBER_OF_TYPES; entityType++)
{
currentTagL1 = addToCXLentityNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, networkIndexOrLinkingPhraseList, appearanceList, entityType);
}
#endif
return result;
}
XMLparserTag* GIAcxlConversionClass::addToCXLentityNodeTagList(XMLparserTag* currentTagL1, vector<GIAentityNode*>* entityNodesList, int64_t* currentCmapNodeIDinCmapNodeList, bool networkIndexOrLinkingPhraseList, bool appearanceList, const int entityType)
{
bool result = true;
for(vector<GIAentityNode*>::iterator entityNodesActiveCompleteListIterator = entityNodesList->begin(); entityNodesActiveCompleteListIterator < entityNodesList->end(); entityNodesActiveCompleteListIterator++)
{
GIAentityNode* currentEntity = *entityNodesActiveCompleteListIterator;
if(currentEntity->entityType == entityType)
{
#ifndef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_TIME_CONDITION_NODES
if(currentEntity->conditionType == CONDITION_NODE_TYPE_TIME)
{//this exception is required because timeCondition nodes have a separate idActiveList in Cmap maps / CXL
currentEntity->timeConditionNode->idActiveListReorderdIDforXMLsave = (*currentCmapNodeIDinCmapNodeList);
currentTagL1 = generateCXLentityNodeTag(currentTagL1, currentEntity->timeConditionNode->conditionName,* currentCmapNodeIDinCmapNodeList, currentEntity->timeConditionNode->printX, currentEntity->timeConditionNode->printY, networkIndexOrLinkingPhraseList, appearanceList);
(*currentCmapNodeIDinCmapNodeList) = (*currentCmapNodeIDinCmapNodeList) + 1;
}
#endif
if(!(currentEntity->disabled))
{
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES
if(currentEntity->instanceNodeList->empty())
{//if GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES; then do not add a networkIndex entity if it has an associated instance (substance node)
#endif
#ifdef GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ
currentEntity->idActiveListReorderdIDforXMLsave = *currentCmapNodeIDinCmapNodeList;
int64_t currentEntityID = currentEntity->idActiveListReorderdIDforXMLsave;
#elif defined GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ_OLD
//idActiveListReorderdIDforXMLsave already set
int64_t currentEntityID = currentEntity->idActiveListReorderdIDforXMLsave;
#else
int64_t currentEntityID = currentEntity->idActiveList;
#endif
currentTagL1 = generateCXLentityNodeTag(currentTagL1, currentEntity->entityName, currentEntityID, currentEntity->printX, currentEntity->printY, networkIndexOrLinkingPhraseList, appearanceList);
(*currentCmapNodeIDinCmapNodeList) = (*currentCmapNodeIDinCmapNodeList) + 1;
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES
}
#endif
}
}
}
return currentTagL1;
}
XMLparserTag* GIAcxlConversionClass::generateCXLentityNodeTag(XMLparserTag* currentTagL1, string entityName, int64_t entityID, int printX, int printY, const bool networkIndexOrLinkingPhraseList, const bool appearanceList)
{
bool result = true;
//generate neuron connection tag
if(networkIndexOrLinkingPhraseList)
{
if(!appearanceList)
{
currentTagL1->name = NET_CXL_TAG_networkIndex;
}
else
{
currentTagL1->name = NET_CXL_TAG_networkIndexAppearance;
}
}
else
{
if(!appearanceList)
{
currentTagL1->name = NET_CXL_TAG_linkingPhrase;
}
else
{
currentTagL1->name = NET_CXL_TAG_linkingPhraseAppearance;
}
}
XMLparserTag* firstTagL2 = new XMLparserTag();
currentTagL1->firstLowerLevelTag = firstTagL2;
XMLparserTag* currentTagL2 = currentTagL1->firstLowerLevelTag;
XMLparserAttribute* currentAttribute = currentTagL1->firstAttribute;
currentAttribute->name = NET_CXL_ATTRIBUTE_id;
currentAttribute->value = SHAREDvars.convertLongToString(entityID);
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
if(!appearanceList)
{
currentAttribute->name = NET_CXL_ATTRIBUTE_label;
currentAttribute->value = entityName;
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
}
else
{
currentAttribute->name = NET_CXL_ATTRIBUTE_x;
currentAttribute->value = SHAREDvars.convertIntToString(printX*GIA_CXL_EXPAND_RATIO);;
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
currentAttribute->name = NET_CXL_ATTRIBUTE_y;
currentAttribute->value = SHAREDvars.convertIntToString(printY*GIA_CXL_EXPAND_RATIO);;
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
}
XMLparserTag* newTag = new XMLparserTag();
currentTagL1->nextTag = newTag;
currentTagL1 = currentTagL1->nextTag;
return currentTagL1;
}
//generateCXLconnectionNodeTagList{}: generates <connection-list> tag, and fills <linking-phrase-list>, and <linking-phrase-appearance-list> tags
bool GIAcxlConversionClass::generateCXLconnectionNodeTagList(XMLparserTag* firstTagInMap, vector<GIAentityNode*>* entityNodesActiveListComplete, const vector<GIAentityNode*>* entityNodesActiveListNetworkIndexes, int64_t* currentCmapNodeIDinCmapNodeList, XMLparserTag* firstTagInLinkingPhraseList, XMLparserTag* firstTagInLinkingPhraseAppearanceList)
{
bool result = true;
XMLparserTag* currentTagInLinkingPhraseList = firstTagInLinkingPhraseList;
XMLparserTag* currentTagInLinkingPhraseAppearanceList = firstTagInLinkingPhraseAppearanceList;
XMLparserTag* currentTagL0 = firstTagInMap;
currentTagL0->name = NET_CXL_TAG_connectionList;
XMLparserTag* newTag0 = new XMLparserTag(); //had to add a null tag
currentTagL0->nextTag = newTag0;
XMLparserTag* firstTagL1 = new XMLparserTag();
currentTagL0->firstLowerLevelTag = firstTagL1;
XMLparserTag* currentTagL1 = currentTagL0->firstLowerLevelTag;
XMLparserTag* newTag1 = new XMLparserTag(); //had to add a null tag
currentTagL1->nextTag = newTag1;
for(int entityType=0; entityType<GIA_ENTITY_NUMBER_OF_TYPES; entityType++)
{
currentTagL1 = addToCXLconnectionNodeTagList(currentTagL1, entityNodesActiveListComplete, currentCmapNodeIDinCmapNodeList, firstTagL1, ¤tTagInLinkingPhraseList, ¤tTagInLinkingPhraseAppearanceList, firstTagL1, entityType);
}
return result;
}
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES
bool GIAcxlConversionClass::checkIfPassedRedundantNetworkIndexNodeRemoval(GIAentityNode* currentEntity)
{
bool result = false;
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES_OLD
if(currentEntity->instanceNodeList->empty())
{//if GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES; then do not add a networkIndex entity if it has an associated instance (substance node)
//if((currentEntity->entityType == GIA_ENTITY_TYPE_ACTION) || (currentEntity->entityType == GIA_ENTITY_TYPE_SUBSTANCE) || (currentEntity->entityType == GIA_ENTITY_TYPE_CONCEPT) || (currentEntity->entityType == GIA_ENTITY_TYPE_CONDITION))
//{//do not add raw networkIndex nodes
result = true;
}
#else
if(currentEntity->instanceNodeList->empty())
{
//entity does not have an associated instance [entity is either a raw/isolated networkIndex node, or it is a substance]
result = true;
}
else
{
//entity has an associated instance [entity is a networkIndex node]
if(!(currentEntity->relationshipSubjectEntity->empty()))
{
result = true;
}
if(!(currentEntity->relationshipObjectEntity->empty()))
{
result = true;
}
if(!(currentEntity->instanceReverseNodeList->empty()))
{//this shouldnt be defined, since this entity is a networkIndex node, not a substance node
result = true;
}
if(!(currentEntity->actionNodeList->empty()))
{
result = true;
}
if(!(currentEntity->actionReverseNodeList->empty()))
{
result = true;
}
if(!(currentEntity->conditionNodeList->empty()))
{
result = true;
}
if(!(currentEntity->conditionReverseNodeList->empty()))
{
result = true;
}
if(!(currentEntity->propertyNodeList->empty()))
{
result = true;
}
if(!(currentEntity->propertyReverseNodeList->empty()))
{
result = true;
}
if(!(currentEntity->definitionNodeList->empty()))
{
result = true;
}
if(!(currentEntity->definitionReverseNodeList->empty()))
{
result = true;
}
if(currentEntity->conditionType == CONDITION_NODE_TYPE_TIME)
{
result = true;
}
}
#endif
return result;
}
#endif
XMLparserTag* GIAcxlConversionClass::addToCXLconnectionNodeTagList(XMLparserTag* currentTagL1, vector<GIAentityNode*>* entityNodesList, int64_t* currentCmapNodeIDinCmapNodeList, const XMLparserTag* firstTagL1, XMLparserTag** currentTagInLinkingPhraseList, XMLparserTag** currentTagInLinkingPhraseAppearanceList, XMLparserTag* firstTagInConnectionsList, const int entityType)
{
bool result = true;
for(vector<GIAentityNode*>::iterator entityNodesActiveCompleteListIterator = entityNodesList->begin(); entityNodesActiveCompleteListIterator < entityNodesList->end(); entityNodesActiveCompleteListIterator++)
{
GIAentityNode* currentEntity = *entityNodesActiveCompleteListIterator;
if(currentEntity->entityType == entityType)
{
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES
if(checkIfPassedRedundantNetworkIndexNodeRemoval(currentEntity))
{
#endif
for(int i=0; i<GIA_ENTITY_NUMBER_OF_VECTOR_CONNECTION_TYPES; i++)
{
if(entityVectorConnectionCXLwriteArray[i])
{
#ifdef GIA_CMAP_CONVERSION_SANITISED
//directly link action/condition subject/objects together (like in a standard/CMapTools networkIndex map)
if(((i == GIA_ENTITY_VECTOR_CONNECTION_TYPE_RELATIONSHIP_SUBJECT) || (i == GIA_ENTITY_VECTOR_CONNECTION_TYPE_RELATIONSHIP_OBJECT))
{
if(entityIsRelationship(currentEntity))
{
vector<GIAentityConnectionClass*>* entitySubjectVectorConnection = currentEntity->relationshipSubjectEntity;
vector<GIAentityConnectionClass*>* entityObjectVectorConnection = currentEntity->relationshipObjectEntity;
bool subjectIsEmpty = false;
bool objectIsEmpty = false;
if(entitySubjectVectorConnection->empty())
{
subjectIsEmpty = true;
}
if(entityObjectVectorConnection->empty())
{
objectIsEmpty = true;
}
GIAentityConnectionClass* entitySubjectConnection = entitySubjectVectorConnection->begin(); //this could equally be back() as there is only 1 subject/object connection
GIAentityConnectionClass* entityObjectConnection = entityObjectVectorConnection->begin(); //this could equally be back() as there is only 1 subject/object connection
string connectionTypeName = currentEntity->entityName;
int64_t linkingPhraseID = currentEntity->idActiveListReorderdIDforXMLsave;
if(subjectIsEmpty)
{
entitySubjectConnection->entity = new GIAentityNode();
entitySubjectConnection->entity->CXLdummyNode = true;
}
if(objectIsEmpty)
{
entityObjectConnection->entity = new GIAentityNode();
entityObjectConnection->entity->CXLdummyNode = true;
}
if(!(subjectIsEmpty && objectIsEmpty))
{
currentTagL1 = generateCXLconnectionNodeTagAndLinkingPhraseTags(currentTagL1, entitySubjectEntity, entityObjectEntity, connectionTypeName, &linkingPhraseID, currentTagInLinkingPhraseList, currentTagInLinkingPhraseAppearanceList, firstTagInConnectionsList, true);
}
if(subjectIsEmpty)
{
delete entitySubjectConnection->entity;
delete entitySubjectConnection;
}
if(objectIsEmpty)
{
delete entityObjectConnection->entity;
delete entityObjectConnection;
}
}
}
else
{
#endif
if(!(currentEntity->entityVectorConnectionsArray[i].empty()))
{
for(vector<GIAentityConnection*>::iterator connectionIter = currentEntity->entityVectorConnectionsArray[i].begin(); connectionIter < currentEntity->entityVectorConnectionsArray[i].end(); connectionIter++)
{
bool pass = true;
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES_OLD
if(i == GIA_ENTITY_VECTOR_CONNECTION_TYPE_INSTANCE_REVERSE)
{
pass = false;
}
#endif
if(pass)
{
GIAentityNode* entity = (*connectionIter)->entity;
string connectionTypeName = entityVectorConnectionDrawConnectionNameArray[i];
currentTagL1 = generateCXLconnectionNodeTagAndLinkingPhraseTags(currentTagL1, currentEntity, entity, connectionTypeName, currentCmapNodeIDinCmapNodeList, currentTagInLinkingPhraseList, currentTagInLinkingPhraseAppearanceList, firstTagInConnectionsList, false);
}
}
}
#ifdef GIA_CMAP_CONVERSION_SANITISED
}
#endif
}
}
#ifndef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_TIME_CONDITION_NODES
if(currentEntity->conditionType == CONDITION_NODE_TYPE_TIME)
{
GIAentityNode fakeTimeEntity;
fakeTimeEntity.entityName = currentEntity->timeConditionNode->conditionName;
fakeTimeEntity.printX = currentEntity->timeConditionNode->printX;
fakeTimeEntity.printY = currentEntity->timeConditionNode->printY;
#ifdef GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ
fakeTimeEntity.idActiveListReorderdIDforXMLsave = currentEntity->timeConditionNode->idActiveListReorderdIDforXMLsave;
#elif defined GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ_OLD
fakeTimeEntity.idActiveListReorderdIDforXMLsave = currentEntity->timeConditionNode->idActiveList;
#else
fakeTimeEntity.idActiveList = currentEntity->timeConditionNode->idActiveList;
#endif
string connectionTypeName = "time";
currentTagL1 = generateCXLconnectionNodeTagAndLinkingPhraseTags(currentTagL1, currentEntity, &fakeTimeEntity, connectionTypeName, currentCmapNodeIDinCmapNodeList, currentTagInLinkingPhraseList, currentTagInLinkingPhraseAppearanceList, firstTagInConnectionsList, false);
}
#endif
#ifdef GIA_CMAP_CONVERSION_SANITISED_DO_NOT_ADD_REDUNDANT_NETWORK_INDEX_NODES
}
#endif
}
}
return currentTagL1;
}
XMLparserTag* GIAcxlConversionClass::generateCXLconnectionNodeTagAndLinkingPhraseTags(XMLparserTag* currentTagL1, const GIAentityNode* entity1, const GIAentityNode* entity2, string connectionTypeName, int64_t* currentCmapNodeIDinCmapNodeList, XMLparserTag** currentTagInLinkingPhraseList, XMLparserTag** currentTagInLinkingPhraseAppearanceList, const XMLparserTag* firstTagInConnectionsList, const bool alreadyMadeLinkingPhrase)
{
#ifdef GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ
int entity1ID = entity1->idActiveListReorderdIDforXMLsave;
int entity2ID = entity2->idActiveListReorderdIDforXMLsave;
#elif defined GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ_OLD
int entity1ID = entity1->idActiveListReorderdIDforXMLsave;
int entity2ID = entity2->idActiveListReorderdIDforXMLsave;
#else
int entity1ID = entity1->idActiveList;
int entity2ID = entity2->idActiveList;
#endif
int entity1X = entity1->printX;
int entity2X = entity2->printX;
int entity1Y = entity1->printY;
int entity2Y = entity2->printY;
int connectionTypeX = (entity1X + entity2X) / 2;
int connectionTypeY = (entity1Y + entity2Y) / 2;
int connectionID = (*currentCmapNodeIDinCmapNodeList);
//verify connection is not already found;
bool alreadyMadeConnection = false;
/*OLD:
XMLparserTag* currentTagInList = firstTagInConnectionsList;
while(currentTagInList->nextTag != NULL)
{
if(currentTagInList->nextTag->nextTag != NULL)
{
int currentFromIDinList[2];
int currentToIDinList[2];
XMLparserAttribute* firstAttributeInList[2];
firstAttributeInList[0] = currentTagInList->firstAttribute;
firstAttributeInList[1] = currentTagInList->nextTag->firstAttribute;
for(int i=0; i<2; i++)
{
XMLparserAttribute* currentAttributeInList = firstAttributeInList[i];
while(currentAttributeInList->nextAttribute != NULL)
{
if(currentAttributeInList->name == NET_CXL_TAG_fromid)
{
currentFromIDinList[i] = convertStringToInt(currentAttributeInList->value);
}
if(currentAttributeInList->name == NET_CXL_TAG_toid)
{
currentToIDinList[i] = convertStringToInt(currentAttributeInList->value);
}
currentAttributeInList = currentAttributeInList->nextAttribute;
}
}
if(((currentFromIDinList[0] == entity1ID) && (currentToIDinList[1] == entity2ID))
|| ((currentFromIDinList[1] == entity1ID) && (currentToIDinList[0] == entity2ID)))
{
alreadyMadeConnection = true;
}
}
currentTagInList = currentTagInList->nextTag;
}
*/
if(!alreadyMadeConnection)
{
if(!(entity1->CXLdummyNode))
{
currentTagL1 = generateCXLconnectionNodeTag(currentTagL1, entity1ID, connectionID);
}
if(!(entity2->CXLdummyNode))
{
currentTagL1 = generateCXLconnectionNodeTag(currentTagL1, connectionID, entity2ID);
}
if(!alreadyMadeLinkingPhrase)
{
*currentTagInLinkingPhraseList = generateCXLentityNodeTag(*currentTagInLinkingPhraseList, connectionTypeName, connectionID, connectionTypeX, connectionTypeY, false, false);
*currentTagInLinkingPhraseAppearanceList = generateCXLentityNodeTag(*currentTagInLinkingPhraseAppearanceList, connectionTypeName, connectionID, connectionTypeX, connectionTypeY, false, true);
(*currentCmapNodeIDinCmapNodeList) = (*currentCmapNodeIDinCmapNodeList) + 1;
}
}
return currentTagL1;
}
XMLparserTag* GIAcxlConversionClass::generateCXLconnectionNodeTag(XMLparserTag* currentTagL1, int64_t fromID, int64_t toID)
{
bool result = true;
//generate neuron connection tag
currentTagL1->name = NET_CXL_TAG_connection;
XMLparserTag* firstTagL2 = new XMLparserTag();
currentTagL1->firstLowerLevelTag = firstTagL2;
XMLparserTag* currentTagL2 = currentTagL1->firstLowerLevelTag;
XMLparserAttribute* currentAttribute = currentTagL1->firstAttribute;
currentAttribute->name = NET_CXL_TAG_fromid;
currentAttribute->value = SHAREDvars.convertLongToString(fromID);
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
currentAttribute->name = NET_CXL_TAG_toid;
currentAttribute->value = SHAREDvars.convertLongToString(toID);
currentAttribute = XMLparserClass.createNewAttribute(currentAttribute);
XMLparserTag* newTag = new XMLparserTag();
currentTagL1->nextTag = newTag;
currentTagL1 = currentTagL1->nextTag;
return currentTagL1;
}
#ifdef GIA_SEMANTIC_NET_CXL_REORDER_NETWORK_INDEX_IDS_UPON_CXL_WRITE_INSTEAD_OF_CXL_READ_OLD
//this method is insufficient due to time condition nodes
void resetIDsForNodeList2(vector<GIAentityNode*>* entityNodesList, int64_t* currentEntityNodeIDinNetworkIndexEntityNodesList, int entityType)
{
for(vector<GIAentityNode*>::iterator entityNodesActiveCompleteListIterator = entityNodesList->begin(); entityNodesActiveCompleteListIterator < entityNodesList->end(); entityNodesActiveCompleteListIterator++)
{
GIAentityNode* currentEntity = *entityNodesActiveCompleteListIterator;
if(currentEntity->entityType == entityType)
{
currentEntity->idActiveListReorderdIDforXMLsave = *currentEntityNodeIDinNetworkIndexEntityNodesList;
(*currentEntityNodeIDinNetworkIndexEntityNodesList) = (*currentEntityNodeIDinNetworkIndexEntityNodesList) + 1;
}
}
}
#endif