ontotext-yasgui-web-component 1.7.1 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,6 +84,9 @@ export class OntotextYasguiWebComponent {
84
84
  this.init(newConfig);
85
85
  }
86
86
  languageChanged(newLang) {
87
+ if (newLang === this.language) {
88
+ return;
89
+ }
87
90
  this.translationService.setLanguage(newLang);
88
91
  this.getOntotextYasgui()
89
92
  .then((ontotextYasgui) => {
@@ -472,38 +475,18 @@ export class OntotextYasguiWebComponent {
472
475
  // catch this to avoid unhandled rejection
473
476
  });
474
477
  break;
475
- case 'explain_query': {
476
- const query = ontotextYasgui.getQuery();
477
- if (query.startsWith(this.llmQueryOnlyComment)) {
478
- return;
479
- }
480
- if (query.startsWith(this.llmResultOnlyComment)) {
481
- ontotextYasgui.setQuery(query.replace(this.llmResultOnlyComment, this.llmQueryOnlyComment));
482
- }
483
- else {
484
- ontotextYasgui.setQuery(`${this.llmQueryOnlyComment}\n${query}`);
485
- }
478
+ case 'explain_query':
479
+ this.applyQueryLLMComment(ontotextYasgui, this.llmQueryOnlyComment);
486
480
  ontotextYasgui.query(undefined, EXPLAIN_PLAN_TYPE.LLM_EXPLAIN).catch(() => {
487
481
  // catch this to avoid unhandled rejection
488
482
  });
489
483
  break;
490
- }
491
- case 'explain_results': {
492
- const query = ontotextYasgui.getQuery();
493
- if (query.startsWith(this.llmResultOnlyComment)) {
494
- return;
495
- }
496
- if (query.startsWith(this.llmQueryOnlyComment)) {
497
- ontotextYasgui.setQuery(query.replace(this.llmQueryOnlyComment, this.llmResultOnlyComment));
498
- }
499
- else {
500
- ontotextYasgui.setQuery(`${this.llmResultOnlyComment}\n${query}`);
501
- }
484
+ case 'explain_results':
485
+ this.applyQueryLLMComment(ontotextYasgui, this.llmResultOnlyComment);
502
486
  ontotextYasgui.query(undefined, EXPLAIN_PLAN_TYPE.LLM_EXPLAIN).catch(() => {
503
487
  // catch this to avoid unhandled rejection
504
488
  });
505
489
  break;
506
- }
507
490
  }
508
491
  });
509
492
  }
@@ -576,6 +559,17 @@ export class OntotextYasguiWebComponent {
576
559
  onShortcutsOpenEvent(_event) {
577
560
  this.showKeyboardShortcutsDialog = !this.showKeyboardShortcutsDialog;
578
561
  }
562
+ /**
563
+ * Adds the LLM comment in the query, or replaces it if one is already present.
564
+ * Doesn't do anything if the query already contains the LLM comment.
565
+ */
566
+ applyQueryLLMComment(ontotextYasgui, llmComment) {
567
+ const query = ontotextYasgui.getQuery();
568
+ if (query.startsWith(llmComment)) {
569
+ return;
570
+ }
571
+ ontotextYasgui.setQuery(`${llmComment}\n${this.removeQueryLLMComments(query)}`);
572
+ }
579
573
  removeQueryLLMComments(userQuery) {
580
574
  return userQuery
581
575
  .replace(this.llmResultOnlyComment, '')