Spaces:
Sleeping
Sleeping
| from typing import Any, Dict | |
| def parse_bibtex_entry_to_mendeley(entry: Dict[str, str]) -> Dict[str, Any]: | |
| """ | |
| Helper function untuk mengubah satu entry bibtexparser menjadi format JSON Mendeley. | |
| """ | |
| authors_list = [] | |
| if "author" in entry: | |
| authors = entry["author"].split(" and ") | |
| for name_str in authors: | |
| if "," in name_str: | |
| # Format: "Last, First" | |
| parts = name_str.split(",", 1) | |
| last_name = parts[0].strip() | |
| first_name = parts[1].strip() | |
| else: | |
| # Format: "First Last" | |
| parts = name_str.split() | |
| last_name = parts[-1] | |
| first_name = " ".join(parts[:-1]) | |
| authors_list.append({"first_name": first_name, "last_name": last_name}) | |
| # 2. Mapping Tipe Dokumen | |
| # Ini bisa diperluas sesuai kebutuhan | |
| type_map = { | |
| "article": "journal", | |
| "book": "book", | |
| "incollection": "book_section", | |
| "inbook": "book_section", | |
| "inproceedings": "conference_proceedings", | |
| "conference": "conference_proceedings", | |
| "phdthesis": "thesis", | |
| "mastersthesis": "thesis", | |
| } | |
| mendeley_type = type_map.get(entry.get("ENTRYTYPE", "generic").lower(), "generic") | |
| # 3. Identifiers | |
| identifiers = {} | |
| if entry.get("doi"): | |
| identifiers["doi"] = entry["doi"] | |
| if entry.get("issn"): | |
| identifiers["issn"] = entry["issn"] | |
| if entry.get("isbn"): | |
| identifiers["isbn"] = entry["isbn"] | |
| # 4. Merakit Payload Dokumen | |
| doc = { | |
| "type": mendeley_type, | |
| "title": entry.get("title"), | |
| "authors": authors_list if authors_list else None, # Kirim list jika ada | |
| "year": entry.get("year"), | |
| "source": entry.get("journal") or entry.get("booktitle"), # 'source' di Mendeley | |
| "volume": entry.get("volume"), | |
| "issue": entry.get("issue"), | |
| "pages": entry.get("pages"), | |
| "identifiers": identifiers if identifiers else None, # Kirim dict jika ada | |
| } | |
| # 5. Membersihkan field yang nilainya None agar tidak dikirim | |
| return {k: v for k, v in doc.items() if v is not None} | |