Skip to content

Commit 2c4edc8

Browse files
authored
Fix bacdive enum YAML generation edge cases
1 parent 55434b0 commit 2c4edc8

2 files changed

Lines changed: 51 additions & 7 deletions

File tree

metpo/tools/make_bacdive_utilization_enum.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def convert_tsv_to_linkml(
7373
# Show preview if requested
7474
if preview:
7575
click.echo("\n=== Preview (first 30 lines) ===")
76-
preview_lines = linkml_yaml.split("\n")[:30]
76+
all_lines = linkml_yaml.split("\n")
77+
preview_lines = all_lines[:30]
7778
click.echo("\n".join(preview_lines))
78-
if len(linkml_yaml.split("\n")) > 30:
79+
if len(all_lines) > 30:
7980
click.echo("...")
8081

8182
except Exception as e:
@@ -125,9 +126,8 @@ def convert_tsv_to_linkml_enum(
125126

126127
# Process each relationship
127128
for _, row in object_properties.iterrows():
128-
# Extract the ID number from the full URI
129+
# Use the full URI as the permissible value meaning
129130
id_uri = row["ID"]
130-
id_uri.split("/")[-1]
131131

132132
# Create a code-friendly key from the label
133133
label = str(row["LABEL"])
@@ -148,9 +148,6 @@ def convert_tsv_to_linkml_enum(
148148
linkml_enum, default_flow_style=False, sort_keys=False, allow_unicode=True
149149
)
150150

151-
# Clean up the YAML formatting
152-
yaml_output = yaml_output.replace("'", "") # Remove unnecessary quotes
153-
154151
# Write to file if specified
155152
if output_file:
156153
with Path(output_file).open("w") as f:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Tests for make_bacdive_utilization_enum utility."""
2+
3+
import yaml
4+
5+
from metpo.tools.make_bacdive_utilization_enum import convert_tsv_to_linkml_enum
6+
7+
8+
def _write_tsv(tmp_path, data_rows):
9+
tsv_path = tmp_path / "bacdive.tsv"
10+
content = [
11+
"ID\tTYPE\tLABEL\tbacdive count",
12+
"ID\tTYPE\tLABEL\tA",
13+
]
14+
content.extend(data_rows)
15+
tsv_path.write_text("\n".join(content) + "\n", encoding="utf-8")
16+
return tsv_path
17+
18+
19+
def test_preserves_apostrophes_in_yaml_values(tmp_path):
20+
tsv_path = _write_tsv(
21+
tmp_path,
22+
[
23+
"https://example.org/relationship/1\towl:ObjectProperty\tdoesn't utilize\t1",
24+
],
25+
)
26+
27+
yaml_output = convert_tsv_to_linkml_enum(str(tsv_path), enum_name="RelationshipTypeEnum")
28+
parsed = yaml.safe_load(yaml_output)
29+
30+
permissible_values = parsed["enums"]["RelationshipTypeEnum"]["permissible_values"]
31+
assert "doesn't_utilize" in permissible_values
32+
33+
34+
def test_permissible_value_meaning_uses_full_uri(tmp_path):
35+
uri = "https://example.org/relationship/123"
36+
tsv_path = _write_tsv(
37+
tmp_path,
38+
[
39+
f"{uri}\towl:ObjectProperty\tutilizes carbon source\t1",
40+
],
41+
)
42+
43+
yaml_output = convert_tsv_to_linkml_enum(str(tsv_path), enum_name="RelationshipTypeEnum")
44+
parsed = yaml.safe_load(yaml_output)
45+
46+
entry = parsed["enums"]["RelationshipTypeEnum"]["permissible_values"]["utilizes_carbon_source"]
47+
assert entry["meaning"] == uri

0 commit comments

Comments
 (0)