Skip to content

Commit 0c05ff1

Browse files
authored
Fix support for literal mappings. (#624)
Since the LinkML-generated Mapping class does not, in itself, validates the post-conditions specified in the schema, it cannot validate that a Mapping object is created with either a subject_id or (if subject_type is `rdfs literal`) a subject_label (likewise for the object side). Instead, that validation is performed by custom code executed as part of the parsing code. However, the present validation is bogus because the check on the value of `subject_type` and `object_type` is trying to compare the value of the slot to a literal string, instead of a EntityTypeEnum object. We fix that comparison here.
1 parent 8434006 commit 0c05ff1

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/sssom/parsers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from linkml_runtime.loaders.rdflib_loader import RDFLibLoader
4343
from pandas.errors import EmptyDataError
4444
from rdflib import Graph
45-
from sssom_schema import Mapping, MappingSet
45+
from sssom_schema import EntityTypeEnum, Mapping, MappingSet
4646
from typing_extensions import Literal, TypeAlias
4747

4848
from sssom.constants import (
@@ -1187,12 +1187,12 @@ def _ensure_valid_mapping_from_dict(mdict: Dict[str, Any]) -> Optional[Mapping]:
11871187

11881188
try:
11891189
m = Mapping(**mdict)
1190-
if m.subject_type == "rdfs literal":
1190+
if m.subject_type == EntityTypeEnum(EntityTypeEnum["rdfs literal"]):
11911191
if m.subject_label is None:
11921192
raise ValueError("Missing subject_label")
11931193
elif m.subject_id is None:
11941194
raise ValueError("Missing subject_id")
1195-
if m.object_type == "rdfs literal":
1195+
if m.object_type == EntityTypeEnum(EntityTypeEnum["rdfs literal"]):
11961196
if m.object_label is None:
11971197
raise ValueError("Missing object_label")
11981198
elif m.object_id is None:

tests/data/literals.sssom.tsv

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#curie_map:
2+
# FBcv: http://purl.obolibrary.org/obo/FBcv_
3+
# ORCID: https://orcid.org/
4+
# obo: http://purl.obolibrary.org/obo/
5+
#mapping_set_id: http://purl.obolibrary.org/obo/fbcv/agr-vocabs.sssom.tsv
6+
#mapping_set_description: Mappings between the FlyBase Controlled Vocabulary (FBcv) and vocabulary terms from the Alliance of Genome Resources.
7+
#creator_id:
8+
# - ORCID:0000-0002-6095-8718
9+
#license: https://creativecommons.org/licenses/by/4.0/
10+
subject_id subject_label predicate_id object_label object_category mapping_justification subject_source object_type
11+
FBcv:0000222 male skos:exactMatch male Genetic Sex semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
12+
FBcv:0000334 female skos:exactMatch female Genetic Sex semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
13+
FBcv:0003124 species study skos:exactMatch species Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
14+
FBcv:0003125 strain study skos:exactMatch genome variation Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
15+
FBcv:0003127 developmental stage study skos:exactMatch developmental stage Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
16+
FBcv:0003128 circadian rhythm study skos:narrowMatch time of day Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
17+
FBcv:0003129 cell cycle study skos:exactMatch cell cycle Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
18+
FBcv:0003130 tissue type study skos:narrowMatch anatomical structure Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal
19+
FBcv:0003131 cell type study skos:exactMatch cell type Data Set Category Tags semapv:ManualMappingCuration obo:fbcv.owl rdfs literal

tests/test_parsers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ def test_parse_tsv(self) -> None:
147147
f"{self.df_file} has the wrong number of mappings.",
148148
)
149149

150+
def test_parse_tsv_with_literal_mappings(self) -> None:
151+
"""Test parsing a SSSOM/TSV file containing literal mappings."""
152+
msdf = parse_sssom_table(f"{test_data_dir}/literals.sssom.tsv")
153+
self.assertEqual(len(msdf.df), 9, "literals.sssom.tsv has the wrong number of mappings.")
154+
150155
def test_parse_alignment_minidom(self) -> None:
151156
"""Test parsing an alignment XML."""
152157
msdf = from_alignment_minidom(

0 commit comments

Comments
 (0)