| import pandas as pd |
|
|
| def _build_docs_index(docs_df): |
| index = {} |
| rows = docs_df.to_dict(orient="records") if hasattr(docs_df, 'to_dict') else [] |
| for row in rows: |
| title = row.get("Título", "") |
| authors_raw = row.get("Autores", "") |
| year = str(row.get("Año", "")) |
| |
| if isinstance(authors_raw, list): |
| surnames = [a.split()[-1] for a in authors_raw[:3] if a] |
| elif isinstance(authors_raw, str) and authors_raw: |
| parts = [a.strip() for a in authors_raw.split(",")] |
| surnames = [p.split()[-1] for p in parts[:3] if p] |
| else: |
| surnames = [] |
| |
| print("Surnames:", surnames, "Year:", year) |
| for s in surnames: |
| key = f"{s.lower()}_{year}" |
| index[key] = title |
|
|
| return index |
|
|
| df = pd.DataFrame([ |
| {"Título": "Paper 1", "Autores": "Nguyen, T. P.", "Año": "2020"}, |
| {"Título": "Paper 2", "Autores": "Raj, A., Kumar, B.", "Año": "2021"} |
| ]) |
|
|
| print(_build_docs_index(df)) |
|
|