99from fastapi import FastAPI , HTTPException , Response
1010from fastapi .responses import HTMLResponse
1111from fastapi .staticfiles import StaticFiles
12- from app .mardi_item_helper import BASE_IRI
13- from fdo_schemas .publication import build_scholarly_article_payload
12+ from fdo_schemas .publication import build_scholarly_article_profile
1413from fdo_schemas .person import build_author_payload
1514
1615MW_API = "https://portal.mardi4nfdi.de/w/api.php"
17- from app .fdo_config import QID_TYPE_MAP , JSONLD_CONTEXT
16+ from app .fdo_config import QID_TYPE_MAP , JSONLD_CONTEXT , FDO_IRI , FDO_ACCESS_IRI , ENTITY_IRI
1817
1918app = FastAPI (
2019 title = "MaRDI FDO façade" ,
@@ -92,26 +91,47 @@ def to_fdo(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
9291
9392
9493def to_fdo_publication (qid : str , entity : Dict [str , Any ]) -> Dict [str , Any ]:
95- """Return a schema.org ScholarlyArticle-styled FDO payload.
9694
97- Args:
98- qid: Identifier of the publication.
99- entity: Raw entity JSON.
95+ fdo_id = f"{ FDO_IRI } { qid } "
96+ access_id = f"{ FDO_ACCESS_IRI } { qid } "
97+
98+ created = entity .get ("created" )
99+ modified = entity .get ("modified" )
100+ created_or_modified = created if created else modified if modified else ""
100101
101- Returns:
102- ``FDOResponse`` enriched with schema.org publication fields.
103- """
104102 return {
105- "@context" : JSONLD_CONTEXT ,
106- "@id" : BASE_IRI + qid ,
107- "@type" : "schema:ScholarlyArticle" ,
108- "kernel" : build_scholarly_article_payload (qid , entity ),
103+ "@context" : [
104+ "https://w3id.org/fdo/context/v1" ,
105+ {
106+ "schema" : "https://schema.org/" ,
107+ "prov" : "http://www.w3.org/ns/prov#" ,
108+ "fdo" : "https://w3id.org/fdo/vocabulary/"
109+ }
110+ ],
111+
112+ "@id" : fdo_id ,
113+ "@type" : "DigitalObject" ,
114+
115+ "kernel" : {
116+ "@id" : fdo_id ,
117+ "digitalObjectType" : "https://types.mardi4nfdi.de/ScholarlyArticle/v1" ,
118+ "created" : created_or_modified ,
119+ "modified" : modified or "" ,
120+ "access" : [{"@id" : access_id }]
121+ },
122+
123+ "profile" : build_scholarly_article_profile (qid , entity ),
124+
109125 "access" : {
110- "accessURL" : f"{ BASE_IRI } { qid } " ,
111- "mediaType" : "application/ld+json" ,
126+ "@id" : access_id ,
127+ "accessURL" : f"{ fdo_id } ?format=jsonld" ,
128+ "mediaType" : "application/ld+json"
112129 },
113- "prov:generatedAtTime" : entity .get ("modified" , "" ),
114- "prov:wasAttributedTo" : "MaRDI Knowledge Graph" ,
130+
131+ "provenance" : {
132+ "prov:generatedAtTime" : modified or "" ,
133+ "prov:wasAttributedTo" : "MaRDI Knowledge Graph"
134+ }
115135 }
116136
117137
@@ -127,11 +147,11 @@ def to_fdo_author(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
127147 """
128148 return {
129149 "@context" : JSONLD_CONTEXT ,
130- "@id" : BASE_IRI + qid ,
150+ "@id" : ENTITY_IRI + qid ,
131151 "@type" : "schema:Person" ,
132152 "kernel" : build_author_payload (qid , entity ),
133153 "access" : {
134- "accessURL" : f"{ BASE_IRI } { qid } " ,
154+ "accessURL" : f"{ ENTITY_IRI } { qid } " ,
135155 "mediaType" : "application/ld+json" ,
136156 },
137157 "prov:generatedAtTime" : entity .get ("modified" , "" ),
@@ -154,15 +174,15 @@ def to_fdo_minimal(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
154174 entity_type = guess_type_from_claims (entity .get ("claims" , {}))
155175 return {
156176 "@context" : JSONLD_CONTEXT ,
157- "@id" : BASE_IRI + qid ,
177+ "@id" : ENTITY_IRI + qid ,
158178 "@type" : entity_type ,
159179 "kernel" : {
160180 "@type" : entity_type ,
161181 "name" : label ,
162182 "description" : description ,
163183 },
164184 "access" : {
165- "accessURL" : f"{ BASE_IRI } { qid } " ,
185+ "accessURL" : f"{ ENTITY_IRI } { qid } " ,
166186 "mediaType" : "application/vnd.mardi.entity+json" ,
167187 },
168188 "prov:generatedAtTime" : entity .get ("modified" , "" ),
0 commit comments