Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa1edee597 | ||
|
|
7a12f681a8 | ||
|
|
fbdad69a1d | ||
|
|
339f12d553 | ||
|
|
cefc8c1b85 | ||
|
|
6794dde27e | ||
|
|
9e4a1c3c69 |
@@ -96,8 +96,7 @@ class Work(BaseModel):
|
||||
updated_date: datetime | None = Field(default=None, description="When this work was last updated (ISO 8601 datetime).")
|
||||
snippet: StrictStr | None = Field(default=None, description="Passage of the title or abstract containing the searched keyword, with the matches wrapped in `<em>`. Only set by the keyword search, and only when the keyword actually occurs in the text.")
|
||||
snippet_field: StrictStr | None = Field(default=None, description="Which field `snippet` was taken from: `title` or `abstract`.")
|
||||
matched_via: list[StrictStr] | None = Field(default=None, description="Names of the topics and OpenAlex keywords that matched the searched keywords. Set by the keyword search so a work matched purely on metadata can explain itself when there is no `snippet`.")
|
||||
__properties: ClassVar[list[str]] = ["id", "doi", "title", "display_name", "publication_year", "publication_date", "type", "language", "cited_by_count", "is_retracted", "is_paratext", "primary_location", "locations", "best_oa_location", "open_access", "authorships", "ids", "biblio", "abstract_inverted_index", "referenced_works", "referenced_works_count", "related_works", "topics", "primary_topic", "keywords", "funders", "awards", "fwci", "citation_normalized_percentile", "cited_by_percentile_year", "counts_by_year", "sustainable_development_goals", "mesh", "indexed_in", "has_content", "content_url", "created_date", "updated_date", "snippet", "snippet_field", "matched_via"]
|
||||
__properties: ClassVar[list[str]] = ["id", "doi", "title", "display_name", "publication_year", "publication_date", "type", "language", "cited_by_count", "is_retracted", "is_paratext", "primary_location", "locations", "best_oa_location", "open_access", "authorships", "ids", "biblio", "abstract_inverted_index", "referenced_works", "referenced_works_count", "related_works", "topics", "primary_topic", "keywords", "funders", "awards", "fwci", "citation_normalized_percentile", "cited_by_percentile_year", "counts_by_year", "sustainable_development_goals", "mesh", "indexed_in", "has_content", "content_url", "created_date", "updated_date", "snippet", "snippet_field"]
|
||||
|
||||
model_config = ConfigDict(
|
||||
validate_by_name=True,
|
||||
@@ -278,8 +277,7 @@ class Work(BaseModel):
|
||||
"created_date": obj.get("created_date"),
|
||||
"updated_date": obj.get("updated_date"),
|
||||
"snippet": obj.get("snippet"),
|
||||
"snippet_field": obj.get("snippet_field"),
|
||||
"matched_via": obj.get("matched_via")
|
||||
"snippet_field": obj.get("snippet_field")
|
||||
})
|
||||
return _obj
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ RELATED_BLOCK_SIZE = 5
|
||||
RELATED_TOPIC_K = 1
|
||||
EXACT_ID_CAP = 1000
|
||||
|
||||
KEYWORD_SEARCH_FIELDS = ["maintitle^3", "intro_content^2", "tags^2", "full_content"]
|
||||
KEYWORD_SEARCH_FIELDS = ["maintitle^3", "intro_content^2", "full_content"]
|
||||
KEYWORD_SEARCH_SCAN_CAP = 50000
|
||||
KEYWORD_SEARCH_ID_CAP = 2000
|
||||
TOPIC_DOCS_PER_ARTICLE = 25
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from datetime import date
|
||||
|
||||
import inse.authors.v2.service as author_service
|
||||
from inse.auth.model import AccessTokenMetadata
|
||||
@@ -295,33 +296,12 @@ async def get_works_by_keywords(
|
||||
{
|
||||
"bool": {
|
||||
"should": [
|
||||
{
|
||||
"nested": {
|
||||
"path": "keywords",
|
||||
"query": {
|
||||
"match_phrase": {"keywords.display_name": kw}
|
||||
},
|
||||
}
|
||||
},
|
||||
{"match_phrase": {"primary_topic.display_name": kw}},
|
||||
# The literal mode: title and abstract only. Topic
|
||||
# and keyword metadata is deliberately not matched
|
||||
# here. Expanding a keyword to related topics is
|
||||
# done in the fuzzy search.
|
||||
{"match_phrase": {"title": kw}},
|
||||
{"match_phrase": {"abstract": kw}},
|
||||
_topics_nested_clause(
|
||||
[
|
||||
{"match_phrase": {"topics.display_name": kw}},
|
||||
{"match_phrase": {"topics.field.display_name": kw}},
|
||||
{
|
||||
"match_phrase": {
|
||||
"topics.subfield.display_name": kw
|
||||
}
|
||||
},
|
||||
{
|
||||
"match_phrase": {
|
||||
"topics.domain.display_name": kw
|
||||
}
|
||||
},
|
||||
]
|
||||
),
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
@@ -335,6 +315,9 @@ async def get_works_by_keywords(
|
||||
# filters
|
||||
must = [topic_clause]
|
||||
|
||||
# Filter out publications with future 'published' years (e.g. 2036).
|
||||
must.append({"range": {"publication_year": {"lte": date.today().year}}})
|
||||
|
||||
if title:
|
||||
must.append(_title_query(title))
|
||||
if publication_year:
|
||||
@@ -378,10 +361,9 @@ async def get_works_by_keywords(
|
||||
track_total_hits=True,
|
||||
offset=page * size,
|
||||
sort=sort,
|
||||
# A work matches on its topic and keyword metadata as well as on its
|
||||
# text, so roughly half the hits contain the searched keyword nowhere in
|
||||
# title or abstract. Highlighting tells the two apart: a fragment comes
|
||||
# back only for the works that really do carry the phrase.
|
||||
# Supplies the expanded row. Retrieval is title and
|
||||
# abstract only, so every hit carries the searched term in one of the
|
||||
# two and a fragment always comes back.
|
||||
highlight={
|
||||
"fields": {
|
||||
"title": WHOLE_FIELD,
|
||||
@@ -408,7 +390,6 @@ async def get_works_by_keywords(
|
||||
snippet, snippet_field = _keyword_snippet(hit)
|
||||
work.snippet = snippet
|
||||
work.snippet_field = snippet_field
|
||||
work.matched_via = _matched_via(source, keywords)
|
||||
elements.append(work)
|
||||
|
||||
return WorkPageV2(elements=elements, total=total, page=page, size=size)
|
||||
@@ -430,42 +411,6 @@ def _keyword_snippet(hit: dict) -> tuple[str | None, str | None]:
|
||||
return None, None
|
||||
|
||||
|
||||
def _matched_via(source: dict, keywords: list[str] | None) -> list[str] | None:
|
||||
"""Names the topics and keywords a work was matched through.
|
||||
|
||||
Only needed when there is no snippet: those works carry the searched term in
|
||||
their metadata rather than in their text, and would otherwise expand into an
|
||||
empty row. Matching mirrors the `match_phrase` clauses above closely enough
|
||||
for a label - it is not used for retrieval.
|
||||
"""
|
||||
wanted = [kw.strip().lower() for kw in (keywords or []) if kw and kw.strip()]
|
||||
if not wanted:
|
||||
return None
|
||||
|
||||
candidates: list[str] = []
|
||||
|
||||
primary_topic = source.get("primary_topic") or {}
|
||||
candidates.append(primary_topic.get("display_name"))
|
||||
|
||||
for topic in source.get("topics") or []:
|
||||
candidates.append(topic.get("display_name"))
|
||||
for level in ("field", "subfield", "domain"):
|
||||
candidates.append((topic.get(level) or {}).get("display_name"))
|
||||
|
||||
for keyword in source.get("keywords") or []:
|
||||
candidates.append(keyword.get("display_name"))
|
||||
|
||||
names: list[str] = []
|
||||
for name in candidates:
|
||||
if not name or name in names:
|
||||
continue
|
||||
lowered = name.lower()
|
||||
if any(kw in lowered for kw in wanted):
|
||||
names.append(name)
|
||||
|
||||
return names or None
|
||||
|
||||
|
||||
async def get_author_works(
|
||||
raw_oa_author_id: str,
|
||||
page: int,
|
||||
|
||||
@@ -68,5 +68,4 @@ export interface Work {
|
||||
updated_date?: string | null;
|
||||
snippet?: string | null;
|
||||
snippet_field?: string | null;
|
||||
matched_via?: Array<string> | null;
|
||||
}
|
||||
|
||||
-14
@@ -20,20 +20,6 @@
|
||||
[content]="snippet.content"
|
||||
[highlights]="snippet.terms" />
|
||||
</article>
|
||||
} @else if (work.matched_via?.length) {
|
||||
<article class="panel-field panel-field--full">
|
||||
<h4 class="panel-field__label">Kein Treffer im Text</h4>
|
||||
<p class="panel-field__text">
|
||||
Das gesuchte Keyword kommt weder im Titel noch im Abstract vor.
|
||||
Die Publikation wurde über
|
||||
{{ work.matched_via!.length === 1 ? 'das Thema' : 'die Themen' }}
|
||||
@for (name of work.matched_via; track name; let last = $last) {
|
||||
<span class="matched-topic">{{ name }}</span
|
||||
>{{ last ? '' : ', ' }}
|
||||
}
|
||||
gefunden.
|
||||
</p>
|
||||
</article>
|
||||
} @else {
|
||||
<span class="empty-text">
|
||||
Für diese Publikation liegt keine Fundstelle vor.
|
||||
|
||||
-5
@@ -83,11 +83,6 @@
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.matched-topic {
|
||||
color: var(--sg-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
+10
-21
@@ -30,6 +30,10 @@ import {
|
||||
toggleTopicLegendSubfieldSelection,
|
||||
} from '../../../../resolvers/utils/topic-legend';
|
||||
import { buildTopicHierarchyTooltip } from '../../../../resolvers/utils/topic-tooltip';
|
||||
import {
|
||||
formatYearRange,
|
||||
normalizeSelectedYears,
|
||||
} from '../../../../resolvers/utils/year-range';
|
||||
import { workQueryParamKeys } from '../../../../resolvers/work-page.resolver';
|
||||
|
||||
export interface TopicTimelineTopic {
|
||||
@@ -303,12 +307,12 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
|
||||
this.topicSelect.emit({
|
||||
topic,
|
||||
years: this.normalizeSelectedYears(years),
|
||||
years: normalizeSelectedYears(years),
|
||||
});
|
||||
}
|
||||
|
||||
selectYears(years: number[]): void {
|
||||
const selectedYears = this.normalizeSelectedYears(years);
|
||||
const selectedYears = normalizeSelectedYears(years);
|
||||
|
||||
if (selectedYears.length === 0) {
|
||||
return;
|
||||
@@ -364,7 +368,7 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
return null;
|
||||
}
|
||||
|
||||
const selectedYears = this.normalizeSelectedYears(years);
|
||||
const selectedYears = normalizeSelectedYears(years);
|
||||
const cacheKey = `${topic.id}|${selectedYears.join(',')}`;
|
||||
const cached = this.topicActionCache.get(cacheKey);
|
||||
|
||||
@@ -374,7 +378,7 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
|
||||
const person = this.personName || 'dieser Person';
|
||||
const action: TimelineTopicAction = {
|
||||
label: `Publikationen von ${person} ${this.formatYearRange(selectedYears)}`,
|
||||
label: `Publikationen von ${person} ${formatYearRange(selectedYears)}`,
|
||||
link: this.personPublicationsLink,
|
||||
queryParams: {
|
||||
[workQueryParamKeys.page]: 0,
|
||||
@@ -421,18 +425,9 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
}
|
||||
|
||||
const person = this.personName || 'dieser Person';
|
||||
const selectedYears = this.normalizeSelectedYears(years);
|
||||
const selectedYears = normalizeSelectedYears(years);
|
||||
|
||||
return `Publikationen von ${person} zum Thema ${topic.name} ${this.formatYearRange(selectedYears)}`;
|
||||
}
|
||||
|
||||
private formatYearRange(years: number[]): string {
|
||||
const firstYear = years[0];
|
||||
const lastYear = years[years.length - 1];
|
||||
|
||||
return firstYear === lastYear
|
||||
? `(${firstYear})`
|
||||
: `(${firstYear}–${lastYear})`;
|
||||
return `Publikationen von ${person} zum Thema ${topic.name} ${formatYearRange(selectedYears)}`;
|
||||
}
|
||||
|
||||
getYearPublicationTooltip(item: TopicTimelineElement): string {
|
||||
@@ -1040,12 +1035,6 @@ export class ResearchTimelineComponent implements OnChanges, AfterViewChecked {
|
||||
.slice(0, this.displayedPhaseTopicLimit);
|
||||
}
|
||||
|
||||
private normalizeSelectedYears(years: number[]): number[] {
|
||||
return Array.from(new Set(years))
|
||||
.filter((year) => Number.isFinite(year))
|
||||
.sort((left, right) => left - right);
|
||||
}
|
||||
|
||||
private getDominantPrimaryTopicCandidates(
|
||||
item: TopicTimelineElement,
|
||||
): TopicTimelineTopic[] {
|
||||
|
||||
+123
-66
@@ -8,25 +8,21 @@ import {
|
||||
getTopicLegendSubfieldId,
|
||||
TopicLegendTopic,
|
||||
} from '../../../../resolvers/utils/topic-legend';
|
||||
import type {
|
||||
TopicTimelineElement,
|
||||
TopicTimelineTopic,
|
||||
} from '../research-timeline/research-timeline.component';
|
||||
import {
|
||||
formatYearRange,
|
||||
normalizeSelectedYears,
|
||||
} from '../../../../resolvers/utils/year-range';
|
||||
import { workQueryParamKeys } from '../../../../resolvers/work-page.resolver';
|
||||
|
||||
interface WordTooltipInputs {
|
||||
topicId: string;
|
||||
secondaryActionLabel: string | null;
|
||||
secondaryActionLink: unknown[] | null;
|
||||
secondaryActionQueryParams: Record<string, string | number>;
|
||||
}
|
||||
|
||||
export interface WordCloudTopicOccurrence {
|
||||
name: string;
|
||||
topicId: string;
|
||||
year: number | undefined;
|
||||
fieldId: string | undefined;
|
||||
fieldName: string | undefined;
|
||||
domainId: string | undefined;
|
||||
domainName: string | undefined;
|
||||
subfieldId: string | undefined;
|
||||
subfieldName: string | undefined;
|
||||
secondaryActionQueryParams: Record<string, string | number | number[]>;
|
||||
}
|
||||
|
||||
export interface WordCloudWord {
|
||||
@@ -49,67 +45,46 @@ const displayedWordLimit = 30;
|
||||
const minimumFontSize = 12;
|
||||
const maximumFontSize = 32;
|
||||
|
||||
interface AggregatedTopic {
|
||||
name: string;
|
||||
count: number;
|
||||
legendTopic: TopicLegendTopic;
|
||||
}
|
||||
|
||||
export function buildResearchWordcloud(
|
||||
occurrences: WordCloudTopicOccurrence[],
|
||||
elements: readonly TopicTimelineElement[],
|
||||
startYear: number | undefined,
|
||||
endYear: number | undefined,
|
||||
): ResearchWordcloud {
|
||||
const counts = new Map<string, number>();
|
||||
const legendTopicsByName = new Map<string, TopicLegendTopic>();
|
||||
const yearsInRange = elements.filter((element) =>
|
||||
isWithinYearRange(element.year, startYear, endYear),
|
||||
);
|
||||
|
||||
for (const occurrence of occurrences) {
|
||||
if (!isWithinYearRange(occurrence.year, startYear, endYear)) {
|
||||
continue;
|
||||
}
|
||||
const aggregated = aggregateTopics(yearsInRange);
|
||||
|
||||
counts.set(occurrence.name, (counts.get(occurrence.name) ?? 0) + 1);
|
||||
|
||||
if (!legendTopicsByName.has(occurrence.name)) {
|
||||
legendTopicsByName.set(occurrence.name, {
|
||||
id: occurrence.topicId,
|
||||
name: occurrence.name,
|
||||
field_id: occurrence.fieldId,
|
||||
field_name: occurrence.fieldName,
|
||||
domain_id: occurrence.domainId,
|
||||
domain_name: occurrence.domainName,
|
||||
subfield_id: occurrence.subfieldId,
|
||||
subfield_name: occurrence.subfieldName,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (counts.size === 0) {
|
||||
if (aggregated.size === 0) {
|
||||
return { words: [], legendTopics: [] };
|
||||
}
|
||||
|
||||
const values = Array.from(counts.values());
|
||||
const minimumValue = Math.min(...values);
|
||||
const maximumValue = Math.max(...values);
|
||||
const intensity = (value: number): number =>
|
||||
maximumValue === minimumValue
|
||||
? 1
|
||||
: (value - minimumValue) / (maximumValue - minimumValue);
|
||||
|
||||
const displayed = Array.from(counts.entries())
|
||||
.sort((left, right) => right[1] - left[1])
|
||||
const displayed = Array.from(aggregated.values())
|
||||
.sort(
|
||||
(left, right) =>
|
||||
right.count - left.count || left.name.localeCompare(right.name),
|
||||
)
|
||||
.slice(0, displayedWordLimit);
|
||||
|
||||
const legendTopics = displayed
|
||||
.map(([name]) => legendTopicsByName.get(name))
|
||||
.filter((topic): topic is TopicLegendTopic => Boolean(topic));
|
||||
const intensity = buildIntensityScale(displayed);
|
||||
|
||||
const words = displayed.map(([name, value]): WordCloudWord => {
|
||||
const legendTopic = legendTopicsByName.get(name);
|
||||
const scale = intensity(value);
|
||||
const words = displayed.map((topic): WordCloudWord => {
|
||||
const legendTopic = topic.legendTopic;
|
||||
const scale = intensity(topic.count);
|
||||
|
||||
return {
|
||||
name,
|
||||
topicId: legendTopic?.id ?? '',
|
||||
rawTopicId: stripOpenAlexId(legendTopic?.id),
|
||||
fieldLegendId: legendTopic ? getTopicLegendFieldId(legendTopic) : '',
|
||||
subfieldLegendId: legendTopic
|
||||
? getTopicLegendSubfieldId(legendTopic)
|
||||
: '',
|
||||
name: topic.name,
|
||||
topicId: legendTopic.id ?? '',
|
||||
rawTopicId: stripOpenAlexId(legendTopic.id),
|
||||
fieldLegendId: getTopicLegendFieldId(legendTopic),
|
||||
subfieldLegendId: getTopicLegendSubfieldId(legendTopic),
|
||||
color: topicHierarchyColor(legendTopic),
|
||||
fontSize: Math.round(
|
||||
minimumFontSize + scale * (maximumFontSize - minimumFontSize),
|
||||
@@ -118,7 +93,72 @@ export function buildResearchWordcloud(
|
||||
};
|
||||
});
|
||||
|
||||
return { words: centreWords(words), legendTopics };
|
||||
return {
|
||||
words: centreWords(words),
|
||||
legendTopics: displayed.map((topic) => topic.legendTopic),
|
||||
};
|
||||
}
|
||||
|
||||
function aggregateTopics(
|
||||
elements: readonly TopicTimelineElement[],
|
||||
): Map<string, AggregatedTopic> {
|
||||
const aggregated = new Map<string, AggregatedTopic>();
|
||||
|
||||
for (const element of elements) {
|
||||
for (const topic of element.primary_topics ?? []) {
|
||||
if (!topic.name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const key = topic.id ?? topic.name;
|
||||
const existing = aggregated.get(key);
|
||||
|
||||
if (existing) {
|
||||
existing.count += topic.count;
|
||||
continue;
|
||||
}
|
||||
|
||||
aggregated.set(key, {
|
||||
name: topic.name,
|
||||
count: topic.count,
|
||||
legendTopic: toLegendTopic(topic),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return aggregated;
|
||||
}
|
||||
|
||||
function buildIntensityScale(
|
||||
topics: readonly AggregatedTopic[],
|
||||
): (count: number) => number {
|
||||
const weights = topics.map((topic) => Math.sqrt(Math.max(topic.count, 0)));
|
||||
const minimumWeight = Math.min(...weights);
|
||||
const maximumWeight = Math.max(...weights);
|
||||
|
||||
if (maximumWeight === minimumWeight) {
|
||||
return () => 0.5;
|
||||
}
|
||||
|
||||
return (count) =>
|
||||
(Math.sqrt(Math.max(count, 0)) - minimumWeight) /
|
||||
(maximumWeight - minimumWeight);
|
||||
}
|
||||
|
||||
function toLegendTopic(topic: TopicTimelineTopic): TopicLegendTopic {
|
||||
return {
|
||||
id: topic.id,
|
||||
name: topic.name,
|
||||
field_id: topic.field_id,
|
||||
field_name: topic.field_name,
|
||||
field_description: topic.field_description,
|
||||
domain_id: topic.domain_id,
|
||||
domain_name: topic.domain_name,
|
||||
domain_description: topic.domain_description,
|
||||
subfield_id: topic.subfield_id,
|
||||
subfield_name: topic.subfield_name,
|
||||
subfield_description: topic.subfield_description,
|
||||
};
|
||||
}
|
||||
|
||||
function isWithinYearRange(
|
||||
@@ -184,6 +224,11 @@ export class ResearchWordcloudComponent {
|
||||
this.rebuildTooltipInputs();
|
||||
}
|
||||
|
||||
@Input() set selectedYears(value: number[]) {
|
||||
this._selectedYears = normalizeSelectedYears(value);
|
||||
this.rebuildTooltipInputs();
|
||||
}
|
||||
|
||||
@Input() loading = false;
|
||||
@Input() loadFailed = false;
|
||||
@Input() activeFieldIds: ReadonlySet<string> = new Set();
|
||||
@@ -194,6 +239,7 @@ export class ResearchWordcloudComponent {
|
||||
private _words: WordCloudWord[] = [];
|
||||
private _personPublicationsLink: unknown[] | null = null;
|
||||
private _personName = '';
|
||||
private _selectedYears: number[] = [];
|
||||
private tooltipInputsByTopic = new Map<string, WordTooltipInputs>();
|
||||
|
||||
selectWord(word: WordCloudWord): void {
|
||||
@@ -217,15 +263,23 @@ export class ResearchWordcloudComponent {
|
||||
}
|
||||
|
||||
wordAriaLabel(word: WordCloudWord): string {
|
||||
return `${this.publicationsLabel()} zum Thema ${word.name}${this.yearRangeSuffix()}`;
|
||||
}
|
||||
|
||||
private publicationsLabel(): string {
|
||||
return this._personName
|
||||
? `Publikationen von ${this._personName} zum Thema ${word.name}`
|
||||
: `Publikationen dieser Person zum Thema ${word.name}`;
|
||||
? `Publikationen von ${this._personName}`
|
||||
: 'Publikationen dieser Person';
|
||||
}
|
||||
|
||||
private yearRangeSuffix(): string {
|
||||
return this._selectedYears.length > 0
|
||||
? ` ${formatYearRange(this._selectedYears)}`
|
||||
: '';
|
||||
}
|
||||
|
||||
private rebuildTooltipInputs(): void {
|
||||
const label = this._personName
|
||||
? `Publikationen von ${this._personName}`
|
||||
: 'Publikationen dieser Person';
|
||||
const label = `${this.publicationsLabel()}${this.yearRangeSuffix()}`;
|
||||
const link = this._personPublicationsLink;
|
||||
|
||||
this.tooltipInputsByTopic = new Map(
|
||||
@@ -239,6 +293,9 @@ export class ResearchWordcloudComponent {
|
||||
secondaryActionLink: link,
|
||||
secondaryActionQueryParams: {
|
||||
[workQueryParamKeys.page]: 0,
|
||||
...(this._selectedYears.length > 0
|
||||
? { [workQueryParamKeys.years]: this._selectedYears }
|
||||
: {}),
|
||||
[workQueryParamKeys.topicId]: word.topicId,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
[loadFailed]="wordCloudLoadFailed"
|
||||
[activeFieldIds]="activeLegendFieldIds"
|
||||
[activeSubfieldIds]="activeLegendSubfieldIds"
|
||||
[selectedYears]="wordCloudYears"
|
||||
[personName]="personName"
|
||||
[personPublicationsLink]="personPublicationsLink"
|
||||
(wordSelect)="onWordClick($event)" />
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
import {
|
||||
buildResearchWordcloud,
|
||||
ResearchWordcloudComponent,
|
||||
WordCloudTopicOccurrence,
|
||||
WordCloudWord,
|
||||
} from './components/research-wordcloud/research-wordcloud.component';
|
||||
import { workQueryParamKeys } from '../../resolvers/work-page.resolver';
|
||||
@@ -40,7 +39,7 @@ export class PersonOverviewComponent implements OnInit {
|
||||
'timeline_legend_visible';
|
||||
private static readonly timelineLegendExpandedQueryParam =
|
||||
'timeline_legend_expanded';
|
||||
private static readonly timelineTopicCountLimit = 4;
|
||||
private static readonly timelineTopicCountLimit = 20;
|
||||
private static readonly initialTimelineTargetPublications = 250;
|
||||
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
@@ -66,6 +65,7 @@ export class PersonOverviewComponent implements OnInit {
|
||||
|
||||
wordCloudWords: WordCloudWord[] = [];
|
||||
wordCloudLegendTopics: TopicLegendTopic[] = [];
|
||||
wordCloudYears: number[] = [];
|
||||
loadingWordCloud = false;
|
||||
wordCloudLoadFailed = false;
|
||||
activeLegendFieldIds: ReadonlySet<string> = new Set();
|
||||
@@ -73,8 +73,6 @@ export class PersonOverviewComponent implements OnInit {
|
||||
personName = '';
|
||||
personPublicationsLink: unknown[] | null = null;
|
||||
|
||||
private rawTopicOccurrences: WordCloudTopicOccurrence[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
combineLatest(this.route.pathFromRoot.map((route) => route.paramMap))
|
||||
.pipe(
|
||||
@@ -88,7 +86,6 @@ export class PersonOverviewComponent implements OnInit {
|
||||
? ['/person', authorId, 'publications']
|
||||
: null;
|
||||
this.loadTopicTimeline(authorId);
|
||||
this.loadWordCloud(authorId);
|
||||
});
|
||||
|
||||
this.loadPersonName();
|
||||
@@ -99,12 +96,24 @@ export class PersonOverviewComponent implements OnInit {
|
||||
this.timelineViewMode = this.parseTimelineViewMode(
|
||||
queryParams.get(PersonOverviewComponent.timelineViewQueryParam),
|
||||
);
|
||||
this.timelineStartYear = this.parseOptionalYear(
|
||||
|
||||
const startYear = this.parseOptionalYear(
|
||||
queryParams.get(PersonOverviewComponent.timelineStartYearQueryParam),
|
||||
);
|
||||
this.timelineEndYear = this.parseOptionalYear(
|
||||
const endYear = this.parseOptionalYear(
|
||||
queryParams.get(PersonOverviewComponent.timelineEndYearQueryParam),
|
||||
);
|
||||
const yearRangeChanged =
|
||||
startYear !== this.timelineStartYear ||
|
||||
endYear !== this.timelineEndYear;
|
||||
|
||||
this.timelineStartYear = startYear;
|
||||
this.timelineEndYear = endYear;
|
||||
|
||||
if (yearRangeChanged) {
|
||||
this.rebuildWordCloud();
|
||||
}
|
||||
|
||||
this.timelineLegendVisible = this.parseBooleanQueryParam(
|
||||
queryParams.get(
|
||||
PersonOverviewComponent.timelineLegendVisibleQueryParam,
|
||||
@@ -219,6 +228,9 @@ export class PersonOverviewComponent implements OnInit {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
[workQueryParamKeys.page]: 0,
|
||||
...(this.wordCloudYears.length > 0
|
||||
? { [workQueryParamKeys.years]: this.wordCloudYears }
|
||||
: {}),
|
||||
[workQueryParamKeys.topicId]: word.topicId,
|
||||
},
|
||||
});
|
||||
@@ -246,9 +258,11 @@ export class PersonOverviewComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
this.topicTimelineElements = [];
|
||||
this.setTimelineElements([]);
|
||||
this.loadingTimeline = true;
|
||||
this.loadingWordCloud = true;
|
||||
this.timelineLoadFailed = false;
|
||||
this.wordCloudLoadFailed = false;
|
||||
this.timelineCanLoadEarlierYears = false;
|
||||
this.timelineLoadingEarlierYears = false;
|
||||
this.timelineEarlierYearsLoadFailed = false;
|
||||
@@ -269,9 +283,11 @@ export class PersonOverviewComponent implements OnInit {
|
||||
|
||||
const timelineElements = this.mapTimelineElements(response.elements);
|
||||
|
||||
this.topicTimelineElements = timelineElements;
|
||||
this.setTimelineElements(timelineElements);
|
||||
this.loadingTimeline = false;
|
||||
this.loadingWordCloud = false;
|
||||
this.timelineLoadFailed = false;
|
||||
this.wordCloudLoadFailed = false;
|
||||
this.timelineCanLoadEarlierYears =
|
||||
response.is_limited ??
|
||||
this.isLikelyLimitedTimeline(timelineElements);
|
||||
@@ -282,9 +298,11 @@ export class PersonOverviewComponent implements OnInit {
|
||||
}
|
||||
|
||||
console.error('Topic timeline could not be loaded.', error);
|
||||
this.topicTimelineElements = [];
|
||||
this.setTimelineElements([]);
|
||||
this.loadingTimeline = false;
|
||||
this.loadingWordCloud = false;
|
||||
this.timelineLoadFailed = true;
|
||||
this.wordCloudLoadFailed = true;
|
||||
this.timelineCanLoadEarlierYears = false;
|
||||
this.timelineLoadingEarlierYears = false;
|
||||
this.timelineEarlierYearsLoadFailed = false;
|
||||
@@ -316,9 +334,11 @@ export class PersonOverviewComponent implements OnInit {
|
||||
response.elements,
|
||||
);
|
||||
|
||||
this.topicTimelineElements = this.mergeTimelineElements(
|
||||
this.topicTimelineElements,
|
||||
completeTimelineElements,
|
||||
this.setTimelineElements(
|
||||
this.mergeTimelineElements(
|
||||
this.topicTimelineElements,
|
||||
completeTimelineElements,
|
||||
),
|
||||
);
|
||||
this.timelineCanLoadEarlierYears = false;
|
||||
this.timelineLoadingEarlierYears = false;
|
||||
@@ -338,9 +358,11 @@ export class PersonOverviewComponent implements OnInit {
|
||||
}
|
||||
|
||||
private resetTimelineState(): void {
|
||||
this.topicTimelineElements = [];
|
||||
this.setTimelineElements([]);
|
||||
this.loadingTimeline = false;
|
||||
this.loadingWordCloud = false;
|
||||
this.timelineLoadFailed = false;
|
||||
this.wordCloudLoadFailed = false;
|
||||
this.timelineCanLoadEarlierYears = false;
|
||||
this.timelineLoadingEarlierYears = false;
|
||||
this.timelineEarlierYearsLoadFailed = false;
|
||||
@@ -365,69 +387,37 @@ export class PersonOverviewComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private loadWordCloud(authorId: string): void {
|
||||
if (!authorId || authorId === '0') {
|
||||
this.wordCloudWords = [];
|
||||
this.wordCloudLegendTopics = [];
|
||||
this.wordCloudLoadFailed = false;
|
||||
this.loadingWordCloud = false;
|
||||
this.rawTopicOccurrences = [];
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadingWordCloud = true;
|
||||
this.wordCloudLoadFailed = false;
|
||||
this.wordCloudWords = [];
|
||||
this.wordCloudLegendTopics = [];
|
||||
|
||||
this.worksService
|
||||
.getAuthorWorks(authorId, 1, 100)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (page) => {
|
||||
this.rawTopicOccurrences = [];
|
||||
page.elements?.forEach((work) => {
|
||||
const year = work.publication_year ?? undefined;
|
||||
work.topics?.forEach((topic) => {
|
||||
if (topic.display_name && topic.id) {
|
||||
this.rawTopicOccurrences.push({
|
||||
name: topic.display_name,
|
||||
topicId: topic.id,
|
||||
year,
|
||||
fieldId: topic.field?.id ?? undefined,
|
||||
fieldName: topic.field?.display_name ?? undefined,
|
||||
domainId: topic.domain?.id ?? undefined,
|
||||
domainName: topic.domain?.display_name ?? undefined,
|
||||
subfieldId: topic.subfield?.id ?? undefined,
|
||||
subfieldName: topic.subfield?.display_name ?? undefined,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.loadingWordCloud = false;
|
||||
|
||||
setTimeout(() => this.rebuildWordCloud());
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Word cloud could not be loaded.', error);
|
||||
this.loadingWordCloud = false;
|
||||
this.rawTopicOccurrences = [];
|
||||
this.wordCloudLegendTopics = [];
|
||||
this.wordCloudLoadFailed = true;
|
||||
},
|
||||
});
|
||||
private setTimelineElements(elements: TopicTimelineElement[]): void {
|
||||
this.topicTimelineElements = elements;
|
||||
this.rebuildWordCloud();
|
||||
}
|
||||
|
||||
private rebuildWordCloud(): void {
|
||||
const wordCloud = buildResearchWordcloud(
|
||||
this.rawTopicOccurrences,
|
||||
this.topicTimelineElements,
|
||||
this.timelineStartYear,
|
||||
this.timelineEndYear,
|
||||
);
|
||||
|
||||
this.wordCloudWords = wordCloud.words;
|
||||
this.wordCloudLegendTopics = wordCloud.legendTopics;
|
||||
this.wordCloudYears = this.getSelectedTimelineYears();
|
||||
}
|
||||
|
||||
private getSelectedTimelineYears(): number[] {
|
||||
const yearsInRange = this.topicTimelineElements
|
||||
.map((element) => element.year)
|
||||
.filter(
|
||||
(year) =>
|
||||
(this.timelineStartYear === undefined ||
|
||||
year >= this.timelineStartYear) &&
|
||||
(this.timelineEndYear === undefined || year <= this.timelineEndYear),
|
||||
)
|
||||
.sort((left, right) => left - right);
|
||||
|
||||
return yearsInRange.length === this.topicTimelineElements.length
|
||||
? []
|
||||
: yearsInRange;
|
||||
}
|
||||
|
||||
private mapTimelineElements(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export function normalizeSelectedYears(years: readonly number[]): number[] {
|
||||
return Array.from(new Set(years))
|
||||
.filter((year) => Number.isFinite(year))
|
||||
.sort((left, right) => left - right);
|
||||
}
|
||||
|
||||
export function formatYearRange(years: readonly number[]): string {
|
||||
const firstYear = years[0];
|
||||
const lastYear = years[years.length - 1];
|
||||
|
||||
return firstYear === lastYear
|
||||
? `(${firstYear})`
|
||||
: `(${firstYear}–${lastYear})`;
|
||||
}
|
||||
Reference in New Issue
Block a user