Skip to content

Commit

Permalink
Merge pull request #187 from keski/master
Browse files Browse the repository at this point in the history
resolve issue #186 and #188
  • Loading branch information
nicholascar authored Jul 26, 2024
2 parents 8fe4c45 + e0c38a8 commit 45c5d1b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions pylode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@ def _restriction_html(ont__, obj__, ns__):
span(card, _class="cardinality"),
raw(_rdf_obj_single_html),
)
else:
card = span(
span(card, _class="cardinality"),
span(
_hyperlink_html(
ont__, back_onts_, ns__, o, fids_, OWL.Class
)
),
)

card = span(
span(card, _class="cardinality"),
span(
_hyperlink_html(
ont__, back_onts_, ns__, o, fids_, OWL.Class
)
),
)

restriction = span(prop, card, br()) if card is not None else prop
restriction = (
Expand All @@ -672,11 +672,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 @@ -687,7 +687,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 @@ -887,6 +887,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 45c5d1b

Please sign in to comment.