Skip to content
Merged
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 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "uv_build"

[project]
name = "translator_tom"
version = "2.0.0"
version = "2.1.0"
description = "TRAPI Object Models: A performant python data model and centralized utilities for the Translator Reasoner API."
readme = "README.md"
requires-python = ">=3.10"
Expand Down
22 changes: 11 additions & 11 deletions src/translator_tom/v1_6/model_dicts/workflow_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
OverlayComputeNgdParameters,
OverlayFisherExactTestParameters,
PlusOrMinus,
SortResultNodeAttributeParameters,
SortResultsEdgeAttributeParameters,
SortResultsNodeAttributeParameters,
SortResultsScoreParameters,
TopOrBottom,
)
Expand Down Expand Up @@ -169,10 +169,10 @@
"OverlayFisherExactTestParametersDict",
"OverlayFisherExactTestParametersDictUtil",
"RunnerParametersDict",
"SortResultNodeAttributeParametersDict",
"SortResultNodeAttributeParametersDictUtil",
"SortResultsEdgeAttributeParametersDict",
"SortResultsEdgeAttributeParametersDictUtil",
"SortResultsNodeAttributeParametersDict",
"SortResultsNodeAttributeParametersDictUtil",
"SortResultsScoreParametersDict",
"SortResultsScoreParametersDictUtil",
]
Expand Down Expand Up @@ -783,22 +783,22 @@ class OperationSortResultsEdgeAttributeDictUtil(BaseOperationDictUtil):
_model = OperationSortResultsEdgeAttribute


class SortResultNodeAttributeParametersDict(OperationParametersDict):
class SortResultsNodeAttributeParametersDict(OperationParametersDict):
node_attribute: str
ascending_or_descending: AscendingOrDescending
qnode_keys: list[QNodeID] | None
qnode_keys: NotRequired[list[QNodeID] | None]


