Clean up paired expressions and Krea ages

This commit is contained in:
2026-06-24 12:16:23 +02:00
parent ab30bdafa8
commit 543e2feab7
2 changed files with 18 additions and 2 deletions
+7 -1
View File
@@ -168,6 +168,12 @@ def _clean_age(age: Any) -> str:
return _clean(age)
def _age_detail_phrase(age: Any) -> str:
text = _clean(age)
text = re.sub(r"\s+adults?$", "", text).strip()
return text.replace("-year-old", " years old")
def _age_subject(row: dict[str, Any], fallback_subject: str = "adult person") -> str:
subject = _clean(row.get("subject_phrase") or row.get("primary_subject") or row.get("subject") or fallback_subject)
age = _clean_age(row.get("age_band") or row.get("age"))
@@ -281,7 +287,7 @@ def _normal_row_to_krea(row: dict[str, Any], detail_level: str, style_mode: str)
subject = _clean(row.get("subject_phrase") or primary or "adult couple")
if subject == "woman and man":
subject = "a woman and a man"
ages = _row_value(row, "age", ("Ages",)) or _clean(row.get("age_band"))
ages = _age_detail_phrase(_row_value(row, "age", ("Ages",)) or row.get("age_band"))
body = _row_value(row, "body", ("Body types",)) or _clean(row.get("body_type"))
parts = [
f"An adult couple: {subject}, all visibly adult",
+11 -1
View File
@@ -523,6 +523,14 @@ def _choose_text(rng: random.Random, items: list[Any]) -> str:
return _item_text(item)
def _choose_distinct_text(rng: random.Random, items: list[Any], first_text: str) -> str:
first_text = _item_text(first_text).lower()
distinct = [item for item in items if _item_text(item).lower() != first_text]
if not distinct:
return ""
return _choose_text(rng, distinct)
def _choose_pair(rng: random.Random, items: list[Any]) -> tuple[str, str]:
return _pair_from(_weighted_choice(rng, items))
@@ -1803,7 +1811,9 @@ def _build_custom_row(
)
expression = _choose_text(expression_rng, expression_entries)
if subject_type in ("couple", "group") and ";" not in expression:
expression = f"{expression}; {_choose_text(expression_rng, expression_entries)}"
secondary_expression = _choose_distinct_text(expression_rng, expression_entries, expression)
if secondary_expression:
expression = f"{expression}; {secondary_expression}"
composition = _choose_text(
composition_rng,
_compatible_entries(_composition_pool(category, subcategory, item, subject_type), women_count, men_count),