Skip to main content

Link your data to authority lists or your own controlled lists

Project description

PyPI version

Django Controlled Vocabulary

This app provides models and admin interface to link your data to standard vocabularies (e.g. ISO language codes, Wikidata). Benefits: increases the consistency and understandability of your project data.

Development Status: Alpha (mostly functional, work in progress)

A ControlledTerm field in the Django admin interface. The user selects the vocabulary (here: Wikidata), then starts typing a term in the text box. Suggestions are brought from Wikidata. When the user saves the changes, information about the selected term is copied into the database (url, identifier, label).

Features

  • create your own controlled lists of terms (i.e. local lists)
  • look up terms from remote vocabularies (i.e. authority files)
  • extensible plug-in architecture for lookups into particular vocabularies:
    • built-in vocabulary plug-ins, such as ISO 639-2 (Language codes), DCMI Type (Dublin Core resource types)
  • stores used terms from remote vocabularies into your database:
    • space efficient (doesn't clutter the database with unused terms)
    • self-contained (i.e. can still works offline & DB always 'semantically' complete)
  • autocomplete widget for Django admin; reusable ControlledTermField for your models
  • command line tool to download vocabulary files from authoritative sources
  • [TODO] possibility to store additional metadata (e.g. geographic coordinates)
  • [TODO] simple rest API to publish your own terms

Data Model & Software Design

Django models

Vocabularies Terms
  • ControlledVocabulary

    • prefix: the vocabulary standard prefix, see http://prefix.cc/wikidata
    • label: the short name of the vocabulary
    • base_url: the url used as a base for all terms in the vocabulary
    • concept: the type of terms this vocabulary contains
    • description: a longer description
  • ControlledTerm

    • termid: a unique code for the term within a vocabulary
    • label: standard name for the term
    • vocabulary: the vocabulary this term belongs to

Vocabulary plug-ins / managers

A Vocabulary plug-in / manager is a python class that provides services for a vocabulary:

  • autocomplete terms from local or remote datasets (see ControlledTermField)
  • supplies metadata for the vocabulary (see ControlledVocabulary)

Managers can provide terms from a CSV file downloaded from an authoritative source.

Some vocabularies can contain thousands of terms or more. A plugin will only insert the terms used by your application. The rest will be accessed on demand from a file on disk or in a third-party server. This approach saves database space and keeps your application data self-contained.

This project comes with built-in plugins for the following vocabularies:

ISO 639-2, DCMI Type, Wikidata, FAST Topics, MIME, Schema.org

Those plugins are enabled by default; see below how to selectively enable them.

This architecture allows third-party plugins to be supplied via separate python packages.

Limitations

  • controlled list rather than fully fledged vocabularies, (i.e. just a bag of terms with unique IDs/URIs, no support for taxonomic relationships among terms like broader, narrower, synonyms, ...)
  • no notion of granularity (e.g. geonames country, region, city, street are all treated as part of the same vocabulary)

Setup

Installation

Install into your environment:

pip install django-controlled-vocabulary

Add the app to the INSTALLED_APPS list in your Django settings file:

INSTALLED_APPS = [
    # other apps
    'controlled_vocabulary',
]

Run the migrations:

./manage.py migrate

Download vocabulary data and add metadata to the database:

./manage.py vocab init

Configuration

Enabling vocabulary plug-ins

Add the following code in your settings.py to enable specific vocabularies based on the import path of their classes.

# List of import paths to vocabularies lookup classes
CONTROLLED_VOCABULARY_VOCABULARIES = [
    'controlled_vocabulary.vocabularies.iso639_2',
    'controlled_vocabulary.vocabularies.dcmitype',
]

ControlledTermField

To define a field with an autocomplete to controlled terms in your Django Model, use the following field:

from controlled_vocabulary.models import ControlledTermField

...

class MyModel(models.Model):

    ...
    language_code = ControlledTermField(
        'iso639-2',
        null=True, blank=True
    )

Where 'iso639-2' is the prefix of a controlled vocabulary in your database.

vocab (command line tool)

vocab is a django command line tool that lets you manipulate the vocabularies and the plugins. To find out more use the help:

./manage vocab help

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

django-controlled-vocabulary-0.3.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_controlled_vocabulary-0.3.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file django-controlled-vocabulary-0.3.0.tar.gz.

File metadata

  • Download URL: django-controlled-vocabulary-0.3.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.6.9 Linux/4.15.0-72-generic

File hashes

Hashes for django-controlled-vocabulary-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5390ed5a5f30e6834d0e8ee8528f566d3db42a9769eb0da5a4491f895b30e29c
MD5 1098498c0defd31f917487c4d6252669
BLAKE2b-256 9544cd5800acb1c75cd2f67eca1773239e50ac808252f192043c0ea2a9a9fabc

See more details on using hashes here.

File details

Details for the file django_controlled_vocabulary-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_controlled_vocabulary-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a4114dd229f9dc1c49bb98c8db2b137d6a85ce335dcea3c68dcf96177287afa
MD5 9005446f47922a3e53309507f844f8c3
BLAKE2b-256 66dca948510bcd19cffe136cfde56678b0bd89be1f6a37cad92036c728768548

See more details on using hashes here.

Supported by

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