Skip to content

Commit c545ef7

Browse files
committed
Update rest
1 parent 054671f commit c545ef7

5 files changed

Lines changed: 41 additions & 35 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ docs = [
8585
"texext",
8686
]
8787
biomappings = [
88-
"biomappings>=0.4.0",
88+
"biomappings>=0.4.1",
8989
]
9090
web = [
9191
"semra[biomappings]",

src/semra/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def summarize_concepts(self) -> t.Counter[tuple[str, str]]:
379379
query = "MATCH (e:concept) WHERE e.prefix <> 'orcid' RETURN e.prefix, count(e.prefix)"
380380
return Counter(
381381
{
382-
(prefix, t.cast(str, bioregistry.get_name(prefix))): count
382+
(prefix, bioregistry.get_name(prefix, strict=True)): count
383383
for prefix, count in self.read_query(query)
384384
}
385385
)

src/semra/web/flask_components.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import typing as t
66
from typing import cast
77

8-
import bioregistry
98
import flask
109
import werkzeug
10+
from bioregistry import NormalizedNamableReference
1111
from curies import Reference
1212
from flask import Blueprint, current_app, render_template
1313

14+
from semra import EXACT_MATCH
1415
from semra.client import BaseClient
1516
from semra.web.shared import State, _figure_number
1617

18+
if t.TYPE_CHECKING:
19+
import biomappings.resources
20+
1721
__all__ = [
1822
"flask_blueprint",
1923
"index_biomapping",
@@ -86,31 +90,27 @@ def mark_exact_incorrect(source: str, target: str) -> werkzeug.Response:
8690
return flask.redirect(flask.url_for(view_concept.__name__, curie=source))
8791

8892
client = _flask_get_client()
93+
state = _flask_get_state()
8994

9095
import biomappings.resources
91-
from biomappings.wsgi import _manual_source
92-
93-
source_reference = Reference.from_curie(source)
94-
target_reference = Reference.from_curie(target)
95-
96-
mapping: dict[str, str] = {
97-
"source prefix": source_reference.prefix,
98-
"source identifier": source_reference.identifier,
99-
"target prefix": target_reference.prefix,
100-
"target identifier": target_reference.identifier,
101-
"relation": "skos:exactMatch",
102-
"type": "semapv:ManualMappingCuration",
103-
"source": _manual_source(),
104-
"prediction_type": "",
105-
"prediction_source": "semra",
106-
"prediction_confidence": "",
107-
}
108-
if source_name := client.get_concept_name(source):
109-
mapping["source name"] = source_name
110-
if target_name := client.get_concept_name(target):
111-
mapping["target name"] = target_name
112-
113-
mapping = biomappings.resources._standardize_mapping(mapping)
96+
from biomappings.utils import MANUAL_MAPPING_CURATION
97+
98+
subject = NormalizedNamableReference.from_curie(source, name=client.get_concept_name(source))
99+
target_reference = NormalizedNamableReference.from_curie(
100+
target, name=client.get_concept_name(target)
101+
)
102+
103+
mapping = biomappings.resources.SemanticMapping.model_validate(
104+
{
105+
"subject": subject,
106+
"predicate": EXACT_MATCH,
107+
"object": target_reference,
108+
"mapping_justification": MANUAL_MAPPING_CURATION,
109+
"author": state.current_author,
110+
"mapping_tool": "semra",
111+
}
112+
)
113+
114114
biomappings.resources.append_false_mappings([mapping])
115115
index_biomapping(_flask_get_false_mapping_index(), mapping)
116116

@@ -152,15 +152,12 @@ def _flask_get_false_mapping_index() -> set[tuple[str, str]]:
152152

153153

154154
def index_biomapping(
155-
mapping_index: set[tuple[str, str]], mapping_dict: t.Mapping[str, str]
155+
mapping_index: set[tuple[str, str]], mapping: biomappings.resources.SemanticMapping
156156
) -> None:
157157
"""Index a mapping from biomappings."""
158-
if mapping_dict["relation"] != "skos:exactMatch":
158+
if mapping.predicate.curie != "skos:exactMatch":
159159
return
160-
sp, si = mapping_dict["source prefix"], mapping_dict["source identifier"]
161-
tp, ti = mapping_dict["target prefix"], mapping_dict["target identifier"]
162-
si = bioregistry.standardize_identifier(sp, si)
163-
ti = bioregistry.standardize_identifier(tp, ti)
164-
s, t = f"{sp}:{si}", f"{tp}:{ti}"
165-
mapping_index.add((s, t))
166-
mapping_index.add((t, s))
160+
subject_curie = mapping.subject.curie
161+
object_curie = mapping.object.curie
162+
mapping_index.add((subject_curie, object_curie))
163+
mapping_index.add((object_curie, subject_curie))

src/semra/web/shared.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from dataclasses import dataclass, field
66

7+
from bioregistry import NormalizedNamedReference
8+
79
from semra.client import BaseClient, ExampleMapping, FullSummary
810

911
__all__ = [
@@ -22,6 +24,7 @@ class State:
2224
summary: FullSummary
2325
biomappings_hash: str | None = None
2426
false_mapping_index: set[tuple[str, str]] = field(default_factory=set)
27+
current_author: NormalizedNamedReference | None = None
2528

2629
def example_mappings(self) -> list[ExampleMapping]:
2730
"""Extract example mappings."""

src/semra/wsgi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Literal, overload
77

88
import fastapi
9+
from bioregistry import NormalizedNamedReference
910
from flask import Flask
1011
from flask_bootstrap import Bootstrap5
1112
from starlette.middleware.wsgi import WSGIMiddleware
@@ -45,9 +46,11 @@ def get_app(
4546

4647
biomappings_git_hash: str | None = None
4748
false_mapping_index: set[tuple[str, str]] = set()
49+
current_author: NormalizedNamedReference | None = None
4850

4951
if use_biomappings:
5052
try:
53+
import biomappings.resources
5154
import biomappings.utils
5255
except ImportError:
5356
pass
@@ -56,11 +59,14 @@ def get_app(
5659
for m in biomappings.load_false_mappings():
5760
index_biomapping(false_mapping_index, m)
5861

62+
current_author = biomappings.resources.get_current_curator(strict=True)
63+
5964
state = State(
6065
client=client,
6166
summary=client.get_full_summary(),
6267
false_mapping_index=false_mapping_index,
6368
biomappings_hash=biomappings_git_hash,
69+
current_author=current_author,
6470
)
6571

6672
flask_app = Flask(__name__)

0 commit comments

Comments
 (0)