Skip to content

Commit 23a8599

Browse files
committed
Add tests for the infer_cardinality method.
1 parent 697922b commit 23a8599

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#curie_map:
2+
# COMENT: https://example.com/entities/
3+
# NETENT: https://example.net/entities/
4+
# ORGENT: https://example.org/entities/
5+
# SRC: https://example.org/sources/
6+
#mapping_set_id: https://example.org/sets/cardinality-scope-empty
7+
#license: https://creativecommons.org/licenses/by/4.0/
8+
subject_id subject_label predicate_id object_id object_label mapping_justification object_source mapping_cardinality
9+
ORGENT:0001 alice skos:closeMatch COMENT:0011 alpha semapv:ManualMappingCuration SRC:com 1:n
10+
ORGENT:0001 alice skos:closeMatch NETENT:0111 alpha semapv:ManualMappingCuration SRC:net 1:n
11+
ORGENT:0002 bob skos:closeMatch COMENT:0012 beta semapv:ManualMappingCuration SRC:com 1:n
12+
ORGENT:0002 bob skos:closeMatch NETENT:0112 bravo semapv:ManualMappingCuration SRC:net 1:n
13+
ORGENT:0007 gavin skos:closeMatch NETENT:0117 golf semapv:ManualMappingCuration SRC:net 1:n
14+
ORGENT:0007 gavin skos:exactMatch COMENT:0013 gamma semapv:ManualMappingCuration SRC:com 1:n
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#curie_map:
2+
# OBJ: https://example.org/object/
3+
# SRC: https://example.org/sources/
4+
# SUBJ: https://example.org/subject/
5+
#mapping_set_id: https://example.org/sets/cardinality-with-unmapped-entities
6+
#license: https://creativecommons.org/licenses/by/4.0/
7+
subject_id predicate_id object_id mapping_justification subject_source object_source mapping_cardinality comment
8+
SUBJ:0001 skos:exactMatch sssom:NoTermFound semapv:ManualMappingCuration SRC:A SRC:B 1:0 S1 in vocabulary A has no exact match in vocabulary B
9+
SUBJ:0001 skos:closeMatch OBJ:0001 semapv:ManualMappingCuration SRC:A SRC:B 1:1 S1 mapped only to O1, O1 mapped only to S1 -- the record involving sssom:NoTermFound does not count, as it is an absence of match rather than an actual mapping
10+
sssom:NoTermFound skos:exactMatch OBJ:0002 semapv:ManualMappingCuration SRC:C SRC:D 0:1 O2 in vocabulary D has no exact match in vocabulary C
11+
sssom:NoTermFound skos:exactMatch sssom:NoTermFound semapv:ManualMappingCuration SRC:E SRC:F 0:0 No exact match between any term from vocabulary E and any term for vocabulary F (in other words, the two vocabularies are completely disjoint, at least as far as exact matches are considered)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#curie_map:
2+
# OBJ: https://example.org/object/
3+
# SUBJ: https://example.org/subject/
4+
#mapping_set_id: https://example.org/sets/cardinality-with-literal-mappings
5+
#license: https://creativecommons.org/licenses/by/4.0/
6+
subject_id predicate_id object_id object_label mapping_justification object_type mapping_cardinality comment
7+
SUBJ:0001 skos:exactMatch OBJ:0001 semapv:LexicalMatching 1:n S1 mapped to O1 (entity) and O1 (literal)
8+
SUBJ:0001 skos:exactMatch OBJ:0001 OBJ:0001 semapv:MappingReview rdfs literal 1:n S1 mapped to O1 (entity) and O1 (literal)

tests/data/cardinality.sssom.tsv

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#curie_map:
2+
# OBJ: https://example.org/object/
3+
# SUBJ: https://example.org/subject/
4+
#mapping_set_id: https://example.org/sets/cardinality
5+
#license: https://creativecommons.org/licenses/by/4.0/
6+
subject_id predicate_id object_id mapping_justification mapping_cardinality comment
7+
SUBJ:0001 skos:exactMatch OBJ:0001 semapv:LexicalMatching 1:1 S1 and O1 only mapped to each other
8+
SUBJ:0001 skos:exactMatch OBJ:0001 semapv:MappingReview 1:1 S1 and O1 only mapped to each other
9+
SUBJ:0002 skos:exactMatch OBJ:0002 semapv:LexicalMatching 1:n S2 mapped to both O2 and O3, O2 mapped only to S2
10+
SUBJ:0002 skos:exactMatch OBJ:0003 semapv:LexicalMatching 1:n S2 mapped to both O2 and O3, O3 mapped only to S2
11+
SUBJ:0003 skos:exactMatch OBJ:0004 semapv:LexicalMatching n:1 S3 and S4 both mapped to only O4
12+
SUBJ:0004 skos:exactMatch OBJ:0004 semapv:LexicalMatching n:1 S3 and S4 both mapped to only O4
13+
SUBJ:0005 skos:exactMatch OBJ:0005 semapv:LexicalMatching n:n S5 mapped to O5 and O6, O5 mapped to S5 and S6
14+
SUBJ:0005 skos:exactMatch OBJ:0006 semapv:LexicalMatching 1:n S5 mapped to O5 and O6, O6 mapped only to S5
15+
SUBJ:0006 skos:exactMatch OBJ:0005 semapv:LexicalMatching n:1 S6 mapped only to O5, O5 mapped to both S5 and S6

tests/test_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,30 @@ def test_propagation_fill_empty_mode(self) -> None:
595595
self.assertIn("mapping_tool", propagated_slots)
596596
self.assertNotIn("mapping_tool", msdf.metadata)
597597
self.assertEqual(2, len(msdf.df["mapping_tool"].unique()))
598+
599+
def test_infer_cardinality(self) -> None:
600+
"""Test cardinality computation."""
601+
602+
def _check_against_precomputed_values(filename):
603+
msdf = parse_sssom_table(f"{data_dir}/{filename}")
604+
# Expected values are already contained in the test file
605+
expected = list(msdf.df["mapping_cardinality"].values)
606+
msdf.df.drop(columns="mapping_cardinality", inplace=True)
607+
msdf.infer_cardinality()
608+
self.assertEqual(expected, list(msdf.df["mapping_cardinality"].values))
609+
610+
_check_against_precomputed_values("cardinality.sssom.tsv")
611+
_check_against_precomputed_values("cardinality-with-NoTermFound.sssom.tsv")
612+
_check_against_precomputed_values("cardinality-with-literal-mappings.sssom.tsv")
613+
614+
def test_infer_scoped_cardinality(self) -> None:
615+
"""Test cardinality computation with scopes."""
616+
msdf = parse_sssom_table(f"{data_dir}/cardinality-scope.sssom.tsv")
617+
618+
msdf.infer_cardinality(["predicate_id"])
619+
expected = ["1:n", "1:n", "1:n", "1:n", "1:1", "1:1"]
620+
self.assertEqual(expected, list(msdf.df["mapping_cardinality"].values))
621+
622+
msdf.infer_cardinality(["object_source"])
623+
expected = ["1:1", "1:1", "1:1", "1:1", "1:1", "1:1"]
624+
self.assertEqual(expected, list(msdf.df["mapping_cardinality"].values))

0 commit comments

Comments
 (0)