Skip to content

Commit e535dbe

Browse files
authored
Merge pull request #7 from NCATSTranslator/trapi-2.0
Trapi 2.0.0-beta2 compliance (and fixes)
2 parents 24614e3 + 99c923e commit e535dbe

32 files changed

Lines changed: 368 additions & 178 deletions

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "uv_build"
44

55
[project]
66
name = "translator_tom"
7-
version = "2.0.0"
7+
version = "2.1.0"
88
description = "TRAPI Object Models: A performant python data model and centralized utilities for the Translator Reasoner API."
99
readme = "README.md"
1010
requires-python = ">=3.10"

‎src/translator_tom/v1_6/model_dicts/workflow_operations.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
OverlayComputeNgdParameters,
6262
OverlayFisherExactTestParameters,
6363
PlusOrMinus,
64-
SortResultNodeAttributeParameters,
6564
SortResultsEdgeAttributeParameters,
65+
SortResultsNodeAttributeParameters,
6666
SortResultsScoreParameters,
6767
TopOrBottom,
6868
)
@@ -169,10 +169,10 @@
169169
"OverlayFisherExactTestParametersDict",
170170
"OverlayFisherExactTestParametersDictUtil",
171171
"RunnerParametersDict",
172-
"SortResultNodeAttributeParametersDict",
173-
"SortResultNodeAttributeParametersDictUtil",
174172
"SortResultsEdgeAttributeParametersDict",
175173
"SortResultsEdgeAttributeParametersDictUtil",
174+
"SortResultsNodeAttributeParametersDict",
175+
"SortResultsNodeAttributeParametersDictUtil",
176176
"SortResultsScoreParametersDict",
177177
"SortResultsScoreParametersDictUtil",
178178
]
@@ -783,22 +783,22 @@ class OperationSortResultsEdgeAttributeDictUtil(BaseOperationDictUtil):
783783
_model = OperationSortResultsEdgeAttribute
784784

785785

786-
class SortResultNodeAttributeParametersDict(OperationParametersDict):
786+
class SortResultsNodeAttributeParametersDict(OperationParametersDict):
787787
node_attribute: str
788788
ascending_or_descending: AscendingOrDescending
789-
qnode_keys: list[QNodeID] | None
789+
qnode_keys: NotRequired[list[QNodeID] | None]
790790

791791

