Spaces:
Sleeping
Sleeping
File size: 2,206 Bytes
18d060d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 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}
|