added highlighted source text of extracted keywords
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-07-06 18:49:49 +02:00
parent a69f014413
commit 1cf80ae074
2 changed files with 55 additions and 2 deletions
@@ -344,14 +344,16 @@
<mat-expansion-panel-header>
<mat-panel-title>Quellentext: {{ sourceUrl() }}</mat-panel-title>
</mat-expansion-panel-header>
<div class="source-text">{{ sourceContent() }}</div>
<div
class="source-text"
[innerHTML]="highlightedSourceContent()"></div>
</mat-expansion-panel>
}
</mat-card-content>
@if (isExtracting() && !keywordsExist()) {
<app-loading
text="{{ statusMessage() }}"
icon="group"
icon="manage_search"
[size]="200"
[diameter]="200" />
}
@@ -45,6 +45,7 @@ import {
} from '../../resolvers/utils/topic-legend';
import { MatTooltipModule } from '@angular/material/tooltip';
import { A11yModule } from '@angular/cdk/a11y';
import { DomSanitizer } from '@angular/platform-browser';
type InputMode = 'url' | 'text';
type KeywordCategory = 'broad' | 'coarse' | 'fine' | 'manual';
type KeywordView = 'llm' | 'topic';
@@ -77,6 +78,7 @@ type KeywordView = 'llm' | 'topic';
})
export class KeywordsSearchComponent {
private readonly formBuilder = inject(FormBuilder);
private readonly sanitizer = inject(DomSanitizer);
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly destroyRef = inject(DestroyRef);
@@ -128,6 +130,55 @@ export class KeywordsSearchComponent {
readonly sourceContent = signal<string>('');
readonly sourceUrl = signal<string | null>(null);
readonly highlightedSourceContent = computed(() => {
const content = this.sourceContent();
if (!content) return '';
const selectedKeywords = this.selectedKeywords();
if (selectedKeywords.length === 0) return content;
let highlightedContent = content;
// replace the keyword with highlighted spans
for (const keyword of selectedKeywords) {
const normalizedKeyword = this.normalizeKeyword(keyword);
// Find the first keyword entry that matches this normalized keyword
const entry = this.allKeywordEntries().find(
(e) =>
this.normalizeKeyword(this.getKeywordLabel(e)) === normalizedKeyword,
);
if (entry) {
const topic = this.getTopic(entry);
if (topic) {
const color = this.getTopicColor(topic);
// Escape HTML special characters in the keyword before using it in HTML
const escapedKeyword = keyword
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
// Create the replacement span HTML
const replacement = `<span style="background-color: color-mix(in srgb, ${color} 27%, #ffffff); 100%); font-weight: bold;" title="Keyword: ${keyword}">${escapedKeyword}</span>`;
const escapedRegexKeyword = keyword.replace(
/[.*+?^${}()|[\]\\]/g,
'\\$&',
);
const regex = new RegExp(escapedRegexKeyword, 'g');
highlightedContent = highlightedContent.replace(regex, replacement);
}
}
}
console.log(
'Highlighted content:',
this.sanitizer.bypassSecurityTrustHtml(highlightedContent),
);
return this.sanitizer.bypassSecurityTrustHtml(highlightedContent);
});
private isRestoringState = false;
// Set right before we call router.navigate() ourselves (from