feat(webapp): add publications tab and table
aiis/pipeline/pr-dev This commit looks good

This commit is contained in:
2026-05-27 14:28:02 +02:00
16 changed files with 425 additions and 83 deletions
+4
View File
@@ -24,6 +24,10 @@ class Settings(BaseSettings):
openalex_works_search_index: str = 'openalex-works'
openalex_works_api_key: str = 'am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ=='
openalex_works_search_timeout_seconds: float = 30.0
llm_api_url: str = 'https://project.nes.uni-due.de/llm2/api/generate'
llm_api_token: str = 'c2d5e7ccf7a4760dd3d19bed2caed9d85ff7437400e0ea82a6d6f912ebc2f212'
llm_model: str = 'gemma4:e4b'
elasticsearch_url: str = 'https://project.nes.uni-due.de/elastic/openalex-authors/_search'
settings = Settings()
logger.info(f"Database URL: {settings.database_url}.")
+86
View File
@@ -15,8 +15,11 @@ from sqlalchemy import insert
from sqlalchemy import update
from sqlalchemy import func
import logging
import httpx
import json
from . import schema
from . import model
from . import config
logger = logging.getLogger(__name__)
@@ -55,3 +58,86 @@ def insert_element(db: Session, value: S) -> S:
db.flush()
db.refresh(value)
return value
def search_persons(author_id: Optional[str] = None, query: Optional[str] = None) -> model.PersonSearchResult:
headers = {
"Authorization": f"ApiKey {config.settings.elasticsearch_api_key}",
"Content-Type": "application/json"
}
if author_id:
query_field = "_id"
query_value = author_id
elif query:
query_field = "display_name"
query_value = query
else:
return "Either author_id or query must be provided"
payload = {
"query": {
"query_string": {
"default_field": query_field,
"query": query_value
}
}
}
with httpx.Client() as client:
response = client.post(config.settings.elasticsearch_url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
persons = []
for hit in data.get("hits", {}).get("hits", []):
source = hit.get("_source", {})
affiliations = []
for aff in source.get("affiliations", []):
institution = aff.get("institution", {})
affiliations.append(model.Affiliation(
institution=institution.get("display_name", ""),
country_code=institution.get("country_code", "")
))
topics = [t.get("display_name", "") for t in source.get("topics", [])]
persons.append(model.Person(
id=hit.get("_id", ""),
name=source.get("display_name", ""),
works_count=source.get("works_count", 0),
cited_by_count=source.get("cited_by_count", 0),
affiliations=affiliations,
topics=topics
))
return model.PersonSearchResult(persons=persons)
def generate_person_bio(author_id: str) -> str:
search_result = search_persons(author_id=author_id)
if not search_result.persons:
return "No person found."
if len(search_result.persons) > 1:
return "Multiple persons found, cannot generate bio."
person = search_result.persons[0]
person_json = json.dumps(person.model_dump())
system_prompt = "Erstelle eine Beschreibung der Person in 3-5 Sätzen. Gebe nur die Beschreibung zurück, ohne Einleitung oder Schluss."
user_prompt = f"Daten zur Person:\n{person_json}"
headers = {
"Authorization": f"Bearer {config.settings.llm_api_token}",
"Content-Type": "application/json"
}
payload = {
"model": config.settings.llm_model,
"prompt": f"{system_prompt}\n{user_prompt}",
"stream": False
}
with httpx.Client(timeout=30.0) as client:
response = client.post(config.settings.llm_api_url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
return data.get("response", "")
+19
View File
@@ -10,6 +10,7 @@ from pydantic import Field
from typing import List
from typing import TypeVar
from typing import Generic
from typing import Optional
T = TypeVar('T', bound=BaseModel)
@@ -34,3 +35,21 @@ class Page(BaseModel, Generic[T]):
class ItemPage(Page[Item]):
pass
class PersonBio(BaseModel):
bio: str = Field(description="The generated biography.")
class Affiliation(BaseModel):
institution: str = Field(description="Institution name.")
country_code: Optional[str] = Field(default=None, description="Country code.")
class Person(BaseModel):
id: str = Field(description="The person id.")
name: str = Field(description="The person name.")
works_count: int = Field(description="Number of works.")
cited_by_count: int = Field(description="Number of citations.")
affiliations: List[Affiliation] = Field(default=[], description="Affiliations.")
topics: List[str] = Field(default=[], description="Research topics.")
class PersonSearchResult(BaseModel):
persons: List[Person] = Field(default=[], description="List of found persons.")
+18
View File
@@ -114,3 +114,21 @@ def delete_item(id: Annotated[int, Path(description='The item id.', ge=0)],
return Response(status_code=HTTP_200_OK)
finally:
db.commit()
@app.get('/persons/search',
operation_id='searchPersons',
response_model=model.PersonSearchResult,
summary='Searches for persons by ID or name.',
tags=[ 'Persons' ])
def search_persons(author_id: Annotated[str, Query(description="OpenAlex author ID (e.g., A5093075883)")] = None,
query: Annotated[str, Query(description="Search query (e.g., Arman AND Arzani)")] = None):
return logic.search_persons(author_id, query)
@app.get('/persons/bio',
operation_id='generatePersonBio',
response_model=model.PersonBio,
summary='Generates a bio for a person by author ID.',
tags=[ 'Persons' ])
def generate_person_bio(author_id: Annotated[str, Query(description="OpenAlex author ID (e.g., A5093075883)")]):
bio = logic.generate_person_bio(author_id)
return model.PersonBio(bio=bio)
@@ -18,7 +18,7 @@
.container {
height: calc(100svh - 84px);
overflow: auto;
background-color: #f4f6fb;
background-color: #ffffff;
}
mat-toolbar.main {
@@ -43,18 +43,6 @@ mat-toolbar.main {
background: linear-gradient(135deg, #1a3a6e 0%, #2259a8 100%);
}
@media (prefers-color-scheme: dark) {
.container {
background-color: #1b1b1f;
}
mat-toolbar.main {
background: linear-gradient(135deg, #001849 0%, #002d6e 60%, #004290 100%);
}
.footer-container {
background: linear-gradient(135deg, #001849 0%, #002d6e 100%);
}
}
@media (max-width: 600px) {
.large {
display: none;
@@ -66,4 +54,3 @@ mat-toolbar.main {
height: calc(100svh - 76px);
}
}
@@ -50,20 +50,3 @@
.error {
color: #ba1a1a;
}
@media (prefers-color-scheme: dark) {
.container {
background: linear-gradient(160deg, #1b1b1f 0%, #252530 100%);
}
.form {
background: #303034;
box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.form h3 {
color: #a4c4ff;
}
.progress {
color: #c1c8dc;
}
}
@@ -5,9 +5,3 @@
background-color: mat.get-theme-color($light-theme, primary-container);
border-radius: 8px;
}
@media (prefers-color-scheme: dark) {
.active {
background-color: mat.get-theme-color($dark-theme, primary-container);
}
}
+7
View File
@@ -42,6 +42,13 @@ export const routes: Routes = [
(mod) => mod.PersonNetworkComponent,
),
},
{
path: 'publications',
loadComponent: () =>
import('./person-publications/person-publications.component').then(
(mod) => mod.PersonPublicationsComponent,
),
},
],
},
{
@@ -50,19 +50,6 @@ mat-paginator {
border-radius: 0 0 12px 12px;
}
@media (prefers-color-scheme: dark) {
.form-section {
background: #303034;
box-shadow: 0 1px 6px rgba(0,0,0,0.2);
}
.form-section h3 {
color: #a4c4ff;
}
::ng-deep .mat-mdc-header-row {
background-color: #1b1b22;
}
}
@media (max-width: 600px) {
.page {
padding: 16px;
@@ -0,0 +1,86 @@
<div class="page">
<h2>Publikationen</h2>
<div class="table-wrap">
@if (loading) {
<div class="loading">
<mat-spinner diameter="36"></mat-spinner>
</div>
}
<table mat-table [dataSource]="publications" class="mat-elevation-z2">
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef>Titel</th>
<td mat-cell *matCellDef="let publication">
<div class="title">{{ publication.title || 'Ohne Titel' }}</div>
</td>
</ng-container>
<ng-container matColumnDef="year">
<th mat-header-cell *matHeaderCellDef>Jahr</th>
<td mat-cell *matCellDef="let publication">{{ publication.publication_year || '-' }}</td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef>Typ</th>
<td mat-cell *matCellDef="let publication">
@if (publication.type) {
<mat-chip class="type-chip">{{ publication.type }}</mat-chip>
} @else {
<span class="empty-text">-</span>
}
</td>
</ng-container>
<ng-container matColumnDef="language">
<th mat-header-cell *matHeaderCellDef>Sprache</th>
<td mat-cell *matCellDef="let publication">{{ publication.language || '-' }}</td>
</ng-container>
<ng-container matColumnDef="citations">
<th mat-header-cell *matHeaderCellDef>Zitationen</th>
<td mat-cell *matCellDef="let publication">{{ publication.cited_by_count }}</td>
</ng-container>
<ng-container matColumnDef="topics">
<th mat-header-cell *matHeaderCellDef>Themen</th>
<td mat-cell *matCellDef="let publication">
<mat-chip-set aria-label="Themen">
@for (topic of publication.topics.slice(0, 3); track topic) {
<mat-chip>{{ topic }}</mat-chip>
} @empty {
<span class="empty-text">-</span>
}
</mat-chip-set>
</td>
</ng-container>
<ng-container matColumnDef="doi">
<th mat-header-cell *matHeaderCellDef>DOI</th>
<td mat-cell *matCellDef="let publication">
@if (doiUrl(publication.doi); as url) {
<a [href]="url" target="_blank" rel="noopener" aria-label="DOI öffnen">
<mat-icon>open_in_new</mat-icon>
</a>
} @else {
<span class="empty-text">-</span>
}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
@if (!loading && publications.length === 0) {
<div class="empty-state">Keine Publikationen gefunden.</div>
}
</div>
<mat-paginator
[length]="total"
[pageSize]="paginationService.selection"
[pageSizeOptions]="paginationService.options"
(page)="onPage($event)">
</mat-paginator>
</div>
@@ -0,0 +1,80 @@
.page {
padding: 28px 32px;
max-width: 1200px;
margin: 0 auto;
}
h2 {
margin: 0 0 20px;
font-weight: 600;
}
.table-wrap {
position: relative;
overflow-x: auto;
}
table {
width: 100%;
min-width: 920px;
border-radius: 8px;
overflow: hidden;
}
.title {
max-width: 420px;
line-height: 1.35;
font-weight: 600;
}
.loading {
position: absolute;
inset: 0;
z-index: 1;
display: grid;
place-items: center;
background: rgba(255, 255, 255, 0.65);
}
.empty-state {
padding: 28px;
text-align: center;
color: rgba(0, 0, 0, 0.6);
background: white;
}
.empty-text {
color: rgba(0, 0, 0, 0.54);
}
mat-chip-set {
display: flex;
max-width: 320px;
}
mat-chip,
.type-chip {
--mdc-chip-elevated-container-color: #e3f2fd;
--mdc-chip-label-text-color: #0d47a1;
--mdc-chip-outline-color: #bbdefb;
max-width: 140px;
}
a {
display: inline-flex;
color: inherit;
}
::ng-deep .mat-mdc-header-row {
background-color: #eaf0ff;
}
mat-paginator {
margin-top: 8px;
}
@media (max-width: 600px) {
.page {
padding: 16px;
}
}
@@ -0,0 +1,74 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatChipsModule } from '@angular/material/chips';
import { MatIconModule } from '@angular/material/icon';
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTableModule } from '@angular/material/table';
import { PaginationService } from '../services/pagination.service';
import { PublicationsService, WorkSummary } from '../services/publications.service';
import { createLoadError } from '../utils/errorHandler';
@Component({
selector: 'app-person-publications',
imports: [
MatChipsModule,
MatIconModule,
MatPaginatorModule,
MatProgressSpinnerModule,
MatSnackBarModule,
MatTableModule,
],
templateUrl: './person-publications.component.html',
styleUrl: './person-publications.component.scss',
})
export class PersonPublicationsComponent implements OnInit {
displayedColumns: string[] = ['title', 'year', 'type', 'language', 'citations', 'topics', 'doi'];
publications: WorkSummary[] = [];
total = 0;
loading = false;
authorId = '';
constructor(
private route: ActivatedRoute,
private publicationsService: PublicationsService,
public paginationService: PaginationService,
private snackBar: MatSnackBar,
) {}
ngOnInit(): void {
this.route.parent?.paramMap.subscribe((params) => {
this.authorId = params.get('id') ?? '';
this.load();
});
}
load(pageIndex = 0, pageSize = this.paginationService.selection): void {
if (!this.authorId) return;
this.loading = true;
this.publicationsService.getAuthorWorks(this.authorId, pageIndex + 1, pageSize).subscribe({
next: (page) => {
this.publications = page.elements;
this.total = page.total;
this.loading = false;
},
error: (error) => {
this.loading = false;
createLoadError(this.snackBar, () => this.load(pageIndex, pageSize), 'Publikationen konnten nicht geladen werden')(error);
},
});
}
onPage(event: PageEvent): void {
this.paginationService.selection = event.pageSize;
this.load(event.pageIndex, event.pageSize);
}
doiUrl(doi: string | null): string | null {
if (!doi) return null;
return doi.startsWith('http') ? doi : `https://doi.org/${doi}`;
}
}
+4 -6
View File
@@ -1,18 +1,16 @@
<p>person works!</p>
<nav mat-tab-nav-bar [tabPanel]="tabPanel">
@for (link of links; track $index) {
@for (link of links; track link.path) {
<a
mat-tab-link
[routerLink]="link.path"
routerLinkActive
#rla="routerLinkActive"
[active]="rla.isActive"
[disabled]="link.disabled"
>
{{ link.label }}
</a>
}
</nav>
<mat-tab-nav-panel #tabPanel></mat-tab-nav-panel>
<router-outlet></router-outlet>
<mat-tab-nav-panel #tabPanel>
<router-outlet></router-outlet>
</mat-tab-nav-panel>
+1 -1
View File
@@ -12,7 +12,7 @@ export class PersonComponent {
links = [
{ label: 'Übersicht', path: 'overview', disabled: false },
{ label: 'Projekte', path: 'projects', disabled: true },
{ label: 'Publikationen', path: 'publications', disabled: true },
{ label: 'Publikationen', path: 'publications', disabled: false },
{ label: 'Netzwerk', path: 'network', disabled: false },
{ label: 'Gründungen', path: 'foundings', disabled: true },
];
@@ -0,0 +1,43 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
export interface WorkSummary {
doi: string | null;
title: string | null;
type: string | null;
language: string | null;
publication_year: number | null;
cited_by_count: number;
topics: string[];
}
export interface WorkPage {
elements: WorkSummary[];
page: number;
total: number;
size: number;
}
@Injectable({
providedIn: 'root',
})
export class PublicationsService {
private readonly basePath = '/inse-service';
constructor(private http: HttpClient) {}
getAuthorWorks(
authorId: string,
page: number = 1,
size: number = 10,
): Observable<WorkPage> {
const params = new HttpParams()
.set('page', page.toString())
.set('size', size.toString());
return this.http.get<WorkPage>(
`${this.basePath}/authors/${authorId}/works`,
{ params },
);
}
}
+2 -26
View File
@@ -60,12 +60,14 @@
html {
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
height: 100%;
background: #ffffff;
@include mat.all-component-themes(m3.$light-theme);
@include mat.typography-hierarchy(m3.$light-theme);
}
body {
height: 100%;
margin: 0;
background: #ffffff;
}
@@ -90,33 +92,7 @@ body {
}
@media (prefers-color-scheme: dark) {
html {
@include mat.all-component-colors(m3.$dark-theme);
}
.primary-button {
@include mat.button-color(m3.$dark-theme, $color-variant: primary);
}
.secondary-button {
@include mat.button-color(m3.$dark-theme, $color-variant: secondary);
}
.tertiary-button {
@include mat.button-color(m3.$dark-theme, $color-variant: tertiary);
}
.primary-icon {
@include mat.icon-color(m3.$dark-theme, $color-variant: primary);
}
.secondary-icon {
@include mat.icon-color(m3.$dark-theme, $color-variant: secondary);
}
.tertiary-icon {
@include mat.icon-color(m3.$dark-theme, $color-variant: tertiary);
}
}
.menu button {
--mat-icon-button-disabled-icon-color: rgba(255,255,255,0.35);
--mat-icon-button-icon-color: #ffffff;
}