From 68977eb17a169adff7a5af2938f8d8b40ae78335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Keskis=C3=A4rkk=C3=A4?= Date: Tue, 4 Apr 2023 14:12:22 +0200 Subject: [PATCH 1/2] remove extra else block (resolves issue #186) --- pylode/utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pylode/utils.py b/pylode/utils.py index 1d36e2e6..0a8eda43 100644 --- a/pylode/utils.py +++ b/pylode/utils.py @@ -635,15 +635,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 = ( From e0c38a8c5473e3cbe795bc3092fbcd2d0351d777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Keskis=C3=A4rkk=C3=A4?= Date: Tue, 4 Apr 2023 16:13:44 +0200 Subject: [PATCH 2/2] intersperse class_set instead of using string join (resolves issue #188) --- pylode/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pylode/utils.py b/pylode/utils.py index 0a8eda43..7a672445 100644 --- a/pylode/utils.py +++ b/pylode/utils.py @@ -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 = ' or ' + joining_word = span("or", _class="cardinality") elif (obj__, OWL.intersectionOf, None) in ont__: - joining_word = ' and ' + joining_word = span("and", _class="cardinality") else: - joining_word = ' , ' + joining_word = span(",", _class="cardinality") class_set = set() for o in ont__.objects(obj__, OWL.unionOf | OWL.intersectionOf): @@ -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 @@ -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)