thegetty / crom

Python library to make creation of CIDOC CRM easier by mapping classes/predicates to python objects
Apache License 2.0
49 stars 16 forks source link

Build Status Coverage Status

Cromulent

A Python library to make creation of CIDOC CRM easier by mapping classes/predicates to python objects/properties, thereby making the CRM "CRoMulent", a Simpsons neologism for "acceptable" or "fine".

Status: Beta

The core vocabulary loading functionality is reasonably stable. The vocabulary section is expanding as we find new, useful terms to include and will likely constantly change.

The code is actively being developed and compability breaking changes are thus to be expected as we use it in various projects across The J Paul Getty Trust, and beyond.

How to Use It

Basic Usage

Import the classes from the model module. As the classes are dynamically generated, they're not in the code but will be there once the build_classes function has been called.

from cromulent.model import factory, Group
g1 = Group(ident="Organization")
g2 = Group(ident="Department")
g1.member = g2
print factory.toString(g1, compact=False)

The constructor for the classes takes the following parameters:

Vocabulary

from cromulent.model import factory
from cromulent.vocab import Height
h = Height()
h.value = 6
print factory.toString(h, compact=False)

Tricks and Gotchas

Factory settings

There are quite a few settings for how the module works, which are managed by a factory object.

URI and File System Configuration:

Model Validation and Generation:

Internal:

How it Works

At import time, the library parses the vocabulary data file (data/crm_vocab.tsv) and creates Python classes in the module's global scope from each of the defined RDF classes. The names of the classes are intended to be easy to use and remember, not necessarily identical to the CRM ontology's names. It also records the properties that can be used with that class, and at run time checks whether the property is defined and that the value fits the defined range.

Hacking

You can change the mapping by tweaking utils/vocab_reader.py and rerunning it to build a new TSV input file. See also the experimental code for loading completely different ontologies.