inveniosoftware / dojson

Simple pythonic JSON to JSON converter.
https://dojson.readthedocs.io
Other
10 stars 29 forks source link

Allow local fields, subfields and indicators #24

Closed fjorba closed 9 years ago

fjorba commented 9 years ago

Marc21 makes room for a local installation to define its own local field with the convention that they contain a 9, either as a tag (typically 9XX tags, but also like 59X), indicators or subfields.

Invenio should make it easy to follow this convention without resorting to tortuous modifications of internal syntax rules.

tiborsimko commented 9 years ago

Yes, this will be possible by composing various JSON schemas together, see my reply in another issue. For a concrete example, @egabancho is working on defining the JSON schemas for CDS records. These have many local fields and subfields defined. @egabancho can you please post here a small example if you already have one?

egabancho commented 9 years ago

There are many ways that you can do it already, this is how I am do it for CDS so far (keep in mind this is work in progress).

First I define my own "model" (in my case it contains all the marc21 rules by default)

from dojson.overdo import Overdo
from dojson.contrib.marc21 import marc21

class CDSMarc21(Overdo):

    """Translation Index for CDS specific MARC21."""

    def __init__(self):
        """Constructor.

        Initializes the list of rules with the default ones from doJSON.
        """
        super(CDSMarc21, self).__init__()
        self.rules.extend(marc21.rules)

cds_marc21 = CDSMarc21()

And then I add new fields to it

from dojson import utils
from ..model import cds_marc21

@cds_marc21.over('subject_indicator', '^690C_')
@utils.for_each_value
def subject_indicator(self, key, value):
    """Subject Indicator."""
    return value.get('a')

This is also somehow related with https://github.com/inveniosoftware/invenio-records/pull/3, it allows to use different processors, i.e. cds_marc21 instead of marc21.