added default Country value to initial resolver call, added TrendMetadataResolver call in news to avoid missmatches
This commit is contained in:
@@ -198,20 +198,23 @@ class TrendMetadataResolver:
|
||||
for t in topic_names:
|
||||
t_clean = clean_inst_id(t)
|
||||
t_canonical = f"https://openalex.org/{t_clean}" if t_clean.startswith("T") else t
|
||||
if (
|
||||
is_exact_id = (
|
||||
t == full_id
|
||||
or t == short_id
|
||||
or t == canonical_id
|
||||
or t_canonical == canonical_id
|
||||
or t_clean == short_id
|
||||
or t.lower() in d_name.lower()
|
||||
or d_name.lower() in t.lower()
|
||||
):
|
||||
)
|
||||
is_exact_name = t.strip().lower() == d_name.strip().lower()
|
||||
if is_exact_id or is_exact_name:
|
||||
topic_ids[t] = canonical_id
|
||||
topic_display_names[t] = d_name
|
||||
topic_display_names[canonical_id] = d_name
|
||||
topic_display_names[short_id] = d_name
|
||||
topic_display_names[full_id] = d_name
|
||||
elif t not in topic_display_names and (t.lower() in d_name.lower() or d_name.lower() in t.lower()):
|
||||
topic_ids[t] = canonical_id
|
||||
topic_display_names[t] = d_name
|
||||
except Exception as e:
|
||||
logger.warning("Failed to resolve topic IDs from ES: %s", e)
|
||||
return topic_ids, topic_display_names
|
||||
|
||||
@@ -1079,6 +1079,10 @@ class NewsTrendStrategy(TrendStrategy):
|
||||
|
||||
cc_news_enabled = self.include_cc_news and not fuzzy
|
||||
|
||||
meta = await TrendMetadataResolver.resolve_all(topics=topics)
|
||||
resolved_topic_ids = meta["resolved_topic_ids"]
|
||||
resolved_topic_names = meta["resolved_topic_names"]
|
||||
|
||||
accumulated_data = {
|
||||
f"{NEWS_ENTITY_PREFIX}{t}": {top: {yr: (0, 1) for yr in years_range} for top in topics}
|
||||
for t in topics
|
||||
@@ -1088,7 +1092,7 @@ class NewsTrendStrategy(TrendStrategy):
|
||||
f"{CC_NEWS_ENTITY_PREFIX}{t}": {top: {yr: (0, 1) for yr in years_range} for top in topics}
|
||||
for t in topics
|
||||
})
|
||||
|
||||
# Stop words are used to avoid match_phrase (get more partial results => tradeoff)
|
||||
STOP_WORDS = {"in", "and", "or", "und", "oder", "der", "die", "das", "von", "mit", "zu", "at", "by", "on", "for", "to", "a", "an", "the"}
|
||||
|
||||
def resolve_keyword_term(idx: int, t_name: str) -> str:
|
||||
@@ -1107,8 +1111,19 @@ class NewsTrendStrategy(TrendStrategy):
|
||||
async def fetch_news_ids_for_term(idx: int, t_name: str) -> list[str]:
|
||||
news_ids: Set[str] = set()
|
||||
if fuzzy:
|
||||
term = t_name
|
||||
es_query = {"match_phrase": {"topic_matches.topic_display_name": term}}
|
||||
canonical_id = resolved_topic_ids.get(t_name)
|
||||
if not canonical_id:
|
||||
clean_id = clean_inst_id(t_name)
|
||||
canonical_id = f"https://openalex.org/{clean_id}" if clean_id.startswith("T") else t_name
|
||||
es_query = {
|
||||
"bool": {
|
||||
"should": [
|
||||
{"term": {"topic_matches.topic_id": canonical_id}},
|
||||
{"term": {"topic_matches.topic_id.keyword": canonical_id}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
try:
|
||||
async for hit in elasticsearch.scan(
|
||||
index=ESIndex.AKTUELLES_OPENALEX_TOPICS.value,
|
||||
@@ -1281,12 +1296,24 @@ class NewsTrendStrategy(TrendStrategy):
|
||||
topic_data=topic_data_map,
|
||||
)
|
||||
|
||||
def get_display_name(t_name: str) -> str:
|
||||
clean = clean_inst_id(t_name)
|
||||
is_id = t_name.startswith("https://openalex.org/") or (clean.startswith("T") and clean[1:].isdigit())
|
||||
if is_id:
|
||||
canonical_id = resolved_topic_ids.get(t_name)
|
||||
return (
|
||||
resolved_topic_names.get(t_name)
|
||||
or (resolved_topic_names.get(canonical_id) if canonical_id else None)
|
||||
or t_name
|
||||
)
|
||||
return t_name
|
||||
|
||||
series_list: list[TrendSeries] = [
|
||||
build_series(f"{NEWS_ENTITY_PREFIX}{t_name}", t_name, t_name) for t_name in topics
|
||||
build_series(f"{NEWS_ENTITY_PREFIX}{t_name}", t_name, get_display_name(t_name)) for t_name in topics
|
||||
]
|
||||
if cc_news_enabled:
|
||||
series_list.extend(
|
||||
build_series(f"{CC_NEWS_ENTITY_PREFIX}{t_name}", t_name, f"{t_name} (CC-News)")
|
||||
build_series(f"{CC_NEWS_ENTITY_PREFIX}{t_name}", t_name, f"{get_display_name(t_name)} (CC-News)")
|
||||
for t_name in topics
|
||||
)
|
||||
|
||||
|
||||
+15
-11
@@ -200,12 +200,18 @@ export class UniTrendParentComponent implements OnInit {
|
||||
},
|
||||
});
|
||||
|
||||
readonly activeChartTopic = linkedSignal<string[], string>({
|
||||
source: () => this.selectedTrendTopics(),
|
||||
computation: (topics, previous) => {
|
||||
readonly activeChartTopic = linkedSignal<
|
||||
{ topics: string[]; raw: TrendResponse | null },
|
||||
string
|
||||
>({
|
||||
source: () => ({
|
||||
topics: this.selectedTrendTopics(),
|
||||
raw: this.rawTrendResponse(),
|
||||
}),
|
||||
computation: (src, previous) => {
|
||||
if (
|
||||
previous?.value &&
|
||||
topics.some(
|
||||
src.topics.some(
|
||||
(t) =>
|
||||
t.toLowerCase().trim() === previous.value.toLowerCase().trim() ||
|
||||
cleanEntityId(t) === cleanEntityId(previous.value),
|
||||
@@ -213,8 +219,8 @@ export class UniTrendParentComponent implements OnInit {
|
||||
) {
|
||||
return previous.value;
|
||||
}
|
||||
const valid = this.findFirstNonEmptyTopic(topics);
|
||||
return valid || (topics.length > 0 ? topics[0] : '');
|
||||
const valid = this.findFirstNonEmptyTopic(src.topics);
|
||||
return valid || (src.topics.length > 0 ? src.topics[0] : '');
|
||||
},
|
||||
});
|
||||
|
||||
@@ -452,7 +458,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
.reduce((sum, item) => sum + (item.raw || 0), 0);
|
||||
|
||||
return {
|
||||
name: topicName,
|
||||
name: this.getMappedTopic(topicName) || topicName,
|
||||
value: totalRaw,
|
||||
};
|
||||
});
|
||||
@@ -658,8 +664,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
}
|
||||
|
||||
isTopicEmpty(topic: string): boolean {
|
||||
const allSeries =
|
||||
this.trendResponse()?.series || this.rawTrendResponse()?.series || [];
|
||||
const allSeries = this.rawTrendResponse()?.series || [];
|
||||
if (allSeries.length === 0) return true;
|
||||
const targetLower = topic.toLowerCase().trim();
|
||||
const targetMappedLower = this.getMappedTopic(topic).toLowerCase().trim();
|
||||
@@ -688,8 +693,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
}
|
||||
|
||||
findFirstNonEmptyTopic(topics: string[]): string {
|
||||
const allSeries =
|
||||
this.trendResponse()?.series || this.rawTrendResponse()?.series || [];
|
||||
const allSeries = this.rawTrendResponse()?.series || [];
|
||||
if (!topics || topics.length === 0) return '';
|
||||
return findFirstNonEmptyTopic(
|
||||
topics,
|
||||
|
||||
@@ -119,7 +119,11 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
return { id: cleanId, name };
|
||||
});
|
||||
|
||||
if (parsedInstitutions.length === 0 && searchType !== 'authors') {
|
||||
if (
|
||||
parsedInstitutions.length === 0 &&
|
||||
searchType !== 'authors' &&
|
||||
searchType !== 'news'
|
||||
) {
|
||||
parsedInstitutions.push({ id: primaryInstId, name: primaryInstName });
|
||||
}
|
||||
|
||||
@@ -128,6 +132,13 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
|
||||
const parts = c.split('|');
|
||||
return { id: parts[0].toUpperCase(), name: parts[1] || parts[0] };
|
||||
});
|
||||
if (
|
||||
parsedCountries.length === 0 &&
|
||||
searchType !== 'authors' &&
|
||||
searchType !== 'news'
|
||||
) {
|
||||
parsedCountries.push({ id: 'DE', name: 'Deutschland' });
|
||||
}
|
||||
|
||||
const regionParams = params.getAll('regions');
|
||||
const parsedRegions: CompareItem[] = regionParams.map((r) => {
|
||||
|
||||
Reference in New Issue
Block a user