#!/usr/bin/env python # generates a graphviz file for visualizing syndetic # links between subjects when skos rdf/xml fed on stdin from rdflib.Graph import Graph from rdflib import Namespace from sys import stdin g = Graph() g.parse(stdin) SKOS = Namespace('http://www.w3.org/2004/02/skos/core#') print 'digraph G {' print ' rankdir = "BT"' for s, o in g.subject_objects(SKOS["broader"]): s_label = g.value(subject=s, predicate=SKOS["prefLabel"]) o_label = g.value(subject=o, predicate=SKOS["prefLabel"]) if o_label is not None: print (' "%s" -> "%s";' % (s_label, o_label)).encode('utf8') print "}"