47def response(resp: "SXNG_Response") -> EngineResults:
48 res = EngineResults()
49 json_data = resp.json()
50
51 def field(k: str) -> str:
52 return str(record.get(k, ""))
53
54 for record in json_data["message"]["items"]:
55
56 if record["type"] == "component":
57
58
59 continue
60 title: str = ""
61 journal: str = ""
62
63 if record["type"] == "book-chapter":
64 title = record["container-title"][0]
65 if record["title"][0].lower().strip() != title.lower().strip():
66 title += f" ({record['title'][0]})"
67 else:
68 title = record["title"][0] if "title" in record else record.get("container-title", [None])[0]
69 journal = record.get("container-title", [None])[0] if "title" in record else ""
70
71 item = res.types.Paper(
72 title=title,
73 journal=journal,
74 content=field("abstract"),
75 doi=field("DOI"),
76 pages=field("page"),
77 publisher=field("publisher"),
78 tags=record.get("subject"),
79 type=field("type"),
80 url=field("URL"),
81 volume=field("volume"),
82 )
83 res.add(item)
84
85 if "resource" in record and "primary" in record["resource"] and "URL" in record["resource"]["primary"]:
86 item.url = record["resource"]["primary"]["URL"]
87
88 if "published" in record and "date-parts" in record["published"]:
89 item.publishedDate = datetime(*(record["published"]["date-parts"][0] + [1, 1][:3]))
90
91 item.authors = [a.get("given", "") + " " + a.get("family", "") for a in record.get("author", [])]
92 item.isbn = record.get("isbn") or [i["value"] for i in record.get("isbn-type", [])]
93
94
95
96
97 return res