Skip to content

Commit 4c13e89

Browse files
committed
Implement our own (de)serialisation to/from RDF.
Since the normalised variant of SSSOM/RDF does not match the output produced (respectively expected) by the LinkML runtime's dumper (resp. loader), we implement our own serialisation/deserialisation routines for RDF. All the code for RDF import/export is contained within the sssom.rdf_internal module. The main class expected to be used outside of that module is the MappingSetRDFConverter class. The `from_sssom_rdf` and `to_rdf_graph` methods in the sssom.parsers and sssom.writers module are rewritten to use the new converter.
1 parent 427f6e8 commit 4c13e89

File tree

4 files changed

+896
-30
lines changed

4 files changed

+896
-30
lines changed

src/sssom/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
MATCH_STRING = "match_string"
121121
SUBJECT_PREPROCESSING = "subject_preprocessing"
122122
OBJECT_PREPROCESSING = "object_preprocessing"
123+
RECORD_ID = "record_id"
123124
SEMANTIC_SIMILARITY_SCORE = "semantic_similarity_score"
124125
SEMANTIC_SIMILARITY_MEASURE = "semantic_similarity_measure"
125126
SEE_ALSO = "see_also"
@@ -136,6 +137,8 @@
136137
# see <https://mapping-commons.github.io/sssom/spec-model/#representing-unmapped-entities>
137138
NO_TERM_FOUND = "sssom:NoTermFound"
138139

140+
ENTITY_TYPE_RDFS_LITERAL = "rdfs literal"
141+
139142
# PREDICATES
140143
OWL_EQUIVALENT_CLASS = "owl:equivalentClass"
141144
OWL_EQUIVALENT_PROPERTY = "owl:equivalentProperty"

src/sssom/parsers.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
get_filter_df_by_prefixes_index,
4040
)
4141
from linkml_runtime.loaders.json_loader import JSONLoader
42-
from linkml_runtime.loaders.rdflib_loader import RDFLibLoader
4342
from pandas.errors import EmptyDataError
4443
from rdflib import Graph
4544
from sssom_schema import EntityTypeEnum, Mapping, MappingSet
@@ -80,6 +79,7 @@
8079
)
8180

8281
from .context import ConverterHint, _get_built_in_prefix_map, ensure_converter
82+
from .rdf_internal import MappingSetRDFConverter
8383
from .sssom_document import MappingSetDocument
8484
from .util import (
8585
SSSOM_DEFAULT_RDF_SERIALISATION,
@@ -617,34 +617,23 @@ def from_sssom_rdf(
617617
:returns: MappingSetDataFrame object
618618
"""
619619
converter = ensure_converter(prefix_map)
620-
mapping_set = cast(
621-
MappingSet,
622-
RDFLibLoader().load(
623-
source=g,
624-
target_class=MappingSet,
625-
schemaview=_get_sssom_schema_object().view,
626-
prefix_map=converter.bimap,
627-
ignore_unmapped_predicates=True,
628-
),
629-
)
630620

631621
# The priority order for combining metadata is:
632622
# 1. Metadata appearing in the SSSOM document
633623
# 2. Metadata passed through ``meta`` to this function
634624
# 3. Default metadata
635625

636-
# As the Metadata appearing in the SSSOM document is already parsed by LinkML
637-
# we only need to overwrite the metadata from 2 and 3 if it is not present
626+
# We prepare a default dictionary with (2) and (3), which will be
627+
# automatically combined with the metadata extracted from the RDF
628+
# graph by the RDF converter.
638629
combine_meta = dict(
639630
ChainMap(
640631
meta or {},
641632
get_default_metadata(),
642633
)
643634
)
644635

645-
_set_metadata_in_mapping_set(mapping_set, metadata=combine_meta, overwrite=False)
646-
mdoc = MappingSetDocument(mapping_set=mapping_set, converter=converter)
647-
return to_mapping_set_dataframe(mdoc)
636+
return MappingSetRDFConverter.from_rdf(g, curie_converter=converter, default_meta=combine_meta)
648637

649638

650639
def from_sssom_json(

0 commit comments

Comments
 (0)