Extract row route metadata policy
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from . import category_template_metadata as template_policy
|
||||
from . import hardcore_position_config as hardcore_position_policy
|
||||
from .hardcore_action_metadata import source_hardcore_action_family
|
||||
except ImportError: # Allows local smoke tests from the repository root.
|
||||
import category_template_metadata as template_policy
|
||||
import hardcore_position_config as hardcore_position_policy
|
||||
from hardcore_action_metadata import source_hardcore_action_family
|
||||
|
||||
|
||||
EMPTY_ACTION_POSITION_ROUTE = {
|
||||
"position_family": "",
|
||||
"position_keys": [],
|
||||
"position_key": "",
|
||||
"action_family": "",
|
||||
}
|
||||
|
||||
|
||||
def empty_action_position_route() -> dict[str, Any]:
|
||||
return {
|
||||
"position_family": "",
|
||||
"position_keys": [],
|
||||
"position_key": "",
|
||||
"action_family": "",
|
||||
}
|
||||
|
||||
|
||||
def resolve_action_position_route(
|
||||
*,
|
||||
is_pose_category: bool,
|
||||
subcategory: dict[str, Any],
|
||||
hardcore_position_config: dict[str, Any] | None,
|
||||
item_template_metadata: dict[str, Any] | None,
|
||||
item_text: Any,
|
||||
source_role_graph: Any,
|
||||
source_composition: Any,
|
||||
pose: Any,
|
||||
item_axis_values: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
if not is_pose_category:
|
||||
return empty_action_position_route()
|
||||
|
||||
metadata = item_template_metadata or {}
|
||||
position_family = template_policy.template_position_family(
|
||||
metadata
|
||||
) or hardcore_position_policy.hardcore_source_position_family(
|
||||
subcategory,
|
||||
hardcore_position_config,
|
||||
)
|
||||
inferred_position_keys = hardcore_position_policy.hardcore_position_keys(
|
||||
item_text,
|
||||
source_role_graph,
|
||||
source_composition,
|
||||
pose,
|
||||
axis_values=item_axis_values,
|
||||
)
|
||||
position_keys = template_policy.merge_position_keys(
|
||||
template_policy.template_position_keys(metadata),
|
||||
inferred_position_keys,
|
||||
)
|
||||
action_family = template_policy.template_action_family(metadata)
|
||||
if not action_family:
|
||||
action_family = source_hardcore_action_family(
|
||||
position_family,
|
||||
source_role_graph,
|
||||
item_text,
|
||||
source_composition,
|
||||
item_axis_values,
|
||||
)
|
||||
|
||||
return {
|
||||
"position_family": position_family,
|
||||
"position_keys": position_keys,
|
||||
"position_key": position_keys[0] if position_keys else "",
|
||||
"action_family": action_family,
|
||||
}
|
||||
Reference in New Issue
Block a user