Skip to content

Commit a98f9dd

Browse files
committed
FDO-Json now delivers access info about PDFs
1 parent 71a3dee commit a98f9dd

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

app/mardi_fdo_server.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,47 +91,60 @@ def to_fdo(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
9191

9292

9393
def to_fdo_publication(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
94-
9594
fdo_id = f"{FDO_IRI}{qid}"
96-
access_id = f"{FDO_ACCESS_IRI}{qid}"
95+
access_json_id = f"{FDO_ACCESS_IRI}{qid}-jsonld"
96+
access_pdf_id = f"{FDO_ACCESS_IRI}{qid}-pdf"
9797

9898
created = entity.get("created")
9999
modified = entity.get("modified")
100100
created_or_modified = created if created else modified if modified else ""
101101

102+
profile, pdf_url = build_scholarly_article_profile(qid, entity)
103+
104+
access_list = [{"@id": access_json_id}]
105+
if pdf_url:
106+
access_list.append({"@id": access_pdf_id})
107+
108+
access_records = [
109+
{
110+
"@id": access_json_id,
111+
"accessURL": f"{fdo_id}?format=jsonld",
112+
"mediaType": "application/ld+json",
113+
}
114+
]
115+
if pdf_url:
116+
access_records.append(
117+
{
118+
"@id": access_pdf_id,
119+
"accessURL": pdf_url,
120+
"mediaType": "application/pdf",
121+
}
122+
)
123+
102124
return {
103125
"@context": [
104126
"https://w3id.org/fdo/context/v1",
105127
{
106128
"schema": "https://schema.org/",
107129
"prov": "http://www.w3.org/ns/prov#",
108-
"fdo": "https://w3id.org/fdo/vocabulary/"
109-
}
130+
"fdo": "https://w3id.org/fdo/vocabulary/",
131+
},
110132
],
111-
112133
"@id": fdo_id,
113134
"@type": "DigitalObject",
114-
115135
"kernel": {
116136
"@id": fdo_id,
117137
"digitalObjectType": "https://types.mardi4nfdi.de/ScholarlyArticle/v1",
118138
"created": created_or_modified,
119139
"modified": modified or "",
120-
"access": [{"@id": access_id}]
121-
},
122-
123-
"profile": build_scholarly_article_profile(qid, entity),
124-
125-
"access": {
126-
"@id": access_id,
127-
"accessURL": f"{fdo_id}?format=jsonld",
128-
"mediaType": "application/ld+json"
140+
"access": access_list,
129141
},
130-
142+
"profile": profile,
143+
"access": access_records,
131144
"provenance": {
132145
"prov:generatedAtTime": modified or "",
133-
"prov:wasAttributedTo": "MaRDI Knowledge Graph"
134-
}
146+
"prov:wasAttributedTo": "MaRDI Knowledge Graph",
147+
},
135148
}
136149

137150

fdo_schemas/publication.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414

1515

1616
def build_scholarly_article_profile(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
17+
claims = entity.get("claims", {})
18+
19+
arxiv_id = extract_string_claim(claims, "P21")
20+
pdf_url = f"https://arxiv.org/pdf/{arxiv_id}.pdf" if arxiv_id else None
1721

22+
# build the profile as before
1823
label = entity.get("labels", {}).get("en", {}).get("value", qid)
1924
description = entity.get("descriptions", {}).get("en", {}).get("value", "")
20-
claims = entity.get("claims", {})
21-
2225
author_ids = extract_item_ids(claims, "P16")
2326
citation_ids = extract_item_ids(claims, "P223")
2427
container_ids = extract_item_ids(claims, "P1433")
@@ -27,7 +30,6 @@ def build_scholarly_article_profile(qid: str, entity: Dict[str, Any]) -> Dict[st
2730
license_ids = extract_item_ids(claims, "P275")
2831
language_ids = extract_item_ids(claims, "P407")
2932
keyword_ids = extract_item_ids(claims, "1450")
30-
3133
publication_date = extract_time_claim(claims, "P28") or ""
3234
doi_value = extract_string_claim(claims, "P27") or ""
3335
page_range = extract_string_claim(claims, "P304")
@@ -40,8 +42,6 @@ def build_scholarly_article_profile(qid: str, entity: Dict[str, Any]) -> Dict[st
4042
profile = {
4143
"@context": "https://schema.org",
4244
"@type": "ScholarlyArticle",
43-
44-
# Schema.org identity stays in the Wikibase namespace
4545
"@id": f"{ENTITY_IRI}{qid}",
4646
"name": label,
4747
"headline": label,
@@ -66,7 +66,7 @@ def build_scholarly_article_profile(qid: str, entity: Dict[str, Any]) -> Dict[st
6666
"@type": "PropertyValue",
6767
"propertyID": "doi",
6868
"value": doi_value,
69-
"url": f"https://doi.org/{doi_value}"
69+
"url": f"https://doi.org/{doi_value}",
7070
}
7171
profile["sameAs"] = [f"https://doi.org/{doi_value}"]
7272

@@ -86,4 +86,14 @@ def build_scholarly_article_profile(qid: str, entity: Dict[str, Any]) -> Dict[st
8686
if citation_ids:
8787
profile["citation"] = schema_refs_from_ids(citation_ids)
8888

89-
return profile
89+
if pdf_url:
90+
profile["encoding"] = [
91+
{
92+
"@type": "MediaObject",
93+
"contentUrl": pdf_url,
94+
"encodingFormat": "application/pdf"
95+
}
96+
]
97+
98+
return profile, pdf_url
99+

0 commit comments

Comments
 (0)