diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2016-10-10 19:52:26 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2016-10-10 19:52:26 +0200 |
commit | a2101a326347a3e276c7f4fdd2f4ba5873d78b08 (patch) | |
tree | 199131912a205e42dd663e7e91cde9d0e6988710 | |
parent | ae0f6d319f099002683d59201d38de60950faa53 (diff) | |
download | eumel-a2101a326347a3e276c7f4fdd2f4ba5873d78b08.tar.gz eumel-a2101a326347a3e276c7f4fdd2f4ba5873d78b08.tar.bz2 eumel-a2101a326347a3e276c7f4fdd2f4ba5873d78b08.zip |
formatRefs: Warn about unused nodes
Just in case I forget to add citations to the root node.
-rwxr-xr-x | tools/formatRefs.py | 20 |
1 files changed, 20 insertions, 0 deletions
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 |