From 04560577319dfbf30496f9a2a0dbfddfe8fc2215 Mon Sep 17 00:00:00 2001 From: David Linke Date: Mon, 30 Oct 2023 09:15:35 +0100 Subject: [PATCH] Upgrade curies pkg and use new passthrough option Closes #173 --- pyproject.toml | 2 +- src/voc4cat/models.py | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3ee1b73..02dd48d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ classifiers = [ dependencies = [ "base32-crockford >= 0.3.0", - "curies >= 0.5.6", + "curies >= 0.6.6", "networkx >= 2.8", "openpyxl >= 3.0.9", "ontospy >= 2.1.0", diff --git a/src/voc4cat/models.py b/src/voc4cat/models.py index f8d2d67..2aa7358 100644 --- a/src/voc4cat/models.py +++ b/src/voc4cat/models.py @@ -233,7 +233,7 @@ def to_graph(self): def to_excel(self, wb: Workbook): ws = wb["Concept Scheme"] - ws["B2"] = config.curies_converter.compress(self.uri) or self.uri + ws["B2"] = config.curies_converter.compress(self.uri, passthrough=True) ws["B3"] = self.title ws["B4"] = self.description ws["B5"] = self.created.isoformat() @@ -365,8 +365,8 @@ def to_excel(self, wb: Workbook, row_no_features: int, row_no_concepts: int): first_row_exported = False for lang in chain(fully_translated, partially_translated): - ws[f"A{row_no_concepts}"] = ( - config.curies_converter.compress(self.uri) or self.uri + ws[f"A{row_no_concepts}"] = config.curies_converter.compress( + self.uri, passthrough=True ) ws[f"B{row_no_concepts}"] = pref_labels.get(lang, "") ws[f"C{row_no_concepts}"] = lang @@ -382,15 +382,12 @@ def to_excel(self, wb: Workbook, row_no_features: int, row_no_concepts: int): ws[f"F{row_no_concepts}"] = ",\n".join(self.alt_labels) ws[f"G{row_no_concepts}"] = ",\n".join( [ - (config.curies_converter.compress(uri) or uri) + config.curies_converter.compress(uri, passthrough=True) for uri in self.children ] ) ws[f"I{row_no_concepts}"] = ( - ( - config.curies_converter.compress(self.source_vocab) - or self.source_vocab - ) + config.curies_converter.compress(self.source_vocab, passthrough=True) if self.source_vocab else None ) @@ -398,29 +395,38 @@ def to_excel(self, wb: Workbook, row_no_features: int, row_no_concepts: int): ws = wb["Additional Concept Features"] - ws[f"A{row_no_features}"] = ( - config.curies_converter.compress(self.uri) or self.uri + ws[f"A{row_no_features}"] = config.curies_converter.compress( + self.uri, passthrough=True ) ws[f"B{row_no_features}"] = ",\n".join( [ - (config.curies_converter.compress(uri) or uri) + config.curies_converter.compress(uri, passthrough=True) for uri in self.related_match ] ) ws[f"C{row_no_features}"] = ",\n".join( - [(config.curies_converter.compress(uri) or uri) for uri in self.close_match] + [ + config.curies_converter.compress(uri, passthrough=True) + for uri in self.close_match + ] ) ws[f"D{row_no_features}"] = ",\n".join( - [(config.curies_converter.compress(uri) or uri) for uri in self.exact_match] + [ + config.curies_converter.compress(uri, passthrough=True) + for uri in self.exact_match + ] ) ws[f"E{row_no_features}"] = ",\n".join( [ - (config.curies_converter.compress(uri) or uri) + config.curies_converter.compress(uri, passthrough=True) for uri in self.narrow_match ] ) ws[f"F{row_no_features}"] = ",\n".join( - [(config.curies_converter.compress(uri) or uri) for uri in self.broad_match] + [ + config.curies_converter.compress(uri, passthrough=True) + for uri in self.broad_match + ] ) return row_no_concepts @@ -461,11 +467,14 @@ def to_graph(self): def to_excel(self, wb: Workbook, row_no: int): ws = wb["Collections"] - ws[f"A{row_no}"] = config.curies_converter.compress(self.uri) or self.uri + ws[f"A{row_no}"] = config.curies_converter.compress(self.uri, passthrough=True) ws[f"B{row_no}"] = self.pref_label ws[f"C{row_no}"] = self.definition ws[f"D{row_no}"] = ",\n".join( - [(config.curies_converter.compress(uri) or uri) for uri in self.members] + [ + config.curies_converter.compress(uri, passthrough=True) + for uri in self.members + ] ) ws[f"E{row_no}"] = self.provenance