Skip to content

Commit

Permalink
neurons orders work around broken runtime type checking in rdflib
Browse files Browse the repository at this point in the history
  • Loading branch information
tgbugs committed Jan 15, 2025
1 parent 95e40c4 commit 91ac350
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions neurondm/neurondm/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def nst_to_adj(l):
second = [p for r in l[1:] if r for p in nst_to_adj(r)]
return tuple(first + second)


def assoc(k, ass):
for a, b in ass:
if a == k:
return a, b


def dvals(k, ass):
pair = assoc(k, ass)
mem = ass[ass.index(pair):] if pair in ass else False
Expand Down Expand Up @@ -215,7 +217,9 @@ def from_rdf(g, linker, to_python=False):
def getlist(g, bn0, to_python=False):
def f(node, g):
o = None
for o in g[node:rdf.first:]:

#for o in g[node:rdf.first:]:
for o in g.objects(node, rdf.first):
if isinstance(o, rdflib.BNode):
# unfortunately we have to branch on the result type
# or have to look ahead to see if the list continues
Expand All @@ -234,15 +238,17 @@ def f(node, g):
else:
yield o

for o in g[node:rdf.rest:]:
#for o in g[node:rdf.rest:]:
for o in g.objects(node, rdf.rest):
if o != rdf.nil:
yield from getlist(g, o, to_python=to_python)

if o is None and isinstance(node, rdflib.BNode): # [ :a :b ] case
for p, o in g[node:]:
#for p, o in g[node:]:
for p, o in g.predicate_objects(node):
if to_python:
yield rl((p.toPython() if isinstance(p, rdflib.Literal) else p),
(o.toPython() if isinstance(o, rdflib.Literal) else o),)
(o.toPython() if isinstance(o, rdflib.Literal) else o),)
else:
yield rl(p, o)

Expand Down

0 comments on commit 91ac350

Please sign in to comment.