Skip to main content

Pydantic Cidoc-CRM implementation

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_cidoc_crm-0.0.2.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

pydantic_cidoc_crm-0.0.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_cidoc_crm-0.0.2.tar.gz.

File metadata

  • Download URL: pydantic_cidoc_crm-0.0.2.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for pydantic_cidoc_crm-0.0.2.tar.gz
Algorithm Hash digest
SHA256 db57581354f1faff7b3bded00c7aa4d0c5a4b22be88cdb7cfb6ac6f72f9e12f9
MD5 f1eef283f9e1b543c48a471de58e6ff8
BLAKE2b-256 1e6dc6fea4693c1dd89f16999454099b8eb56eb72dc98ecb4fb6eb268b8872a7

See more details on using hashes here.

File details

Details for the file pydantic_cidoc_crm-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_cidoc_crm-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c2296b8b529096e3edf2c7e85f52f78ecd36e5d5b3ce03108ba0b9cf50cc5a2b
MD5 ff6fda8f4e9f4d4022e70ae752facf41
BLAKE2b-256 df826fdf6df08051ef2cf5d76cb3eb88f6b1dfbbb8130bc91db55b02c29f4851

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page