|
| 1 | +"""Test for merging MappingSetDataFrames.""" |
| 2 | + |
| 3 | +import unittest |
| 4 | + |
| 5 | +from sssom_schema import Mapping |
| 6 | + |
| 7 | +from sssom.context import get_converter |
| 8 | +from sssom.parsers import parse_sssom_table |
| 9 | +from sssom.util import MappingSetDataFrame |
| 10 | +from sssom.writers import write_table |
| 11 | + |
| 12 | + |
| 13 | +class TestSemraCompatibility(unittest.TestCase): |
| 14 | + """A test case for making sure the model works as intended.""" |
| 15 | + |
| 16 | + def test_basic_inference(self): |
| 17 | + """Test if instantiating Mapping() fails when required elements are missing.""" |
| 18 | + mdict_missing = dict( |
| 19 | + subject_id="ID:123" |
| 20 | + ) # This is missing object_id, predicate_id, mapping_justification |
| 21 | + |
| 22 | + import io |
| 23 | + |
| 24 | + import pandas as pd |
| 25 | + from semra.api import infer_chains, infer_reversible |
| 26 | + from semra.io import from_sssom_df, get_sssom_df |
| 27 | + |
| 28 | + data = [ |
| 29 | + ["UBERON:1", "skos:exactMatch", "FBbt:9"], |
| 30 | + ["UBERON:1", "skos:exactMatch", "WBbt:6"], |
| 31 | + ] |
| 32 | + |
| 33 | + df = pd.DataFrame(data=data, columns=["subject_id", "predicate_id", "object_id"]) |
| 34 | + |
| 35 | + mappings = from_sssom_df(df, mapping_set_name="test") |
| 36 | + mappings = infer_reversible(mappings, progress=False) |
| 37 | + mappings = infer_chains(mappings, progress=False) |
| 38 | + |
| 39 | + df = get_sssom_df(mappings) |
| 40 | + print(df) |
| 41 | + msdf = MappingSetDataFrame(df=df, converter=get_converter()) |
| 42 | + print(msdf.df) |
| 43 | + msdf.standardize_references() |
| 44 | + msdf.clean_prefix_map() |
| 45 | + with open("testout.sssom.tsv", "w", encoding="utf-8") as file: |
| 46 | + write_table(msdf=msdf, file=file) |
0 commit comments