#!/usr/bin/env python

from rdflib import ConjunctiveGraph, Namespace, Literal

DC = Namespace('http://purl.org/dc/elements/1.1/')
SKOS = Namespace('http://www.w3.org/2004/02/skos/core#')

bib = ConjunctiveGraph('Sleepycat')
bib.open('store')

lcsh = ConjunctiveGraph('Sleepycat')
lcsh.open('/home/ed/sites/lcsh.info/store')

for s, o in bib.subject_objects(predicate=DC['subject']):
    heading = o.strip('.')

    for concept in lcsh.subjects(SKOS['prefLabel'], Literal(heading, 'en')):
        # hack until juvenile subject headings get their own concept scheme
        # distinct from lcsh
        if concept.startswith('http://lcsh.info/sh'):
            bib.remove((s, DC['subject'], o))
            bib.add((s, DC['subject'], concept))
            break
