Skip to main content

Pydantic Cidoc-CRM Implementation

License

A Python implementation of Cidoc-CRM 7.1.1 using pydantic and rdflib.

Data modelling in conformity with Cidoc-CRM poses some challenges. Cidoc-CRM has a complex inheritance structure, from which specific range and domain restrictions are derived. Complying with these restrictions can be difficult at times. This package is an attempt to facilitate working with Cidoc-CRM in Python, as well as mitigate some of its challenges. By means of rigours type checking, domain and range are ensured to be correct at all times, as well as typos prevented that would hinder interoperability.

To conform to Python's syntax and standards, a few name changes had to be made:

  1. Underscores and dashes in class names are omitted (E24_Physical_Human-Made_Thing -> E24PhysicalHumanMadeThing)
  2. All properties start with a lower p (P1_is_identified_by -> p1_is_identified_by)
  3. Dashes in property names are replaced by underscores (P4_has_time-span -> p4_has_time_span)

However, when an object is serialized, all names are converted back.

Limitations

Cardinality and XSD types are not defined in the RDFS files. Since this model is automatically generated from theses files, they are not implemented here either. For now, every property accepts an instance or a list of instances of the required domain class or one of its subclasses.

Installation

$ pip3 install pydantic_cidoc_crm

Usage

from pydantic_cidoc_crm import E53Place, E41Appellation
x = E53Place(
    iri="http:/localhost/a_place",
    p1_is_identified_by=E41Appellation(
        iri="http:/localhost/a_place/appellation",
        p190_has_symbolic_content=["Berlin"]
    )
)
x.serialize()
<http:/localhost/a_place/appellation> <http://www.cidoc-crm.org/cidoc-crm/P190_has_symbolic_content> "Berlin" .
<http:/localhost/a_place/appellation> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E41_Appellation> .
<http:/localhost/a_place> <http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by> <http:/localhost/a_place/appellation> .
<http:/localhost/a_place> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E53_Place>

Restrictions of domain:

from pydantic_cidoc_crm import E53Place, E41Appellation
x = E53Place(
    iri="http:/localhost/a_place",
    p48_has_preferred_identifier=E41Appellation(
        iri="http:/localhost/a_place/identifier",
        p190_has_symbolic_content="123"
    )
)

Will throw a validation error:

pydantic.error_wrappers.ValidationError: 1 validation error for E53Place
p48_has_preferred_identifier
  Domain must be E42Identifier or a subclass of it. (type=value_error)

Restriction of range and safeguard against typos:

from pydantic_cidoc_crm import E53Place, E41Appellation
x = E53Place(
    iri="http:/localhost/a_place",
    p1_is_identefied_by=E41Appellation(
        iri="http:/localhost/a_place/appellation",
        p190_has_symbolic_content="Berlin"
    )
)

Will throw a validation error:

pydantic.error_wrappers.ValidationError: 1 validation error for E53Place
p1_is_identefied_by
  extra fields not permitted (type=value_error.extra)

License

This project is licensed under MIT license - see the LICENSE file for more information.

Release files for pydantic-cidoc-crm 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-cidoc-crm 0.0.2
File Size Uploaded
pydantic_cidoc_crm-0.0.2.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-cidoc-crm 0.0.2
File Interpreter ABI Platform
pydantic_cidoc_crm-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.4 kB

Release files / pydantic_cidoc_crm-0.0.2.tar.gz

Download URL pydantic_cidoc_crm-0.0.2.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
db57581354f1faff7b3bded00c7aa4d0c5a4b22be88cdb7cfb6ac6f72f9e12f9
BLAKE2b-256 checksum
How to use checksums
1e6dc6fea4693c1dd89f16999454099b8eb56eb72dc98ecb4fb6eb268b8872a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release files / pydantic_cidoc_crm-0.0.2-py3-none-any.whl

Download URL pydantic_cidoc_crm-0.0.2-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2296b8b529096e3edf2c7e85f52f78ecd36e5d5b3ce03108ba0b9cf50cc5a2b
BLAKE2b-256 checksum
How to use checksums
df826fdf6df08051ef2cf5d76cb3eb88f6b1dfbbb8130bc91db55b02c29f4851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page