|
5 | 5 | import typing as t |
6 | 6 | from typing import cast |
7 | 7 |
|
8 | | -import bioregistry |
9 | 8 | import flask |
10 | 9 | import werkzeug |
| 10 | +from bioregistry import NormalizedNamableReference |
11 | 11 | from curies import Reference |
12 | 12 | from flask import Blueprint, current_app, render_template |
13 | 13 |
|
| 14 | +from semra import EXACT_MATCH |
14 | 15 | from semra.client import BaseClient |
15 | 16 | from semra.web.shared import State, _figure_number |
16 | 17 |
|
| 18 | +if t.TYPE_CHECKING: |
| 19 | + import biomappings.resources |
| 20 | + |
17 | 21 | __all__ = [ |
18 | 22 | "flask_blueprint", |
19 | 23 | "index_biomapping", |
@@ -86,31 +90,27 @@ def mark_exact_incorrect(source: str, target: str) -> werkzeug.Response: |
86 | 90 | return flask.redirect(flask.url_for(view_concept.__name__, curie=source)) |
87 | 91 |
|
88 | 92 | client = _flask_get_client() |
| 93 | + state = _flask_get_state() |
89 | 94 |
|
90 | 95 | 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 | + |
114 | 114 | biomappings.resources.append_false_mappings([mapping]) |
115 | 115 | index_biomapping(_flask_get_false_mapping_index(), mapping) |
116 | 116 |
|
@@ -152,15 +152,12 @@ def _flask_get_false_mapping_index() -> set[tuple[str, str]]: |
152 | 152 |
|
153 | 153 |
|
154 | 154 | 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 |
156 | 156 | ) -> None: |
157 | 157 | """Index a mapping from biomappings.""" |
158 | | - if mapping_dict["relation"] != "skos:exactMatch": |
| 158 | + if mapping.predicate.curie != "skos:exactMatch": |
159 | 159 | 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)) |
0 commit comments