hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

commit 5f0f5cae73c4a8226fc246a8b86adf92f1d3f5fc
parent 5af92a6e358724f456ab0fcd600ec33635b9d005
Author: triesap <tyson@radroots.org>
Date:   Mon, 21 Sep 2026 13:50:49 +0000

core: interpret buyer condition strength and negation

Diffstat:
Asrc/hyf_application/buyer_conditions.mojo | 33+++++++++++++++++++++++++++++++++
Mtests/test_application.mojo | 22++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/src/hyf_application/buyer_conditions.mojo b/src/hyf_application/buyer_conditions.mojo @@ -0,0 +1,33 @@ +from std.collections import Optional + +from hyf_core.domain.demand import Condition, condition + + +def interpret_condition_strength(phrase: String) -> String: + var lowered = phrase.lower() + if lowered == "required" or lowered == "must" or lowered == "need": + return "mandatory" + if lowered == "ideally" or lowered == "prefer" or lowered == "preferred": + return "preferred" + if lowered == "not" or lowered == "no" or lowered == "exclude": + return "excluded" + if lowered == "fine" or lowered == "ok" or lowered == "permitted": + return "permitted" + return "preferred" + + +def interpret_buyer_condition( + kind: String, phrase: String, value: Optional[String] +) raises -> Condition: + var strength = interpret_condition_strength(phrase) + if strength == "excluded" and not value: + return condition(kind, strength, None) + return condition(kind, strength, value) + + +def delivery_exclusion_means_pickup() -> Bool: + return False + + +def missing_information_is_prohibition() -> Bool: + return False diff --git a/tests/test_application.mojo b/tests/test_application.mojo @@ -221,3 +221,25 @@ def test_buyer_discovers_multiple_demand_lines() raises: assert_equal(lines[0].product_phrase, "tomatoes") assert_equal(lines[1].product_phrase, "basil") assert_equal(lines[0].line_id, "line-1") + + +from hyf_application.buyer_conditions import ( + delivery_exclusion_means_pickup, + interpret_buyer_condition, + interpret_condition_strength, + missing_information_is_prohibition, +) +from std.collections import Optional + + +def test_buyer_condition_strength_and_negation() raises: + assert_equal(interpret_condition_strength("required"), "mandatory") + assert_equal(interpret_condition_strength("ideally"), "preferred") + assert_equal(interpret_condition_strength("not"), "excluded") + assert_equal(interpret_condition_strength("fine"), "permitted") + var required = interpret_buyer_condition("fulfillment", "required", Optional[String]("delivery")) + assert_equal(required.strength, "mandatory") + var excluded = interpret_buyer_condition("fulfillment", "not", Optional[String]("pickup")) + assert_equal(excluded.strength, "excluded") + assert_true(not delivery_exclusion_means_pickup()) + assert_true(not missing_information_is_prohibition())