@@ -169,31 +169,73 @@ def _get_publisher_url_from_identifier(self, identifier):
169
169
170
170
def _publisher (self , subject , identifier ):
171
171
"""
172
- Returns a dict with details about a dct:publisher entity, a foaf:Agent
172
+ Returns a dict with details about a dct:publisher entity,
173
+ represented as a foaf:Agent.
173
174
174
- Both subject and predicate must be rdflib URIRef or BNode objects
175
+ Both `subject` and `predicate` must be rdflib URIRef or BNode objects.
176
+
177
+ Examples of supported RDF structures:
175
178
176
- Examples :
179
+ 1. Basic Organization Representation (Legacy) :
177
180
178
181
<dct:publisher>
179
182
<foaf:Organization rdf:about="http://orgs.vocab.org/some-org">
180
183
<foaf:name>Publishing Organization for dataset 1</foaf:name>
181
184
</foaf:Organization>
182
185
</dct:publisher>
183
186
187
+ Output:
184
188
{
185
189
'url': 'http://orgs.vocab.org/some-org',
186
190
'name': 'Publishing Organization for dataset 1',
187
191
}
188
192
189
- Returns keys for url, name with the values set to
190
- an empty string if they could not be found
193
+ 2. Multilingual Agent Representation:
194
+
195
+ <dct:publisher>
196
+ <foaf:Agent rdf:about="http://orgs.vocab.org/some-org">
197
+ <foaf:name xml:lang="de">Wirtschaftsamt</foaf:name>
198
+ <foaf:name xml:lang="it">Ufficio economico</foaf:name>
199
+ <foaf:name xml:lang="fr">Bureau des economiques</foaf:name>
200
+ <foaf:mbox rdf:resource="mailto:wirtschaftsamt@sh.ch"/>
201
+ <foaf:homepage rdf:resource="https://some-org.org/info"/>
202
+ </foaf:Agent>
203
+ </dct:publisher>
204
+
205
+ The `name` field resolves directly using `multilang=True`,
206
+ allowing for prioritized language selection.
207
+ The `url` field prioritizes the `foaf:homepage` property and falls back
208
+ to the `rdf:about` attribute of the Agent.
209
+
210
+ Returns:
211
+ A JSON-encoded dictionary with keys:
212
+ - `url`: The URL of the publisher (from `foaf:homepage` or `rdf:about`)
213
+ - `name`: The resolved multilingual name using the `multilang=True`
214
+
215
+ If no valid data is found, the values for `url` and `name` will default
216
+ to empty strings.
191
217
"""
192
218
publisher = {}
193
219
for agent in self .g .objects (subject , DCT .publisher ):
194
- publisher ['url' ] = (str (agent ) if isinstance (agent ,
195
- URIRef ) else '' )
196
- publisher_name = self ._object_value (agent , FOAF .name )
220
+ publisher ['url' ] = (
221
+ self ._object_value (agent , FOAF .homepage ) or
222
+ (str (agent ) if isinstance (agent , URIRef ) else '' )
223
+ )
224
+ # detect if the agent is a foaf:Agent or foaf:Organization
225
+ is_agent = (FOAF .Agent in self .g .objects (agent , RDF .type ))
226
+ is_organization = (
227
+ FOAF .Organization in self .g .objects (agent , RDF .type ))
228
+
229
+ if is_agent :
230
+ # handle multilingual name for foaf:Agent
231
+ publisher_name = self ._object_value (agent , FOAF .name ,
232
+ multilang = True )
233
+ elif is_organization :
234
+ # handle single name for foaf:Organization
235
+ publisher_name = self ._object_value (agent , FOAF .name )
236
+ else :
237
+ publisher_name = None
238
+
197
239
publisher_deprecated = self ._object_value (agent , RDFS .label )
198
240
if publisher_name :
199
241
publisher ['name' ] = publisher_name
@@ -1124,18 +1166,33 @@ def _accrual_periodicity_to_graph(self, dataset_ref, accrual_periodicity):
1124
1166
))
1125
1167
1126
1168
def _publisher_to_graph (self , dataset_ref , dataset_dict ):
1169
+ """ Supporting both FOAF.Agent (with multilingual names)
1170
+ and FOAF.Organization (with a single name)
1171
+ """
1127
1172
g = self .g
1128
1173
publisher_uri , publisher_name = \
1129
1174
dh .get_publisher_dict_from_dataset (
1130
1175
dataset_dict .get ('publisher' )
1131
1176
)
1132
- if publisher_uri :
1133
- publisher_ref = URIRef (publisher_uri )
1177
+
1178
+ # determine publisher structure FOAF.Agent or FOAF.Organization
1179
+ if isinstance (publisher_name , dict ):
1180
+ entity_type = FOAF .Agent
1181
+ publisher_ref = URIRef (publisher_uri ) if publisher_uri else BNode ()
1182
+
1183
+ g .add ((publisher_ref , RDF .type , entity_type ))
1184
+ for lang , name in publisher_name .items ():
1185
+ if name : # check if the name is not empty
1186
+ g .add ((publisher_ref , FOAF .name , Literal (name , lang = lang )))
1134
1187
else :
1135
- publisher_ref = BNode ()
1136
- g .add ((publisher_ref , RDF .type , FOAF .Organization ))
1137
- if publisher_name :
1138
- g .add ((publisher_ref , FOAF .name , Literal (publisher_name )))
1188
+ entity_type = FOAF .Organization
1189
+ publisher_ref = URIRef (publisher_uri ) if publisher_uri else BNode ()
1190
+
1191
+ g .add ((publisher_ref , RDF .type , entity_type ))
1192
+ if publisher_name :
1193
+ g .add ((publisher_ref , FOAF .name , Literal (publisher_name )))
1194
+
1195
+ # link the publisher to the dataset
1139
1196
g .add ((dataset_ref , DCT .publisher , publisher_ref ))
1140
1197
1141
1198
0 commit comments