792-
class SortResultNodeAttributeParametersDictUtil(
793-
DictUtil[SortResultNodeAttributeParametersDict]
792+
class SortResultsNodeAttributeParametersDictUtil(
793+
DictUtil[SortResultsNodeAttributeParametersDict]
794794
):
795-
"""Utility methods for `SortResultNodeAttributeParametersDict`, mirroring the model."""
795+
"""Utility methods for `SortResultsNodeAttributeParametersDict`, mirroring the model."""
796796

797-
_model = SortResultNodeAttributeParameters
797+
_model = SortResultsNodeAttributeParameters
798798

799799
@staticmethod
800800
def qnode_keys_list(
801-
parameters: SortResultNodeAttributeParametersDict,
801+
parameters: SortResultsNodeAttributeParametersDict,
802802
) -> list[QNodeID]:
803803
"""Return a guaranteed list of qnode_keys, empty if it is not defined."""
804804
qnode_keys = parameters.get("qnode_keys")
@@ -807,7 +807,7 @@ def qnode_keys_list(
807807

808808
class OperationSortResultsNodeAttributeDict(BaseOperationDict):
809809
id: Literal["sort_results_node_attribute"]
810-
parameters: SortResultNodeAttributeParametersDict
810+
parameters: SortResultsNodeAttributeParametersDict
811811

812812

813813
class OperationSortResultsNodeAttributeDictUtil(BaseOperationDictUtil):

‎src/translator_tom/v1_6/models/workflow_operations.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"PlusOrMinus",
6969
"PlusOrMinusEnum",
7070
"RunnerParameters",
71-
"SortResultNodeAttributeParameters",
7271
"SortResultsEdgeAttributeParameters",
72+
"SortResultsNodeAttributeParameters",
7373
"SortResultsScoreParameters",
7474
"TopOrBottom",
7575
"TopOrBottomEnum",
@@ -714,15 +714,15 @@ class OperationSortResultsEdgeAttribute(BaseOperation):
714714
parameters: SortResultsEdgeAttributeParameters
715715

716716

717-
class SortResultNodeAttributeParameters(OperationParameters):
718-
"""Parameters for the SortResultNodeAttribute operation."""
717+
class SortResultsNodeAttributeParameters(OperationParameters):
718+
"""Parameters for the SortResultsNodeAttribute operation."""
719719

720720
node_attribute: Annotated[str, Field(examples=["normalized_google_distance"])]
721721
"""The name of the node attribute to order by."""
722722

723723
ascending_or_descending: AscendingOrDescending
724724

725-
qnode_keys: Annotated[list[QNodeID] | None, Field(examples=["[e01]"])]
725+
qnode_keys: Annotated[list[QNodeID] | None, Field(examples=["[e01]"])] = None
726726
"""This indicates if you only want to consider nodes with specific node_keys.
727727
728728
If not provided or empty, all nodes will be looked at.
@@ -744,7 +744,7 @@ class OperationSortResultsNodeAttribute(BaseOperation):
744744
"""
745745

746746
id: Literal["sort_results_node_attribute"]
747-
parameters: SortResultNodeAttributeParameters
747+
parameters: SortResultsNodeAttributeParameters
748748

749749

750750
class SortResultsScoreParameters(OperationParameters):

‎src/translator_tom/v1_6/validation/_workflow_operations.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
OverlayComputeJaccardParameters,
2828
OverlayComputeNgdParameters,
2929
OverlayFisherExactTestParameters,
30-
SortResultNodeAttributeParameters,
3130
SortResultsEdgeAttributeParameters,
31+
SortResultsNodeAttributeParameters,
3232
)
3333
from translator_tom.v1_6.validation._util import (
3434
Location,
@@ -300,9 +300,9 @@ def _validate_sort_edge_attr_params(
300300
)
301301

302302

303-
@semantic_validate.register(SortResultNodeAttributeParameters)
303+
@semantic_validate.register(SortResultsNodeAttributeParameters)
304304
def _validate_sort_node_attr_params(
305-
obj: SortResultNodeAttributeParameters,
305+
obj: SortResultsNodeAttributeParameters,
306306
location: Location | None = None,
307307
*,
308308
qgraph: QueryGraph | PathfinderQueryGraph | None = None,

‎src/translator_tom/v2_0/model_dicts/analysis.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
class AnalysisDict(TypedDict):
2828
resource_id: CURIE
29-
edge_bindings: NotRequired[dict[QEdgeID, EdgeBindingDict] | None]
30-
path_bindings: NotRequired[dict[QPathID, PathBindingDict] | None]
31-
score: NotRequired[float | None]
32-
support_graphs: NotRequired[list[AuxGraphID] | None]
33-
scoring_method: NotRequired[str | None]
34-
attributes: NotRequired[list[AttributeDict] | None]
29+
edge_bindings: NotRequired[dict[QEdgeID, EdgeBindingDict]]
30+
path_bindings: NotRequired[dict[QPathID, PathBindingDict]]
31+
score: NotRequired[float]
32+
support_graphs: NotRequired[list[AuxGraphID]]
33+
scoring_method: NotRequired[str]
34+
attributes: NotRequired[list[AttributeDict]]
3535

3636

3737
class AnalysisDictUtil(DictUtil[AnalysisDict]):

‎src/translator_tom/v2_0/model_dicts/asyncquery.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ class AsyncQueryDict(QueryDict):
3535

3636

3737
class AsyncQueryResponseDict(TypedDict):
38-
status: NotRequired[str | None]
39-
description: NotRequired[str | None]
38+
status: NotRequired[str]
39+
description: NotRequired[str]
4040
job_id: str
4141

4242

4343
class AsyncQueryStatusResponseDict(TypedDict):
4444
status: str
4545
description: str
4646
logs: list[LogEntryDict]
47-
response_url: NotRequired[str | None]
47+
response_url: NotRequired[str]
4848

4949

5050
class AsyncQueryDictUtil(DictUtil[AsyncQueryDict]):

‎src/translator_tom/v2_0/model_dicts/attribute.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828

2929
class AttributeDict(TypedDict):
3030
attribute_type_id: CURIE
31-
original_attribute_name: NotRequired[str | None]
31+
original_attribute_name: NotRequired[str]
3232
value: FastJsonValue
33-
value_type_id: NotRequired[CURIE | None]
34-
attribute_source: NotRequired[str | None]
35-
value_url: NotRequired[str | None]
36-
description: NotRequired[str | None]
37-
attributes: NotRequired[list[AttributeDict] | None]
33+
value_type_id: NotRequired[CURIE]
34+
attribute_source: NotRequired[str]
35+
value_url: NotRequired[str]
36+
description: NotRequired[str]
37+
attributes: NotRequired[list[AttributeDict]]
3838

3939

4040
class AttributeDictUtil(DictUtil[AttributeDict]):
@@ -82,12 +82,12 @@ def merge_attribute_lists(
8282
"AttributeConstraintDict",
8383
{
8484
"id": CURIE,
85-
"name": NotRequired[str | None],
85+
"name": NotRequired[str],
8686
"not": NotRequired[bool],
8787
"operator": Operator,
8888
"value": FastJsonValue,
89-
"unit_id": NotRequired[CURIE | None],
90-
"unit_name": NotRequired[str | None],
89+
"unit_id": NotRequired[CURIE],
90+
"unit_name": NotRequired[str],
9191
},
9292
)
9393

‎src/translator_tom/v2_0/model_dicts/constraints.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ def met_by(
120120

121121

122122
class QEdgeConstraintsDict(TypedDict):
123-
knowledge_level: NotRequired[KnowledgeLevelConstraintDict | None]
124-
agent_type: NotRequired[AgentTypeConstraintDict | None]
125-
attributes: NotRequired[list[AttributeConstraintDict] | None]
126-
qualifiers: NotRequired[list[QualifierSetConstraint] | None]
127-
sources: NotRequired[SourceConstraintDict | None]
123+
knowledge_level: NotRequired[KnowledgeLevelConstraintDict]
124+
agent_type: NotRequired[AgentTypeConstraintDict]
125+
attributes: NotRequired[list[AttributeConstraintDict]]
126+
qualifiers: NotRequired[list[QualifierSetConstraint]]
127+
sources: NotRequired[SourceConstraintDict]
128128

129129

130130
class QEdgeConstraintsDictUtil(DictUtil[QEdgeConstraintsDict]):

‎src/translator_tom/v2_0/model_dicts/knowledge_graph.py‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252

5353

5454
class NodeDict(TypedDict):
55-
name: NotRequired[str | None]
55+
name: NotRequired[str]
5656
categories: list[Biolink.Entity]
57-
attributes: NotRequired[list[AttributeDict] | None]
58-
is_set: NotRequired[bool | None]
57+
attributes: NotRequired[list[AttributeDict]]
58+
is_set: NotRequired[bool]
5959

6060

6161
class NodeDictUtil(DictUtil[NodeDict]):
@@ -90,7 +90,9 @@ def update(node: NodeDict, other: NodeDict) -> None:
9090
9191
Does not mutate `other`.
9292
"""
93-
node["name"] = other.get("name") or node.get("name")
93+
name = other.get("name") or node.get("name")
94+
if name is not None:
95+
node["name"] = name
9496
node["categories"] = list(set(node["categories"]) | set(other["categories"]))
9597

9698
other_attrs = other.get("attributes")
@@ -108,8 +110,8 @@ class EdgeDict(TypedDict):
108110
predicate: Biolink.Predicate
109111
subject: CURIE
110112
object: CURIE
111-
attributes: NotRequired[list[AttributeDict] | None]
112-
qualifiers: NotRequired[list[QualifierDict] | None]
113+
attributes: NotRequired[list[AttributeDict]]
114+
qualifiers: NotRequired[list[QualifierDict]]
113115
sources: list[RetrievalSourceDict]
114116
knowledge_level: str
115117
agent_type: str
@@ -313,7 +315,7 @@ def append_aggregator(edge: EdgeDict, source: Infores) -> None:
313315

314316
class KnowledgeGraphDict(TypedDict):
315317
nodes: dict[CURIE, NodeDict]
316-
edges: NotRequired[dict[EdgeID, EdgeDict] | None]
318+
edges: NotRequired[dict[EdgeID, EdgeDict]]
317319

318320

319321
class KnowledgeGraphDictUtil(DictUtil[KnowledgeGraphDict]):
@@ -490,9 +492,11 @@ def prune(
490492
for aux_graph_id in cast("list[str]", edge_aux_graphs["value"]):
491493
edges_to_check.extend(aux_graphs[aux_graph_id]["edges"])
492494

493-
knowledge_graph["edges"] = {
494-
edge_id: edges[edge_id] for edge_id in bound_edges
495-
} or None
495+
bound = {edge_id: edges[edge_id] for edge_id in bound_edges}
496+
if bound:
497+
knowledge_graph["edges"] = bound
498+
else:
499+
knowledge_graph.pop("edges", None)
496500
knowledge_graph["nodes"] = {
497501
curie: knowledge_graph["nodes"][curie] for curie in bound_nodes
498502
}

‎src/translator_tom/v2_0/model_dicts/log_entry.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
class LogEntryDict(TypedDict):
1414
timestamp: str
15-
level: NotRequired[LogLevel | None]
16-
code: NotRequired[str | None]
15+
level: NotRequired[LogLevel]
16+
code: NotRequired[str]
1717
message: str
1818

1919

0 commit comments

Comments
 (0)