| author | Alan Dipert
<alan@dipert.org> 2025-12-04 20:04:02 UTC |
| committer | Alan Dipert
<alan@dipert.org> 2025-12-04 20:04:02 UTC |
| parent | 255f98621cca9a1a6eb19abadfd4b3c238403607 |
| test_generator.py | +32 | -9 |
diff --git a/test_generator.py b/test_generator.py index a0d9416..e11aade 100644 --- a/test_generator.py +++ b/test_generator.py @@ -530,41 +530,54 @@ def _base_features( spec: LanguageSpec, rng: random.Random, difficulty: str, constraints: Optional[SectionConstraints] = None ) -> SentenceFeatures: cons = constraints + adj_pool = ["tall", "red", "big", "fast"] verbs = cons.allowed_verbs if cons else ["see", "chase", "give"] verb_id = rng.choice(verbs) allow_past = cons.allow_past if cons else True tense = "PAST" if allow_past and (difficulty == "late" or rng.random() < 0.4) else "PRES" subj_nouns = cons.allowed_agent_nouns if cons else ["man", "woman"] + subj_adj = [] + if (cons.allow_adjectives if cons else True) and rng.random() < 0.6: + subj_adj = [rng.choice(adj_pool)] subj = np_features( noun_id=rng.choice(subj_nouns), role=AGENT, plural=(cons.allow_plural if cons else difficulty != "early") and rng.random() < 0.4, - adjectives=(["tall"] if ((cons.allow_adjectives if cons else True) and rng.random() < 0.6) else []), + adjectives=subj_adj, ) if verb_id == "give": rec_nouns = cons.allowed_recipient_nouns if cons else ["boy", "girl"] + obj1_adj = [] + if (cons.allow_adjectives if cons else True) and rng.random() < 0.5: + obj1_adj = [rng.choice(adj_pool)] obj1 = np_features( noun_id=rng.choice(rec_nouns), role=RECIPIENT, plural=(cons.allow_plural if cons else difficulty != "early") and rng.random() < 0.4, - adjectives=(["fast"] if ((cons.allow_adjectives if cons else True) and rng.random() < 0.4) else []), + adjectives=obj1_adj, ) theme_nouns = cons.allowed_theme_nouns if cons else ["ball", "house"] + obj2_adj = [] + if (cons.allow_adjectives if cons else True) and rng.random() < 0.6: + obj2_adj = [rng.choice(adj_pool)] obj2 = np_features( noun_id=rng.choice(theme_nouns), role=THEME, plural=(cons.allow_plural if cons else difficulty == "late") and rng.random() < 0.5, - adjectives=(["red"] if ((cons.allow_adjectives if cons else True) and rng.random() < 0.6) else []), + adjectives=obj2_adj, ) else: rec_nouns = cons.allowed_recipient_nouns if cons else ["boy", "girl", "man", "woman"] + obj1_adj = [] + if (cons.allow_adjectives if cons else True) and rng.random() < 0.6: + obj1_adj = [rng.choice(adj_pool)] obj1 = np_features( noun_id=rng.choice(rec_nouns), role=RECIPIENT, plural=(cons.allow_plural if cons else difficulty != "early") and rng.random() < 0.5, - adjectives=(["red"] if ((cons.allow_adjectives if cons else True) and rng.random() < 0.6) else []), + adjectives=obj1_adj, ) obj2 = None @@ -599,13 +612,18 @@ def _planned_features( allow_past = cons.allow_past if cons else True allow_adjectives = cons.allow_adjectives if cons else True allow_feminine = cons.allow_feminine if cons else True + adj_pool = ["tall", "red", "big", "fast"] def build_pool(nouns: List[str], role: str) -> List[NPFeature]: pool: List[NPFeature] = [] for noun in nouns: - base_adj = ["tall"] if role == AGENT else ["red"] - adjs = [base_adj] if allow_adjectives else [[]] - for adj_list in adjs: + adj_choices = adj_pool if allow_adjectives else [] + if not adj_choices: + adj_variants = [[]] + else: + # include one no-adj variant plus one for each adjective to diversify surfaces + adj_variants = [[]] + [[adj] for adj in adj_choices] + for adj_list in adj_variants: pool.append(np_features(noun, role, plural=False, adjectives=adj_list)) if allow_plural: pool.append(np_features(noun, role, plural=True, adjectives=adj_list)) @@ -689,10 +707,14 @@ def _planned_features( must_adj = remaining.get("adjective", 0) >= items_left if allow_adjectives else False if allow_adjectives and (remaining.get("adjective", 0) > 0 or must_adj): if not obj1.adjectives: - obj1 = np_features(obj1.noun_id, obj1.role, feminine=obj1.feminine, plural=obj1.plural, adjectives=["red"]) + obj1 = np_features( + obj1.noun_id, obj1.role, feminine=obj1.feminine, plural=obj1.plural, adjectives=[rng.choice(adj_pool)] + ) delta["adjective"] = 1 elif not subj.adjectives: - subj = np_features(subj.noun_id, subj.role, feminine=subj.feminine, plural=subj.plural, adjectives=["tall"]) + subj = np_features( + subj.noun_id, subj.role, feminine=subj.feminine, plural=subj.plural, adjectives=[rng.choice(adj_pool)] + ) delta["adjective"] = 1 return sentence_features(verb_id, tense, subj, obj1, obj2, use_irregular_verb=use_irregular_verb), delta @@ -737,6 +759,7 @@ def _boost_feature_load(sf: SentenceFeatures, target: int, constraints: Optional allow_plural = cons.allow_plural if cons else True allow_past = cons.allow_past if cons else True allow_adjectives = cons.allow_adjectives if cons else True + adj_pool = ["red", "fast", "big", "tall"] subj = sf.subject obj1 = sf.obj1 obj2 = sf.obj2