#!/usr/bin/env python from rdflib import ConjunctiveGraph from lcsh.namespaces import SKOS from re import match g = ConjunctiveGraph('Sleepycat') g.open('store') prefixes = {} try: for s in g.subjects(predicate=SKOS['prefLabel']): m = match('^http://lcsh.info/([a-z]+)', s) prefix = m.group(1) prefixes[prefix] = prefixes.get(prefix, 0) + 1 finally: g.close() for prefix in prefixes.keys(): print "%s [%s]" % (prefix, prefixes[prefix])