Skip to content

Commit

Permalink
Set things up for DCAT US profile
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 2, 2024
1 parent 418afa5 commit ebadc16
Show file tree
Hide file tree
Showing 6 changed files with 3,738 additions and 0 deletions.
1 change: 1 addition & 0 deletions ckanext/dcat/profiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
from .euro_dcat_ap import EuropeanDCATAPProfile
from .euro_dcat_ap_2 import EuropeanDCATAP2Profile
from .euro_dcat_ap_3 import EuropeanDCATAP3Profile
from .dcat_us_3 import DCATUS3Profile
from .euro_dcat_ap_scheming import EuropeanDCATAPSchemingProfile
from .schemaorg import SchemaOrgProfile
74 changes: 74 additions & 0 deletions ckanext/dcat/profiles/dcat_us_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from rdflib import Literal, BNode

from ckanext.dcat.profiles import (
DCAT,
XSD,
SKOS,
ADMS,
RDF,
)

from .euro_dcat_ap_2 import EuropeanDCATAP2Profile
from .euro_dcat_ap_scheming import EuropeanDCATAPSchemingProfile


class DCATUS3Profile(EuropeanDCATAP2Profile, EuropeanDCATAPSchemingProfile):
"""
An RDF profile based on the DCAT-US 3 for data portals in the US
"""

def parse_dataset(self, dataset_dict, dataset_ref):

# Call base method for common properties
dataset_dict = self._parse_dataset_base(dataset_dict, dataset_ref)

# DCAT AP v2 properties also applied to higher versions
dataset_dict = self._parse_dataset_v2(dataset_dict, dataset_ref)

# DCAT AP v2 scheming fields
dataset_dict = self._parse_dataset_v2_scheming(dataset_dict, dataset_ref)

return dataset_dict

def graph_from_dataset(self, dataset_dict, dataset_ref):

# Call base method for common properties
self._graph_from_dataset_base(dataset_dict, dataset_ref)

# DCAT AP v2 properties also applied to higher versions
self._graph_from_dataset_v2(dataset_dict, dataset_ref)

# DCAT AP v2 scheming fields
self._graph_from_dataset_v2_scheming(dataset_dict, dataset_ref)

# DCAT AP v3 properties also applied to higher versions
self._graph_from_dataset_v3(dataset_dict, dataset_ref)

def graph_from_catalog(self, catalog_dict, catalog_ref):

self._graph_from_catalog_base(catalog_dict, catalog_ref)

def _graph_from_dataset_v3(self, dataset_dict, dataset_ref):

# byteSize decimal -> nonNegativeInteger
for subject, predicate, object in self.g.triples((None, DCAT.byteSize, None)):
if object and object.datatype == XSD.decimal:
self.g.remove((subject, predicate, object))

self.g.add(
(
subject,
predicate,
Literal(int(object), datatype=XSD.nonNegativeInteger),
)
)

# Other identifiers
value = self._get_dict_value(dataset_dict, "alternate_identifier")
if value:
items = self._read_list_value(value)
for item in items:
identifier = BNode()
self.g.add((dataset_ref, ADMS.identifier, identifier))
self.g.add((identifier, RDF.type, ADMS.Identifier))
self.g.add((identifier, SKOS.notation, Literal(item)))
Loading

0 comments on commit ebadc16

Please sign in to comment.