update topic profile query and enhance data models with IDs
This commit is contained in:
@@ -499,21 +499,41 @@ def _topic_profile_query(
|
||||
# topic treemap
|
||||
"by_field": {
|
||||
"terms": {
|
||||
"field": "primary_topic.field.display_name.keyword",
|
||||
"field": "primary_topic.field.id",
|
||||
"size": 30,
|
||||
},
|
||||
"aggs": {
|
||||
"field_name": {
|
||||
"terms": {
|
||||
"field": "primary_topic.field.display_name.keyword",
|
||||
"size": 1,
|
||||
},
|
||||
},
|
||||
"by_subfield": {
|
||||
"terms": {
|
||||
"field": "primary_topic.subfield.display_name.keyword",
|
||||
"field": "primary_topic.subfield.id",
|
||||
"size": 30,
|
||||
},
|
||||
"aggs": {
|
||||
"subfield_name": {
|
||||
"terms": {
|
||||
"field": "primary_topic.subfield.display_name.keyword",
|
||||
"size": 1,
|
||||
},
|
||||
},
|
||||
"by_topic": {
|
||||
"terms": {
|
||||
"field": "primary_topic.display_name.keyword",
|
||||
"field": "primary_topic.id",
|
||||
"size": 30,
|
||||
},
|
||||
"aggs": {
|
||||
"topic_name": {
|
||||
"terms": {
|
||||
"field": "primary_topic.display_name.keyword",
|
||||
"size": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -583,15 +603,18 @@ async def topic_profile_for_authors(
|
||||
]
|
||||
field_tree = [
|
||||
FieldNode(
|
||||
name=field_bucket.get("key", ""),
|
||||
id=field_bucket.get("key", ""),
|
||||
name=_bucket_name(field_bucket, "field_name", field_bucket.get("key", "")),
|
||||
count=field_bucket.get("doc_count", 0),
|
||||
subfields=[
|
||||
SubfieldNode(
|
||||
name=subfield_bucket.get("key", ""),
|
||||
id=subfield_bucket.get("key", ""),
|
||||
name=_bucket_name(subfield_bucket, "subfield_name", subfield_bucket.get("key", "")),
|
||||
count=subfield_bucket.get("doc_count", 0),
|
||||
topics=[
|
||||
TopicNode(
|
||||
name=topic_bucket.get("key", ""),
|
||||
id=topic_bucket.get("key", ""),
|
||||
name=_bucket_name(topic_bucket, "topic_name", topic_bucket.get("key", "")),
|
||||
count=topic_bucket.get("doc_count", 0),
|
||||
)
|
||||
for topic_bucket in subfield_bucket.get("by_topic", {}).get("buckets", [])
|
||||
@@ -779,6 +802,14 @@ def _display_name_from_bucket(author_bucket: dict) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _bucket_name(bucket: dict, name_agg_key: str, fallback: str) -> str:
|
||||
"""Reads a display name out of a bucket's name sub-aggregation, falling back to its id."""
|
||||
name_buckets = bucket.get(name_agg_key, {}).get("buckets", [])
|
||||
if name_buckets and name_buckets[0].get("key"):
|
||||
return str(name_buckets[0]["key"])
|
||||
return fallback
|
||||
|
||||
|
||||
def _citations_from_bucket(author_bucket: dict) -> int:
|
||||
"""Reads the summed citations out of the reverse_nested sub-aggregation."""
|
||||
citations_value = (
|
||||
|
||||
@@ -289,11 +289,13 @@ class SubfieldShare(BaseModel):
|
||||
|
||||
|
||||
class TopicNode(BaseModel):
|
||||
id: str = Field(description="The OpenAlex ID of the primary topic.")
|
||||
name: str = Field(description="The primary-topic display name.")
|
||||
count: int = Field(description="Number of works whose primary topic is this topic.")
|
||||
|
||||
|
||||
class SubfieldNode(BaseModel):
|
||||
id: str = Field(description="The OpenAlex ID of the subfield.")
|
||||
name: str = Field(description="The subfield display name.")
|
||||
count: int = Field(description="Number of works whose primary topic belongs to this subfield.")
|
||||
topics: List[TopicNode] = Field(
|
||||
@@ -303,6 +305,7 @@ class SubfieldNode(BaseModel):
|
||||
|
||||
|
||||
class FieldNode(BaseModel):
|
||||
id: str = Field(description="The OpenAlex ID of the field.")
|
||||
name: str = Field(description="The field display name.")
|
||||
count: int = Field(description="Number of works whose primary topic belongs to this field.")
|
||||
subfields: List[SubfieldNode] = Field(
|
||||
|
||||
@@ -116,6 +116,16 @@ Content-Type: application/json
|
||||
"timespan": { "from": 2018, "to": 2025 }
|
||||
}
|
||||
|
||||
###
|
||||
POST http://localhost:8000/api/rank/topic-profile
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"author_ids": ["https://openalex.org/A504035360", "https://openalex.org/A5019137844"],
|
||||
"keywords": ["Augmented Reality Applications"],
|
||||
"operator": "or"
|
||||
}
|
||||
|
||||
###
|
||||
GET https://project.nes.uni-due.de/elastic/_aliases
|
||||
Authorization: ApiKey am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ==
|
||||
|
||||
Reference in New Issue
Block a user