Skip to content

Commit 13df76d

Browse files
committed
feat: Supporting both FOAF.Agent nad FOAF.Organization in export graph
1 parent 3192e85 commit 13df76d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

ckanext/dcatapchharvest/profiles.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,18 +1166,33 @@ def _accrual_periodicity_to_graph(self, dataset_ref, accrual_periodicity):
11661166
))
11671167

11681168
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+
"""
11691172
g = self.g
11701173
publisher_uri, publisher_name = \
11711174
dh.get_publisher_dict_from_dataset(
11721175
dataset_dict.get('publisher')
11731176
)
1174-
if publisher_uri:
1175-
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)))
11761187
else:
1177-
publisher_ref = BNode()
1178-
g.add((publisher_ref, RDF.type, FOAF.Organization))
1179-
if publisher_name:
1180-
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
11811196
g.add((dataset_ref, DCT.publisher, publisher_ref))
11821197

11831198

0 commit comments

Comments
 (0)