Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/test/term_info_queries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,27 @@ def test_label_stray_backslash_cleaned(self):
"short_form": "VFB_jrchk0e3", "unique_facets": ["Adult"],
"label": "MBON01(y5β\\'2a)_L"}, "description": [], "comment": []},
"query": "Get JSON for Individual", "version": "t", "parents": [],
"relationships": [], "xrefs": [], "anatomy_channel_image": [],
"pub_syn": [], "def_pubs": []}
"relationships": [{"relation": {"iri": "i", "label": "is part\\'of",
"type": "part_of"}, "object": {"symbol": "", "iri": "i",
"types": ["Class"], "short_form": "FBbt_1", "unique_facets": [],
"label": "adult brain"}}],
"xrefs": [], "anatomy_channel_image": [],
"pub_syn": [{"synonym": {"scope": "has_exact_synonym",
"label": "MBON01(y5β\\'2a)_syn", "type": ""},
"pub": {"core": {"symbol": "", "iri": "i", "types": ["pub"],
"short_form": "Unattributed", "unique_facets": ["pub"], "label": ""},
"FlyBase": "", "PubMed": "", "DOI": ""}}], "def_pubs": []}
'''
terminfo = deserialize_term_info(terminfo_json)
# backslash stripped, apostrophe and Greek beta preserved
self.assertEqual("MBON01(y5β'2a)_L", terminfo.term.core.label)
self.assertNotIn("\\", terminfo.term.core.label)
# and it flows clean into the internal link (used for Name/Meta rendering)
self.assertNotIn("\\", terminfo.term.core.get_int_link())
# synonyms and relationship (edge) labels are cleaned too
self.assertEqual("MBON01(y5β'2a)_syn", terminfo.pub_syn[0].synonym.label)
self.assertNotIn("\\", terminfo.pub_syn[0].synonym.label)
self.assertNotIn("\\", terminfo.relationships[0].relation.label)

def test_term_info_deserialization(self):
terminfo_json = """
Expand Down
8 changes: 8 additions & 0 deletions src/vfbquery/term_info_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class MinimalEdgeInfo:
confidence_value: Optional[str] = ""
database_cross_reference: Optional[List[str]] = None

def __post_init__(self):
self.label = clean_label(self.label)


@dataclass_json
@dataclass
Expand All @@ -141,6 +144,11 @@ class Synonym:
scope: Optional[str] = ""
type: Optional[str] = ""

def __post_init__(self):
# Synonyms carry the same over-escaping artifact as labels (e.g. a
# synonym "y5B\\'2a"); clean at ingestion so search/term-info render clean.
self.label = clean_label(self.label)

def __str__(self):
if self.scope:
return re.sub(r"([^_A-Z])([A-Z])", r"\1 \2", self.scope).replace("has ", "") + ": " + self.label
Expand Down
Loading