Custom RML Rules

An advantage of building RML mapping rules is that you can add custom RML rules to an existing Processor subclass. For example, you may want to a bf:heldBy predicate to your bf:Item entities that points to your institution's IRI.

Referring back to the State of Colorado Publication's library, we create a new RML predicateObjectMap to the existing BIBFRAME Item tripleMap with the following:


@prefix rml:    <http://semweb.mmlab.be/ns/rml#> .
@prefix rr:   < http://www.w3.org/ns/r2rml#>.
@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .

bc:MODS2BIBFRAME_Item  rr:predicateObjectMap [
    rr:predicate bf:heldBy ;
    rr:objectMap [
        rr:constant <https://www.cde.state.co.us/stateinfo> ;
    ]
] .

Saving this rule in a temporary file, we will create a new XMLProcessor instance with the new RML rule and rerun the MODS-to-BIBFRAME conversion.


>>> mods_processor = processor.XMLProcessor(
        rml_rules=['mods-to-bf.ttl',
                   'bibcat-base.ttl',
                   '/Path/to/rule/custom.ttl'],
        base_url = 'https://www.cde.state.co.us/',
        namespaces={"mods": "http://www.loc.gov/mods/v3",
                    "xlink": "https://www.w3.org/1999/xlink"})
>>> mods_processor.run(
        mods_xml,
        instance_iri='https://www.cde.state.co.us/rail-communication-handbook',
        item_iri='http://hermes.cde.state.co.us/drupal/islandora/object/co:21951/')

Checking the resulting turtle serialization of the output RDF graph, we can see that 'http://hermes.cde.state.co.us/drupal/islandora/object/co:21951/' subject now has a new triple with the predicate being bf:heldBy and the object being the Colorado State Library Publication IRI.


.
.
.
<http://hermes.cde.state.co.us/drupal/islandora/object/co:21951/> a bf:Item ;
    bf:generationProcess [ a bf:GenerationProcess ;
            bf:generationDate "2017-11-10T14:36:50.510775" ;
            rdf:value "Generated by BIBCAT version 1.18.1 from KnowledgeLinks.io"^^xsd:string ] ;
    bf:heldBy <https://www.cde.state.co.us/stateinfo> ;
    bf:itemOf <https://www.cde.state.co.us/rail-communication-handbook> .

.
.

This finishes the introduction to RML mapping with bibcat, now we will look at a second core functionality, that of linking to other sources of Linked Data with our existing BIBFRAME RDF.

Original contented Copyrighted © 2017 by Jeremy Nelson and KnowledgeLinks under Creative Commons License, Source code repository licensed under the Apache 2 and available on Github.