class SortResultNodeAttributeParametersDictUtil(
DictUtil[SortResultNodeAttributeParametersDict]
class SortResultsNodeAttributeParametersDictUtil(
DictUtil[SortResultsNodeAttributeParametersDict]
):
"""Utility methods for `SortResultNodeAttributeParametersDict`, mirroring the model."""
"""Utility methods for `SortResultsNodeAttributeParametersDict`, mirroring the model."""

_model = SortResultNodeAttributeParameters
_model = SortResultsNodeAttributeParameters

@staticmethod
def qnode_keys_list(
parameters: SortResultNodeAttributeParametersDict,
parameters: SortResultsNodeAttributeParametersDict,
) -> list[QNodeID]:
"""Return a guaranteed list of qnode_keys, empty if it is not defined."""
qnode_keys = parameters.get("qnode_keys")
Expand All @@ -807,7 +807,7 @@ def qnode_keys_list(

class OperationSortResultsNodeAttributeDict(BaseOperationDict):
id: Literal["sort_results_node_attribute"]
parameters: SortResultNodeAttributeParametersDict
parameters: SortResultsNodeAttributeParametersDict


class OperationSortResultsNodeAttributeDictUtil(BaseOperationDictUtil):
Expand Down
10 changes: 5 additions & 5 deletions src/translator_tom/v1_6/models/workflow_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"PlusOrMinus",
"PlusOrMinusEnum",
"RunnerParameters",
"SortResultNodeAttributeParameters",
"SortResultsEdgeAttributeParameters",
"SortResultsNodeAttributeParameters",
"SortResultsScoreParameters",
"TopOrBottom",
"TopOrBottomEnum",
Expand Down Expand Up @@ -714,15 +714,15 @@ class OperationSortResultsEdgeAttribute(BaseOperation):
parameters: SortResultsEdgeAttributeParameters


class SortResultNodeAttributeParameters(OperationParameters):
"""Parameters for the SortResultNodeAttribute operation."""
class SortResultsNodeAttributeParameters(OperationParameters):
"""Parameters for the SortResultsNodeAttribute operation."""

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

ascending_or_descending: AscendingOrDescending

qnode_keys: Annotated[list[QNodeID] | None, Field(examples=["[e01]"])]
qnode_keys: Annotated[list[QNodeID] | None, Field(examples=["[e01]"])] = None
"""This indicates if you only want to consider nodes with specific node_keys.

If not provided or empty, all nodes will be looked at.
Expand All @@ -744,7 +744,7 @@ class OperationSortResultsNodeAttribute(BaseOperation):
"""

id: Literal["sort_results_node_attribute"]
parameters: SortResultNodeAttributeParameters
parameters: SortResultsNodeAttributeParameters


class SortResultsScoreParameters(OperationParameters):
Expand Down
6 changes: 3 additions & 3 deletions src/translator_tom/v1_6/validation/_workflow_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
OverlayComputeJaccardParameters,
OverlayComputeNgdParameters,
OverlayFisherExactTestParameters,
SortResultNodeAttributeParameters,
SortResultsEdgeAttributeParameters,
SortResultsNodeAttributeParameters,
)
from translator_tom.v1_6.validation._util import (
Location,
Expand Down Expand Up @@ -300,9 +300,9 @@ def _validate_sort_edge_attr_params(
)


@semantic_validate.register(SortResultNodeAttributeParameters)
@semantic_validate.register(SortResultsNodeAttributeParameters)
def _validate_sort_node_attr_params(
obj: SortResultNodeAttributeParameters,
obj: SortResultsNodeAttributeParameters,
location: Location | None = None,
*,
qgraph: QueryGraph | PathfinderQueryGraph | None = None,
Expand Down
12 changes: 6 additions & 6 deletions src/translator_tom/v2_0/model_dicts/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

class AnalysisDict(TypedDict):
resource_id: CURIE
edge_bindings: NotRequired[dict[QEdgeID, EdgeBindingDict] | None]
path_bindings: NotRequired[dict[QPathID, PathBindingDict] | None]
score: NotRequired[float | None]
support_graphs: NotRequired[list[AuxGraphID] | None]
scoring_method: NotRequired[str | None]
attributes: NotRequired[list[AttributeDict] | None]
edge_bindings: NotRequired[dict[QEdgeID, EdgeBindingDict]]
path_bindings: NotRequired[dict[QPathID, PathBindingDict]]
score: NotRequired[float]
support_graphs: NotRequired[list[AuxGraphID]]
scoring_method: NotRequired[str]
attributes: NotRequired[list[AttributeDict]]


class AnalysisDictUtil(DictUtil[AnalysisDict]):
Expand Down
6 changes: 3 additions & 3 deletions src/translator_tom/v2_0/model_dicts/asyncquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class AsyncQueryDict(QueryDict):


class AsyncQueryResponseDict(TypedDict):
status: NotRequired[str | None]
description: NotRequired[str | None]
status: NotRequired[str]
description: NotRequired[str]
job_id: str


class AsyncQueryStatusResponseDict(TypedDict):
status: str
description: str
logs: list[LogEntryDict]
response_url: NotRequired[str | None]
response_url: NotRequired[str]


class AsyncQueryDictUtil(DictUtil[AsyncQueryDict]):
Expand Down
18 changes: 9 additions & 9 deletions src/translator_tom/v2_0/model_dicts/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

class AttributeDict(TypedDict):
attribute_type_id: CURIE
original_attribute_name: NotRequired[str | None]
original_attribute_name: NotRequired[str]
value: FastJsonValue
value_type_id: NotRequired[CURIE | None]
attribute_source: NotRequired[str | None]
value_url: NotRequired[str | None]
description: NotRequired[str | None]
attributes: NotRequired[list[AttributeDict] | None]
value_type_id: NotRequired[CURIE]
attribute_source: NotRequired[str]
value_url: NotRequired[str]
description: NotRequired[str]
attributes: NotRequired[list[AttributeDict]]


class AttributeDictUtil(DictUtil[AttributeDict]):
Expand Down Expand Up @@ -82,12 +82,12 @@ def merge_attribute_lists(
"AttributeConstraintDict",
{
"id": CURIE,
"name": NotRequired[str | None],
"name": NotRequired[str],
"not": NotRequired[bool],
"operator": Operator,
"value": FastJsonValue,
"unit_id": NotRequired[CURIE | None],
"unit_name": NotRequired[str | None],
"unit_id": NotRequired[CURIE],
"unit_name": NotRequired[str],
},
)

Expand Down
10 changes: 5 additions & 5 deletions src/translator_tom/v2_0/model_dicts/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def met_by(


class QEdgeConstraintsDict(TypedDict):
knowledge_level: NotRequired[KnowledgeLevelConstraintDict | None]
agent_type: NotRequired[AgentTypeConstraintDict | None]
attributes: NotRequired[list[AttributeConstraintDict] | None]
qualifiers: NotRequired[list[QualifierSetConstraint] | None]
sources: NotRequired[SourceConstraintDict | None]
knowledge_level: NotRequired[KnowledgeLevelConstraintDict]
agent_type: NotRequired[AgentTypeConstraintDict]
attributes: NotRequired[list[AttributeConstraintDict]]
qualifiers: NotRequired[list[QualifierSetConstraint]]
sources: NotRequired[SourceConstraintDict]


class QEdgeConstraintsDictUtil(DictUtil[QEdgeConstraintsDict]):
Expand Down
24 changes: 14 additions & 10 deletions src/translator_tom/v2_0/model_dicts/knowledge_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@


class NodeDict(TypedDict):
name: NotRequired[str | None]
name: NotRequired[str]
categories: list[Biolink.Entity]
attributes: NotRequired[list[AttributeDict] | None]
is_set: NotRequired[bool | None]
attributes: NotRequired[list[AttributeDict]]
is_set: NotRequired[bool]


class NodeDictUtil(DictUtil[NodeDict]):
Expand Down Expand Up @@ -90,7 +90,9 @@ def update(node: NodeDict, other: NodeDict) -> None:

Does not mutate `other`.
"""
node["name"] = other.get("name") or node.get("name")
name = other.get("name") or node.get("name")
if name is not None:
node["name"] = name
node["categories"] = list(set(node["categories"]) | set(other["categories"]))

other_attrs = other.get("attributes")
Expand All @@ -108,8 +110,8 @@ class EdgeDict(TypedDict):
predicate: Biolink.Predicate
subject: CURIE
object: CURIE
attributes: NotRequired[list[AttributeDict] | None]
qualifiers: NotRequired[list[QualifierDict] | None]
attributes: NotRequired[list[AttributeDict]]
qualifiers: NotRequired[list[QualifierDict]]
sources: list[RetrievalSourceDict]
knowledge_level: str
agent_type: str
Expand Down Expand Up @@ -313,7 +315,7 @@ def append_aggregator(edge: EdgeDict, source: Infores) -> None:

class KnowledgeGraphDict(TypedDict):
nodes: dict[CURIE, NodeDict]
edges: NotRequired[dict[EdgeID, EdgeDict] | None]
edges: NotRequired[dict[EdgeID, EdgeDict]]


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

knowledge_graph["edges"] = {
edge_id: edges[edge_id] for edge_id in bound_edges
} or None
bound = {edge_id: edges[edge_id] for edge_id in bound_edges}
if bound:
knowledge_graph["edges"] = bound
else:
knowledge_graph.pop("edges", None)
knowledge_graph["nodes"] = {
curie: knowledge_graph["nodes"][curie] for curie in bound_nodes
}
4 changes: 2 additions & 2 deletions src/translator_tom/v2_0/model_dicts/log_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class LogEntryDict(TypedDict):
timestamp: str
level: NotRequired[LogLevel | None]
code: NotRequired[str | None]
level: NotRequired[LogLevel]
code: NotRequired[str]
message: str


Expand Down
8 changes: 4 additions & 4 deletions src/translator_tom/v2_0/model_dicts/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@


class MessageDict(TypedDict):
results: NotRequired[list[ResultDict] | None]
query_graph: NotRequired[QueryGraphDict | None]
knowledge_graph: NotRequired[KnowledgeGraphDict | None]
auxiliary_graphs: NotRequired[dict[AuxGraphID, AuxiliaryGraphDict] | None]
results: NotRequired[list[ResultDict]]
query_graph: NotRequired[QueryGraphDict]
knowledge_graph: NotRequired[KnowledgeGraphDict]
auxiliary_graphs: NotRequired[dict[AuxGraphID, AuxiliaryGraphDict]]


def _query_graph_hash(query_graph: QueryGraphDict | None) -> str | None:
Expand Down
6 changes: 3 additions & 3 deletions src/translator_tom/v2_0/model_dicts/meta_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

class MetaAttributeDict(TypedDict):
attribute_type_id: CURIE
attribute_source: NotRequired[str | None]
original_attribute_names: NotRequired[list[str] | None]
attribute_source: NotRequired[str]
original_attribute_names: NotRequired[list[str]]
constraint_use: NotRequired[bool]
constraint_name: NotRequired[str | None]
constraint_name: NotRequired[str]


class MetaAttributeDictUtil(DictUtil[MetaAttributeDict]):
Expand Down
Loading
Loading