summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2016-10-10 19:52:26 +0200
committerLars-Dominik Braun <lars@6xq.net>2016-10-10 19:52:26 +0200
commita2101a326347a3e276c7f4fdd2f4ba5873d78b08 (patch)
tree199131912a205e42dd663e7e91cde9d0e6988710
parentae0f6d319f099002683d59201d38de60950faa53 (diff)
downloadeumel-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-xtools/formatRefs.py20
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