Skip to content

Commit

Permalink
Read & write single IRIs as hyperlink with qualifier
Browse files Browse the repository at this point in the history
e.g. "https://example.org/001 (example 001)"
don't add qualifier in concepts and collections
  • Loading branch information
dalito committed Jan 28, 2025
1 parent 8a5ab86 commit 3a349e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/voc4cat/convert_043.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openpyxl.worksheet.worksheet import Worksheet
from pydantic import ValidationError

from voc4cat import models
from voc4cat import config, models
from voc4cat.utils import ConversionError, split_and_tidy

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -70,10 +70,11 @@ def extract_concepts_and_collections(
row = cell.row
if cell.value is None or cell.value in header_names_to_skip:
continue
uri = q[f"A{row}"].value.strip()
uri = q[f"A{row}"].value.split()[0].strip()
uri = prefix_converter.expand(uri) or uri
concept_data[uri] = {
"uri": uri,
"curie": config.curies_converter.compress(uri),
"pref_label": q[f"B{row}"].value,
"pl_language_code": split_and_tidy(q[f"C{row}"].value),
"definition": q[f"D{row}"].value,
Expand All @@ -92,7 +93,7 @@ def extract_concepts_and_collections(
row = cell.row
if cell.value is None or cell.value in header_names_to_skip:
continue
uri = r[f"A{row}"].value.strip()
uri = r[f"A{row}"].value.split()[0].strip()
uri = prefix_converter.expand(uri) or uri
if uri in additional_concept_iris:
msg = f"Concept IRI {uri} used a second time in sheet {r} at row {row} but must be unique."
Expand Down Expand Up @@ -133,7 +134,7 @@ def extract_concepts_and_collections(
continue

data_collection = {
"uri": s[f"A{row}"].value,
"uri": s[f"A{row}"].value.split()[0].strip(),
"pref_label": s[f"B{row}"].value,
"definition": s[f"C{row}"].value,
"members": s[f"D{row}"].value,
Expand Down
21 changes: 16 additions & 5 deletions src/voc4cat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,14 @@ def to_excel(self, wb: Workbook, row_no_concepts: int, row_no_features: int) ->
fully_translated.insert(0, "en")

first_row_exported = False
if "ex" not in config.curies_converter.prefix_map:
config.curies_converter.add_prefix("ex", "https://example.org/")
for lang in chain(fully_translated, partially_translated):
ws[f"A{row_no_concepts}"] = config.curies_converter.compress(
ws[f"A{row_no_concepts}"].value = config.curies_converter.compress(
self.uri, passthrough=True
)
) # + f" ({pref_labels.get(lang, '')})" #
ws[f"A{row_no_concepts}"].hyperlink = self.uri
ws[f"A{row_no_concepts}"].style = "Hyperlink"
ws[f"B{row_no_concepts}"] = pref_labels.get(lang, "")
ws[f"C{row_no_concepts}"] = lang
ws[f"D{row_no_concepts}"] = definitions.get(lang, "")
Expand All @@ -426,6 +430,7 @@ def to_excel(self, wb: Workbook, row_no_concepts: int, row_no_features: int) ->
[
config.curies_converter.compress(uri, passthrough=True)
for uri in self.children
# TODO add pref_label of children but where to look up? Here we know just the current concept.
]
)
ws[f"I{row_no_concepts}"] = (
Expand All @@ -446,9 +451,11 @@ def to_excel(self, wb: Workbook, row_no_concepts: int, row_no_features: int) ->
]
):
ws = wb["Additional Concept Features"]
ws[f"A{row_no_features}"] = config.curies_converter.compress(
ws[f"A{row_no_features}"].value = config.curies_converter.compress(
self.uri, passthrough=True
)
) + f" ({pref_labels.get('en', '')})"
ws[f"A{row_no_features}"].hyperlink = self.uri
ws[f"A{row_no_features}"].style = "Hyperlink"
ws[f"B{row_no_features}"] = ",\n".join(
[
config.curies_converter.compress(uri, passthrough=True)
Expand Down Expand Up @@ -524,7 +531,11 @@ def to_graph(self, cs):

def to_excel(self, wb: Workbook, row_no: int):
ws = wb["Collections"]
ws[f"A{row_no}"] = config.curies_converter.compress(self.uri, passthrough=True)
ws[f"A{row_no}"].value = config.curies_converter.compress(
self.uri, passthrough=True
) # + f" ({self.pref_label})"
ws[f"A{row_no}"].hyperlink = self.uri
ws[f"A{row_no}"].style = "Hyperlink"
ws[f"B{row_no}"] = self.pref_label
ws[f"C{row_no}"] = self.definition
ws[f"D{row_no}"] = ",\n".join(
Expand Down

0 comments on commit 3a349e9

Please sign in to comment.