Skip to content

Commit

Permalink
intersperse class_set instead of using string join (resolves issue #188)
Browse files Browse the repository at this point in the history
  • Loading branch information
keski committed Apr 4, 2023
1 parent 68977eb commit e0c38a8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pylode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,11 @@ def _setclass_html(ont__, obj__, back_onts__, ns__, fids__):
"""Makes lists of (union) 'ClassX or Class Y or ClassZ' or
(intersection) 'ClassX and Class Y and ClassZ'"""
if (obj__, OWL.unionOf, None) in ont__:
joining_word = ' <span class="cardinality">or</span> '
joining_word = span("or", _class="cardinality")
elif (obj__, OWL.intersectionOf, None) in ont__:
joining_word = ' <span class="cardinality">and</span> '
joining_word = span("and", _class="cardinality")
else:
joining_word = ' <span class="cardinality">,</span> '
joining_word = span(",", _class="cardinality")

class_set = set()
for o in ont__.objects(obj__, OWL.unionOf | OWL.intersectionOf):
Expand All @@ -671,7 +671,7 @@ def _setclass_html(ont__, obj__, back_onts__, ns__, fids__):
)
)

return raw(joining_word.join([mem.render() for mem in class_set]))
return intersperse(class_set, joining_word)

def _bn_html(ont__, back_onts__, ns__, fids__, obj__: BNode):
# TODO: remove back_onts and fids if not needed by subfunctions
Expand Down Expand Up @@ -871,6 +871,11 @@ def _element_html(
return elems


def intersperse(lst, sep):
result = [sep] * (len(lst) * 2 - 1)
result[0::2] = lst
return result

def de_space_html(html):
# s = "".join([l_.strip().replace("\n", " ") for l_ in html.split("\n")])
# return re.sub(" +", " ", s)
Expand Down

0 comments on commit e0c38a8

Please sign in to comment.