From a2101a326347a3e276c7f4fdd2f4ba5873d78b08 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 10 Oct 2016 19:52:26 +0200 Subject: formatRefs: Warn about unused nodes Just in case I forget to add citations to the root node. --- tools/formatRefs.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/formatRefs.py b/tools/formatRefs.py index f82705e..265f04d 100755 --- a/tools/formatRefs.py +++ b/tools/formatRefs.py @@ -96,12 +96,32 @@ def getRecursiveAll (s, g, n, predicate): for p in parents: yield from getRecursiveAll (s, g, p, predicate) +def warnUnusedButDefined (graph, rootNode): + """ + Warn about defined, but unused subjects + """ + + subjects = set () + objects = set () + for s, p, o in graph: + subjects.add (s) + objects.add (o) + for unused in subjects.difference (objects): + if unused == rootNode: + continue + print ('Unused: {}'.format (unused), file=sys.stderr) + for ctxp, ctxo in g[unused]: + print ('\t{} {}'.format (ctxp, ctxo), file=sys.stderr) + if __name__ == '__main__': g = Graph() result = g.parse ("index.ttl", format='turtle') rootUri = sys.argv[1] rootNode = URIRef (rootUri) s = Namespace("https://schema.org/") + + warnUnusedButDefined (result, rootNode) + for ref in result.objects (rootNode, s.citation): t = list (g.objects (ref, RDF.type)) assert len (t) == 1 -- cgit v1.2.3