Published in Donny Winston

In a hierarchy, each agent only acts on behalf of one other agent: from rdflib import Graph from rdflib.namespace import RDF, PROV def hierarchy(graph): return all( len(set(graph.objects(agent, PROV.actedOnBehalfOf))) <= 1 for agent in graph.subjects(RDF.type, PROV.Agent) ) hierarchy(Graph().parse(data=""" @prefix prov: . @prefix : . :doc a prov:Agent; . :sleepy a prov:Agent;