@@ -289,23 +289,19 @@ export class TypeModel {
289
289
randomTypeProbability : number ,
290
290
id : string
291
291
) : string {
292
- const probabilities = this . calculateProbabilitiesForElement (
293
- incorporateExecutionScore ,
294
- id
295
- ) ;
296
-
297
- // const x = new Map();
298
- // for (const [type, probability] of probabilities.entries()) {
299
- // const typeEnum = type.includes("<>") ? type.split("<>")[1] : type;
300
-
301
- // if (!x.has(typeEnum)) {
302
- // x.set(typeEnum, 0);
303
- // }
292
+ let probabilities ;
304
293
305
- // x.set(typeEnum, x.get(typeEnum) + probability);
306
- // }
307
- // console.log(id);
308
- // console.log(x);
294
+ // This allows caching of type scores. The only problem is that when a score of a relation changes it will not recalculate for the current element (only for the relation element)
295
+ if ( this . _scoreHasChangedMap . get ( id ) ) {
296
+ probabilities = this . calculateProbabilitiesForElement (
297
+ incorporateExecutionScore ,
298
+ id
299
+ ) ;
300
+ this . _scoreHasChangedMap . set ( id , false ) ;
301
+ } else {
302
+ // prevent recalculation of probabilities without score changes
303
+ probabilities = this . _elementTypeProbabilityMap . get ( id ) ;
304
+ }
309
305
310
306
const genericTypes = [
311
307
TypeEnum . ARRAY ,
@@ -357,10 +353,19 @@ export class TypeModel {
357
353
randomTypeProbability : number ,
358
354
id : string
359
355
) : string {
360
- const probabilities = this . calculateProbabilitiesForElement (
361
- incorporateExecutionScore ,
362
- id
363
- ) ;
356
+ let probabilities ;
357
+
358
+ // This allows caching of type scores. The only problem is that when a score of a relation changes it will not recalculate for the current element (only for the relation element)
359
+ if ( this . _scoreHasChangedMap . get ( id ) ) {
360
+ probabilities = this . calculateProbabilitiesForElement (
361
+ incorporateExecutionScore ,
362
+ id
363
+ ) ;
364
+ this . _scoreHasChangedMap . set ( id , false ) ;
365
+ } else {
366
+ // prevent recalculation of probabilities without score changes
367
+ probabilities = this . _elementTypeProbabilityMap . get ( id ) ;
368
+ }
364
369
365
370
const genericTypes = [
366
371
TypeEnum . ARRAY ,
@@ -421,16 +426,6 @@ export class TypeModel {
421
426
id : string ,
422
427
relationPairsVisited ?: Map < string , Set < string > >
423
428
) : Map < string , number > {
424
- // if (!this._scoreHasChangedMap.has(element)) {
425
- // throw new ImplementationError(`Element ${element} does not exist`);
426
- // }
427
- // if (this._scoreHasChangedMap.get(element) === false) {
428
- // // prevent recalculation of probabilities without score changes
429
- // return this._elementTypeProbabilityMap.get(element);
430
- // }
431
-
432
- // this._scoreHasChangedMap.set(element, false);
433
-
434
429
let probabilityMap = new Map < string , number > ( ) ;
435
430
436
431
if ( id === "anon" ) {
@@ -446,8 +441,6 @@ export class TypeModel {
446
441
447
442
if ( ! relationPairsVisited ) {
448
443
relationPairsVisited = new Map ( ) ;
449
- // this._scoreHasChangedMap.set(element, false);
450
- // this._elementTypeProbabilityMap.set(element, probabilityMap);
451
444
}
452
445
453
446
let totalScore = this . _sum ( typeScoreMap . values ( ) ) ;
0 commit comments