Data catalog to RDF library¶
License¶
Apache License
Version 2.0, January 2004
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
Definitions.
“License” shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
“Licensor” shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
“Legal Entity” shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, “control” means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
“You” (or “Your”) shall mean an individual or Legal Entity exercising permissions granted by this License.
“Source” form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
“Object” form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
“Work” shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
“Derivative Works” shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
“Contribution” shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, “submitted” means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as “Not a Contribution.”
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a “NOTICE” text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets “[]” replaced with your own identifying information. (Don’t include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same “printed page” as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Reference¶
datacatalogtordf.resource¶
Resource module for mapping a sub-classes to rdf.
This module contains methods for mapping a sub-class objects to rdf according to the dcat-ap-no v.2 standard
Refer to sub-class for typical usage examples.
- class datacatalogtordf.resource.Resource¶
Bases:
ABC
An abstract class representing a dcat:Resource.
Ref: dcat:Resource.
- property access_rights: str¶
A link to information about who can access the resource or an indication of its security status.
- property conforms_to: List[str]¶
A list of links to established standards to which the described resource conforms.
- property contactpoint: Contact¶
Relevant contact information for the cataloged resource.
- Type
Contact
- Return type
Contact
- classmethod from_json(json)¶
Convert a JSON (dict).
- property has_policy: str¶
A link to an ODRL conformant policy expressing the rights associated with the resource.
- property is_referenced_by: List[Resource]¶
A list of related resources, such as a publication, that references, cites, or otherwise points to the cataloged resource.
- property landing_page: List[str]¶
A list of links to web pages that can be navigated to in a Web browser to gain access to the catalog, a dataset, its distributions and/or additional information.
- property modification_date: str¶
Most recent date on which the item was changed, updated or modified.
- property qualified_attributions: List[Dict]¶
List of links to an Agent having some form of responsibility for the resource.
- property qualified_relation: List[Relationship]¶
A list of links to a description of a relationship with another resource.
- Type
List[Relationship]
- Return type
- property resource_relation: List[str]¶
A list of links to resources with an unspecified relationship to the cataloged item.
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
- to_rdf(format='turtle', encoding='utf-8')¶
Maps the distribution to rdf.
- Available formats:
turtle (default)
xml
json-ld
- Parameters
- Return type
- Returns
a rdf serialization as a bytes literal according to format.
Example
>>> from datacatalogtordf import Catalog >>> >>> catalog = Catalog() >>> catalog.identifier = "http://example.com/catalogs/1" >>> catalog.title = {'en': 'Title of catalog'} >>> bool(catalog.to_rdf()) True
datacatalogtordf.relationship¶
Relationship module for mapping a relationship to rdf.
This module contains methods for mapping a relationship object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Relationship
>>>
>>> relationship = Relationship()
>>> relationship.identifier = "http://example.com/relations/1"
>>> relationship.title = {"en": "Title of relationship"}
>>>
>>> bool(relationship.to_rdf())
True
- class datacatalogtordf.relationship.Relationship(identifier=None)¶
Bases:
object
A class representing a dcat:Relationship.
Ref: dcat:Relationship
- classmethod from_json(json)¶
Convert a JSON (dict).
- Parameters
json (
Dict
) – A dict representing this class.- Returns
The object.
- Return type
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
datacatalogtordf.catalog¶
Catalog module for mapping a catalog to rdf.
This module contains methods for mapping a catalog object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Catalog, Dataset
>>>
>>> catalog = Catalog()
>>> catalog.identifier = "http://example.com/catalogs/1"
>>> catalog.title = {"en": "Title of catalog"}
>>>
>>> a_dataset = Dataset()
>>> a_dataset.identifier = "http://example.com/datasets/1"
>>> catalog.datasets.append(a_dataset)
>>>
>>> bool(catalog.to_rdf())
True
- class datacatalogtordf.catalog.Catalog(identifier=None)¶
Bases:
Dataset
A class representing a dcat:Catalog.
Ref: dcat:Catalog.
- property access_rights: str¶
A link to information about who can access the resource or an indication of its security status.
- property access_rights_comments: List[str]¶
Referanse til hjemmel (kilde for påstand) i offentlighetsloven, sikkerhetsloven, beskyttelsesinstruksen eller annet lovverk som ligger til grunn for vurdering av tilgangsnivå.
- property catalogrecords: List[CatalogRecord]¶
A list of records describing the registration of a single dataset or data service that is part of the catalog.
- Type
List[CatalogRecord]
- Return type
- property catalogs: List[Catalog]¶
A list of catalogs that are of interest in the context of this catalog.
- property conforms_to: List[str]¶
A list of links to established standards to which the described resource conforms.
- property contactpoint: Contact¶
Relevant contact information for the cataloged resource.
- Type
Contact
- Return type
Contact
- property distributions: List[Distribution]¶
A list of distributions of the dataset.
- Type
List[Distribution]
- Return type
- classmethod from_json(json)¶
Convert a JSON (dict).
- property has_policy: str¶
A link to an ODRL conformant policy expressing the rights associated with the resource.
- property in_series: DatasetSeries¶
A dataset series of which the dataset is part.
- Type
- Return type
- property is_referenced_by: List[Resource]¶
A list of related resources, such as a publication, that references, cites, or otherwise points to the cataloged resource.
- property landing_page: List[str]¶
A list of links to web pages that can be navigated to in a Web browser to gain access to the catalog, a dataset, its distributions and/or additional information.
- property modification_date: str¶
Most recent date on which the item was changed, updated or modified.
- property qualified_attributions: List[Dict]¶
List of links to an Agent having some form of responsibility for the resource.
- property qualified_relation: List[Relationship]¶
A list of links to a description of a relationship with another resource.
- Type
List[Relationship]
- Return type
- property resource_relation: List[str]¶
A list of links to resources with an unspecified relationship to the cataloged item.
- property services: List[DataService]¶
A list of dataservices of sites or end-points that is listed in the catalog.
- Type
List[DataService]
- Return type
- property spatial_resolution_in_meters: List[Decimal]¶
A list of minimum spatial separation resolvables in a dataset, measured in meters.
- property temporal: List[PeriodOfTime]¶
A list of temporal periods that the dataset covers.
- Type
List[PeriodOfTime]
- Return type
- property themes: List[str]¶
A list of links to knowledge organization system (KOS) used to classify catalog.
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
- to_rdf(format='turtle', encoding='utf-8', include_datasets=True, include_services=True)¶
Maps the catalog to rdf.
- Available formats:
turtle (default)
xml
json-ld
- Parameters
- Return type
- Returns
a rdf serialization as a bytes literal according to format.
datacatalogtordf.catalogrecord¶
CatalogRecord module for mapping a catalogrecord to rdf.
This module contains methods for mapping a catalogrecord object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import CatalogRecord
>>>
>>> catalogrecord = CatalogRecord()
>>> catalogrecord.identifier = "http://example.com/catalogrecords/1"
>>> catalogrecord.title = {"en": "Title of catalogrecord"}
>>>
>>> bool(catalogrecord.to_rdf())
True
- class datacatalogtordf.catalogrecord.CatalogRecord(identifier=None)¶
Bases:
object
A class representing a dcat:CatalogRecord.
Ref: https://www.w3.org/TR/vocab-dcat-2/#Class:Catalog_Record
- Parameters
identifier (URI) – the identifier of the dataset-series.
- classmethod from_json(json)¶
Convert a JSON (dict).
- Parameters
json (
Dict
) – A dict representing this class.- Returns
The object.
- Return type
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
datacatalogtordf.dataservice¶
DataService module for mapping a dataService to rdf.
This module contains methods for mapping a dataservice object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import DataService
>>>
>>> dataservice = DataService()
>>> dataservice.identifier = "http://example.com/dataservices/1"
>>> dataservice.title = {"en": "Title of dataservice"}
>>>
>>> bool(dataservice.to_rdf())
True
- class datacatalogtordf.dataservice.DataService(identifier=None)¶
Bases:
Resource
A class representing a dcat:DataService.
- Parameters
identifier (URI) – the identifier of the datasetservice.
Ref: dcat:DataService.
- property access_rights: str¶
A link to information about who can access the resource or an indication of its security status.
- property conforms_to: List[str]¶
A list of links to established standards to which the described resource conforms.
- property contactpoint: Contact¶
Relevant contact information for the cataloged resource.
- Type
Contact
- Return type
Contact
- property endpointDescription: str¶
A description of the services available via the end-points, including their operations, parameters etc.
- property endpointURL: str¶
The root location or primary endpoint of the service (a Web-resolvable IRI).
- classmethod from_json(json)¶
Convert a JSON (dict).
- property has_policy: str¶
A link to an ODRL conformant policy expressing the rights associated with the resource.
- property is_referenced_by: List[Resource]¶
A list of related resources, such as a publication, that references, cites, or otherwise points to the cataloged resource.
- property landing_page: List[str]¶
A list of links to web pages that can be navigated to in a Web browser to gain access to the catalog, a dataset, its distributions and/or additional information.
- property modification_date: str¶
Most recent date on which the item was changed, updated or modified.
- property qualified_attributions: List[Dict]¶
List of links to an Agent having some form of responsibility for the resource.
- property qualified_relation: List[Relationship]¶
A list of links to a description of a relationship with another resource.
- Type
List[Relationship]
- Return type
- property resource_relation: List[str]¶
A list of links to resources with an unspecified relationship to the cataloged item.
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
- to_rdf(format='turtle', encoding='utf-8')¶
Maps the distribution to rdf.
- Available formats:
turtle (default)
xml
json-ld
- Parameters
- Return type
- Returns
a rdf serialization as a bytes literal according to format.
Example
>>> from datacatalogtordf import Catalog >>> >>> catalog = Catalog() >>> catalog.identifier = "http://example.com/catalogs/1" >>> catalog.title = {'en': 'Title of catalog'} >>> bool(catalog.to_rdf()) True
datacatalogtordf.dataset¶
Dataset module for mapping a dataset to rdf.
This module contains methods for mapping a dataset object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Dataset, Distribution
>>>
>>> dataset = Dataset()
>>> dataset.identifier = "http://example.com/datasets/1"
>>> dataset.title = {"en": "Title of dataset"}
>>>
>>> a_distribution = Distribution()
>>> a_distribution.identifier = "http://example.com/dataservices/1"
>>> a_distribution.title = {"en": "Title of distribution"}
>>> dataset.distributions.append(a_distribution)
>>>
>>> bool(dataset.to_rdf())
True
- class datacatalogtordf.dataset.Dataset(identifier=None)¶
Bases:
Resource
A class representing a dcat:Dataset.
- Parameters
identifier (URI) – the identifier of the dataset.
Ref: dcat:Dataset.
- property access_rights: str¶
A link to information about who can access the resource or an indication of its security status.
- property access_rights_comments: List[str]¶
Referanse til hjemmel (kilde for påstand) i offentlighetsloven, sikkerhetsloven, beskyttelsesinstruksen eller annet lovverk som ligger til grunn for vurdering av tilgangsnivå.
- property conforms_to: List[str]¶
A list of links to established standards to which the described resource conforms.
- property contactpoint: Contact¶
Relevant contact information for the cataloged resource.
- Type
Contact
- Return type
Contact
- property distributions: List[Distribution]¶
A list of distributions of the dataset.
- Type
List[Distribution]
- Return type
- classmethod from_json(json)¶
Convert a JSON (dict).
- property has_policy: str¶
A link to an ODRL conformant policy expressing the rights associated with the resource.
- property in_series: DatasetSeries¶
A dataset series of which the dataset is part.
- Type
- Return type
- property is_referenced_by: List[Resource]¶
A list of related resources, such as a publication, that references, cites, or otherwise points to the cataloged resource.
- property landing_page: List[str]¶
A list of links to web pages that can be navigated to in a Web browser to gain access to the catalog, a dataset, its distributions and/or additional information.
- property modification_date: str¶
Most recent date on which the item was changed, updated or modified.
- property qualified_attributions: List[Dict]¶
List of links to an Agent having some form of responsibility for the resource.
- property qualified_relation: List[Relationship]¶
A list of links to a description of a relationship with another resource.
- Type
List[Relationship]
- Return type
- property resource_relation: List[str]¶
A list of links to resources with an unspecified relationship to the cataloged item.
- property spatial_resolution_in_meters: List[Decimal]¶
A list of minimum spatial separation resolvables in a dataset, measured in meters.
- property temporal: List[PeriodOfTime]¶
A list of temporal periods that the dataset covers.
- Type
List[PeriodOfTime]
- Return type
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
- to_rdf(format='turtle', encoding='utf-8', include_distributions=True)¶
Maps the catalog to rdf.
- Available formats:
turtle (default)
xml
json-ld
datacatalogtordf.dataset_series¶
DatasetSeries module for mapping a dataset_series to rdf.
This module contains methods for mapping a dataset_series object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Catalog, DatasetSeries, Dataset
>>>
>>> dataset_series = DatasetSeries("http://example.com/dataset_series/1")
>>> dataset_series.title = {"en": "Title of dataset_series"}
>>>
>>> catalog = Catalog("http://example.com/catalog/1")
>>> catalog.datasets.append(dataset_series)
>>>
>>> first_dataset = Dataset()
>>> first_dataset.identifier = "http://example.com/datasets/1"
>>> first_dataset.in_series = dataset_series
>>>
>>> second_dataset = Dataset()
>>> second_dataset.identifier = "http://example.com/datasets/2"
>>> second_dataset.in_series = dataset_series
>>> second_dataset.prev = first_dataset
>>>
>>> dataset_series.first = first_dataset
>>> dataset_series.last = second_dataset
>>>
>>> bool(catalog.to_rdf())
True
- class datacatalogtordf.dataset_series.DatasetSeries(identifier=None)¶
Bases:
Dataset
A class representing a dcat:DatasetSeries.
Ref: dcat:DatasetSeries.
- Parameters
identifier (URI) – the identifier of the dataset-series.
- property access_rights: str¶
A link to information about who can access the resource or an indication of its security status.
- property access_rights_comments: List[str]¶
Referanse til hjemmel (kilde for påstand) i offentlighetsloven, sikkerhetsloven, beskyttelsesinstruksen eller annet lovverk som ligger til grunn for vurdering av tilgangsnivå.
- property conforms_to: List[str]¶
A list of links to established standards to which the described resource conforms.
- property contactpoint: Contact¶
Relevant contact information for the cataloged resource.
- Type
Contact
- Return type
Contact
- property distributions: List[Distribution]¶
A list of distributions of the dataset.
- Type
List[Distribution]
- Return type
- property first: Dataset¶
The first resource in an ordered collection or series of resources, to which the current resource belongs.
- classmethod from_json(json)¶
Convert a JSON (dict).
- property has_policy: str¶
A link to an ODRL conformant policy expressing the rights associated with the resource.
- property in_series: DatasetSeries¶
A dataset series of which the dataset is part.
- Type
- Return type
- property is_referenced_by: List[Resource]¶
A list of related resources, such as a publication, that references, cites, or otherwise points to the cataloged resource.
- property landing_page: List[str]¶
A list of links to web pages that can be navigated to in a Web browser to gain access to the catalog, a dataset, its distributions and/or additional information.
- property last: Dataset¶
The last resource in an ordered collection or series of resources, to which the current resource belongs.
- property modification_date: str¶
Most recent date on which the item was changed, updated or modified.
- property qualified_attributions: List[Dict]¶
List of links to an Agent having some form of responsibility for the resource.
- property qualified_relation: List[Relationship]¶
A list of links to a description of a relationship with another resource.
- Type
List[Relationship]
- Return type
- property resource_relation: List[str]¶
A list of links to resources with an unspecified relationship to the cataloged item.
- property spatial_resolution_in_meters: List[Decimal]¶
A list of minimum spatial separation resolvables in a dataset, measured in meters.
- property temporal: List[PeriodOfTime]¶
A list of temporal periods that the dataset covers.
- Type
List[PeriodOfTime]
- Return type
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
- to_rdf(format='turtle', encoding='utf-8', include_datasets=True, include_services=True, include_models=True, include_contains_services=True)¶
Maps the catalog to rdf.
- Available formats:
turtle (default)
xml
json-ld
- Parameters
format (str) – a valid format.
encoding (str) – the encoding to serialize into
include_datasets (bool) – includes the dataset graphs in the catalog
include_services (bool) – includes the services in the catalog
include_models (bool) – includes the models in the catalog
include_contains_services (bool) – includes the services (cpsvno) in the catalog
- Return type
- Returns
a rdf serialization as a bytes literal according to format.
datacatalogtordf.distribution¶
Distribution module for mapping a distribution to rdf.
This module contains methods for mapping a distribution object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Distribution
>>>
>>> distribution = Distribution()
>>> distribution.identifier = "http://example.com/dataservices/1"
>>> distribution.title = {"en": "Title of distribution"}
>>>
>>> bool(distribution.to_rdf())
True
- class datacatalogtordf.distribution.Distribution(identifier=None)¶
Bases:
object
A class representing a dcat:Distribution.
Ref: dcat:Distribution
- Parameters
identifier (URI) – the identifier of the dataset-series.
- property access_URL: str¶
A URL of the resource that gives access to a distribution of the dataset. E.g. landing page, feed, SPARQL endpoint.
- property access_rights: str¶
A link to rights statement that concerns how the distribution is accessed.
- property access_service: DataService¶
A data service that gives access to the distribution of the dataset.
- Type
- Return type
- property compression_format: str¶
Link to the compression format of the distribution in which the data is contained in a compressed form, e.g. to reduce the size of the downloadable file.
- property conforms_to: List[str]¶
A list of links to established standards to which the distribution conforms.
- classmethod from_json(json)¶
Convert a JSON (dict).
- Parameters
json (
Dict
) – A dict representing this class.- Returns
The object.
- Return type
- property has_policy: str¶
A link to an ODRL conformant policy expressing the rights associated with the distribution.
- property modification_date: str¶
Most recent date on which the distribution was changed, updated or modified.
- property package_format: str¶
Link to the package format of the distribution in which one or more data files are grouped together, e.g. to enable a set of related files to be downloaded together.
- property spatial_resolution_in_meters: List[Decimal]¶
A list of minimum spatial separation resolvables in a dataset distribution, measured in meters.
- property temporal_resolution: List[str]¶
A list of minimum time period resolvables in the dataset distribution.
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
datacatalogtordf.uri¶
URI helper module for very basic validation of a uri.
- class datacatalogtordf.uri.URI(link)¶
Bases:
str
A helper class to validate a URI.
If the string is serializable as an rdflib.URIRef, it is valid. Otherwise not.
Essentially it is serializable if none of the following chars occurs:
_invalid_uri_chars = '<>" {}|\\^`'
- Parameters
link (
str
) – The string to validate as URI.- Raises
InvalidURIError – If the string is not a valid URI.
Ref: https://github.com/RDFLib/rdflib/blob/master/rdflib/term.py#L75
Example
>>> from datacatalogtordf import Dataset, URI >>> >>> dataset = Dataset() >>> dataset.identifier = URI("http://example.com/datasets/1") >>> dataset.identifier 'http://example.com/datasets/1'
datacatalogtordf.periodoftime¶
PeriodOfTime module for mapping a period_of_time to rdf.
This module contains methods for mapping a period_of_time object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import PeriodOfTime
>>>
>>> period_of_time = PeriodOfTime()
>>> period_of_time.start_date = "2019-12-31"
>>> period_of_time.end_date = "2020-12-31"
>>>
>>> bool(period_of_time.to_rdf())
True
- class datacatalogtordf.periodoftime.Date(link)¶
Bases:
str
A helper class to validate a Date.
If the string is a valid of the format “%Y-%m-%d”, it is valid. Otherwise not.
- Raises
InvalidDateError – If the str does not represent a valid date
- class datacatalogtordf.periodoftime.PeriodOfTime¶
Bases:
object
A class representing a dcat:PeriodOfTime.
Ref: dcat:PeriodOfTime
- Raises
InvalidDateIntervalError – If the interval is “negative”, i.e. start date is after the end date
- classmethod from_json(json)¶
Convert a JSON (dict).
- Parameters
json (
Dict
) – A dict representing this class.- Returns
The object.
- Return type
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
datacatalogtordf.location¶
Location module for mapping a location to rdf.
This module contains methods for mapping a location object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Location
>>>
>>> location = Location()
>>> location.identifier = "http://example.com/relations/1"
>>> location.centroid = "POINT(4.88412 52.37509)"
>>>
>>> bool(location.to_rdf())
True
- class datacatalogtordf.location.Location(identifier=None)¶
Bases:
object
A class representing a dcat:Location.
Ref: dcat:Location
- classmethod from_json(json)¶
Convert a JSON (dict).
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
datacatalogtordf.agent¶
Agent module for mapping a agent to rdf.
This module contains methods for mapping a agent object to rdf according to the dcat-ap-no v.2 standard
Example
>>> from datacatalogtordf import Agent, Dataset
>>> dataset = Dataset()
>>> dataset.identifier = "http://example.com/datasets/1"
>>> # Create an agent:
>>> agent = Agent()
>>> agent.identifier = "http://example.com/agents/1"
>>> agent.name = {"en": "James Bond", "nb": "Djeims Bånd"}
>>> # Assigen the agent to the publisher property:
>>> dataset.publisher = agent
>>> bool(dataset.to_rdf())
True
- class datacatalogtordf.agent.Agent(identifier=None)¶
Bases:
object
A class representing a foaf:Agent.
- Parameters
identifier (URI) – the identifier of the dataset.
- classmethod from_json(json)¶
Convert a JSON (dict).
- to_json()¶
Convert the Resource to a json / dict. It will omit the non-initalized fields.
- Returns
The json representation of this instance.
- Return type
Dict
datacatalogtordf.exceptions¶
Exeptions module for datacatalogtordf.
- exception datacatalogtordf.exceptions.Error(msg=None)¶
Bases:
Exception
Base class for exceptions.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception datacatalogtordf.exceptions.InvalidDateError(date, msg)¶
Bases:
Error
Exception raised for errors in the input.
- str -- input str in which the error occurred
- message -- explanation of the error
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception datacatalogtordf.exceptions.InvalidDateIntervalError(start_date, end_date, msg)¶
Bases:
Error
Exception raised for errors in the input.
- str -- input str in which the error occurred
- message -- explanation of the error
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
A small Python library for mapping a data catalog to rdf
The library contains helper classes for the following dcat classes:
Other relevant classes are also supported, such as:
Contact (vcard:Kind)
The library will map to the Norwegian Application Profile of the DCAT standard.
Installation¶
To install the datacatalogtordf package, run this command in your terminal:
$ pip install datacatalogtordf
Usage¶
This package can be used like this:
from datacatalogtordf import Catalog, Dataset
# Create catalog object
catalog = Catalog()
catalog.identifier = "http://example.com/catalogs/1"
catalog.title = {"en": "A dataset catalog"}
catalog.publisher = "https://example.com/publishers/1"
# Create a dataset:
dataset = Dataset()
dataset.identifier = "http://example.com/datasets/1"
dataset.title = {"nb": "inntektsAPI", "en": "incomeAPI"}
#
# Add concept to catalog:
catalog.datasets.append(dataset)
# get rdf representation in turtle (default)
rdf = catalog.to_rdf(format="turtle")
print(rdf.decode())
Will produce the following output:
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dct: <http://purl.org/dc/terms/> .
<http://example.com/catalogs/1> a dcat:Catalog ;
dct:publisher <https://example.com/publishers/1> ;
dct:title "A dataset catalog"@en ;
dcat:dataset <http://example.com/datasets/1> .
<http://example.com/datasets/1> a dcat:Dataset ;
dct:title "incomeAPI"@en,
"inntekstAPI"@nb .