Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest SSSOM(v0.4.x) #681

Closed
wants to merge 3 commits into from
Closed
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
2,907 changes: 1,175 additions & 1,732 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ linkml-runtime = ">=1.5.3"
linkml-renderer = ">=0.3.0"
networkx = ">=2.7.1"
sssom-schema = ">=0.11.0"
sssom = ">=0.3.38"
sssom = "0.4.0rc1"
ratelimit = ">=2.2.1"
appdirs = ">=1.4.4"
semsql = ">=0.3.1"
lark = ">=1.1.2"
kgcl-schema = "0.6.0"
kgcl-schema = ">=0.6.0"
funowl = ">=0.2.0"
gilda = {version = ">=1.0.0", optional = true}
kgcl-rdflib = "0.5.0"
Expand All @@ -37,7 +37,7 @@ pysolr = "^3.9.0"
eutils = ">=0.6.0"
requests-cache = "^1.0.1"
click = "*"
semsimian = "0.2.1"
semsimian = ">=0.2.10"
urllib3 = {version = "< 2", optional = true}
pydantic = "*"

Expand Down
2 changes: 2 additions & 0 deletions src/oaklib/datamodels/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
URL_PREDICATE = "schema:url"
PREFIX_PREDICATE = "sh:prefix"

CURIE_MAP_KEY = "curie_map"

# TODO: replace with oio vocab
LABEL_PREDICATE = omd.slots.label.curie
HAS_EXACT_SYNONYM = omd.slots.has_exact_synonym.curie
Expand Down
34 changes: 21 additions & 13 deletions src/oaklib/utilities/lexical/lexical_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from pathlib import Path
from typing import Collection, Dict, List, Optional, Tuple, Union

import curies
from curies import Converter
from linkml_runtime.dumpers import json_dumper, yaml_dumper
from linkml_runtime.loaders import json_loader, yaml_loader
from linkml_runtime.utils.metamodelcore import URIorCURIE
from sssom.constants import LICENSE, MAPPING_SET_ID
from sssom.context import get_default_metadata
from sssom.constants import LICENSE, MAPPING_SET_ID, MetadataType, get_default_metadata
from sssom.context import ensure_converter
from sssom.sssom_document import MappingSetDocument
from sssom.typehints import Metadata
from sssom.util import MappingSetDataFrame, to_mapping_set_dataframe
from sssom_schema import Mapping, MappingSet

Expand All @@ -35,6 +36,7 @@
Synonymizer,
)
from oaklib.datamodels.vocabulary import (
CURIE_MAP_KEY,
IDENTIFIER_PREDICATE,
SEMAPV,
SKOS_BROAD_MATCH,
Expand Down Expand Up @@ -244,7 +246,7 @@ def lexical_index_to_sssom(
oi: BasicOntologyInterface,
lexical_index: LexicalIndex,
ruleset: MappingRuleCollection = None,
meta: Metadata = None,
metadata: MetadataType = None,
prefix_map: dict = None,
subjects: Collection[CURIE] = None,
objects: Collection[CURIE] = None,
Expand Down Expand Up @@ -310,18 +312,24 @@ def lexical_index_to_sssom(
# mappings.append(create_mapping(oi, term, r1, r2))
logging.info("Done creating SSSOM mappings")

if meta is None:
meta = get_default_metadata()
if prefix_map:
meta.prefix_map.update(
{k: v for k, v in prefix_map.items() if k not in meta.prefix_map.keys()}
)
mapping_set_id = meta.metadata[MAPPING_SET_ID]
license = meta.metadata[LICENSE]
if metadata is None:
metadata = get_default_metadata()

converter = curies.chain(
[
Converter.from_prefix_map(metadata.pop(CURIE_MAP_KEY, {})),
ensure_converter(prefix_map, use_defaults=False),
]
)
metadata.setdefault(CURIE_MAP_KEY, {}).update(converter.prefix_map)

mapping_set_id = metadata[MAPPING_SET_ID]
license = metadata[LICENSE]

mset = MappingSet(mapping_set_id=mapping_set_id, mappings=mappings, license=license)
# doc = MappingSetDocument(prefix_map=oi.prefix_map(), mapping_set=mset)
doc = MappingSetDocument(prefix_map=meta.prefix_map, mapping_set=mset)

doc = MappingSetDocument(converter=converter, mapping_set=mset)
msdf = to_mapping_set_dataframe(doc)
num_mappings = len(msdf.df.index)
if ensure_strict_prefixes:
Expand Down
17 changes: 12 additions & 5 deletions src/oaklib/utilities/mapping/sssom_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from dataclasses import dataclass, field
from typing import Iterable, List, Optional, Tuple

import curies
from linkml_runtime.utils.metamodelcore import URIorCURIE
from sssom.context import ensure_converter
from sssom.sssom_document import MappingSetDocument
from sssom.util import to_mapping_set_dataframe
from sssom.writers import write_table
Expand Down Expand Up @@ -77,11 +79,16 @@ def finish(self):
mset = MappingSet(
mapping_set_id="temp", mappings=self.mappings, license=UNSPECIFIED_MAPPING_SET_ID
)
if self.ontology_interface:
prefix_map = self.ontology_interface.prefix_map()
else:
prefix_map = {}
doc = MappingSetDocument(prefix_map=prefix_map, mapping_set=mset)

converter = (
curies.chain(
[ensure_converter(self.ontology_interface.prefix_map(), use_defaults=False)]
)
if self.ontology_interface
else None
)

doc = MappingSetDocument(converter=converter, mapping_set=mset)
msdf = to_mapping_set_dataframe(doc)
msdf.clean_prefix_map(strict=False)
write_table(msdf, self.file)
10 changes: 8 additions & 2 deletions tests/test_utilities/test_sssom_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ def test_sssom_with_rules_file(self):
lexical_index = create_lexical_index(oi)
add_labels_from_uris(oi)
ruleset = load_mapping_rules(str(RULES))
metadata = get_metadata_and_prefix_map(MATCHER_META_YML)
msdf = lexical_index_to_sssom(self.oi, lexical_index, ruleset=ruleset, meta=metadata)
converter, metadata = get_metadata_and_prefix_map(MATCHER_META_YML)
msdf = lexical_index_to_sssom(
self.oi,
lexical_index,
ruleset=ruleset,
metadata=metadata,
prefix_map=converter.prefix_map,
)
with open(MATCHER_TEST_SSSOM_OUT, "w", encoding="utf-8") as file:
write_table(msdf, file)
msdoc = to_mapping_set_document(msdf)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ deps =
coverage
semsimian
gilda
linkml

[testenv:lint]
deps =
Expand Down