Skip to content

Commit

Permalink
Only add IRI with mapping to AdditionalConceptFeatures
Browse files Browse the repository at this point in the history
completes work on #241
  • Loading branch information
dalito committed Jan 25, 2025
1 parent 371e5e7 commit 60ddd87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
19 changes: 15 additions & 4 deletions src/voc4cat/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def rdf_to_excel(
file_to_convert_path: Path,
output_file_path: Path | None = None,
template_file_path: Path | None = None,
) -> None:
) -> Path:
if not file_to_convert_path.name.endswith(tuple(RDF_FILE_ENDINGS.keys())):
msg = "Files for conversion to Excel must end with one of the RDF file formats: '{}'".format(
"', '".join(RDF_FILE_ENDINGS.keys())
Expand Down Expand Up @@ -254,7 +254,7 @@ def rdf_to_excel(
for s, o in g.subject_objects(SKOS.broader):
g.add((o, SKOS.narrower, s))

row_no_features, row_no_concepts = 3, 3
row_no_concepts, row_no_features = 3, 3
for s in g.subjects(RDF.type, SKOS.Concept):
holder = {
"uri": str(s),
Expand Down Expand Up @@ -319,8 +319,19 @@ def rdf_to_excel(
narrow_match=holder["narrow_match"],
broad_match=holder["broad_match"],
vocab_name=vocab_name,
).to_excel(wb, row_no_features, row_no_concepts)
row_no_features += 1
).to_excel(wb, row_no_concepts, row_no_features)
row_no_concepts += 1
# only go to next row in "Additional Concepts Features" if there are any mappings
if any(
[
holder["related_match"],
holder["close_match"],
holder["exact_match"],
holder["narrow_match"],
holder["broad_match"],
]
):
row_no_features += 1

row_no = 3

Expand Down
73 changes: 37 additions & 36 deletions src/voc4cat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def to_graph(self):

return g

def to_excel(self, wb: Workbook, row_no_features: int, row_no_concepts: int):
def to_excel(self, wb: Workbook, row_no_concepts: int, row_no_features: int) -> int:
""" "
Export Concept to Excel using one row per language
Expand Down Expand Up @@ -433,41 +433,42 @@ def to_excel(self, wb: Workbook, row_no_features: int, row_no_concepts: int):
)
row_no_concepts += 1

ws = wb["Additional Concept Features"]

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, passthrough=True)
for uri in self.related_match
]
)
ws[f"C{row_no_features}"] = ",\n".join(
[
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, passthrough=True)
for uri in self.exact_match
]
)
ws[f"E{row_no_features}"] = ",\n".join(
[
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, passthrough=True)
for uri in self.broad_match
]
)
# Fill Additional Concept Features sheet
if any([self.related_match, self.close_match, self.exact_match, self.narrow_match, self.broad_match]):
ws = wb["Additional Concept Features"]
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, passthrough=True)
for uri in self.related_match
]
)
ws[f"C{row_no_features}"] = ",\n".join(
[
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, passthrough=True)
for uri in self.exact_match
]
)
ws[f"E{row_no_features}"] = ",\n".join(
[
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, passthrough=True)
for uri in self.broad_match
]
)

return row_no_concepts

Expand Down

0 comments on commit 60ddd87

Please sign in to comment.