feat: collega il lessico semantico al filler

This commit is contained in:
2026-04-14 18:56:17 +02:00
parent 77c7e709b6
commit b172b9c04b
15 changed files with 2255563 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
from dataclasses import dataclass
import locale
import random
import sys
import time
from typing import Dict, Iterable, List, Optional, Sequence, Set, Tuple
@@ -114,6 +115,7 @@ class CrosswordGenerator:
max_candidates_per_word: int = 12,
time_limit_seconds: float = 8.0,
diffxy: int = DIFFXY,
seed: Optional[int] = None,
) -> None:
normalized = [self._normalize(word) for word in words]
unique_words = list(dict.fromkeys(word for word in normalized if len(word) >= 2))
@@ -122,6 +124,8 @@ class CrosswordGenerator:
self.max_candidates_per_word = max_candidates_per_word
self.time_limit_seconds = time_limit_seconds
self.diffxy = diffxy
self.seed = seed
self.rng = random.Random(seed)
self.started_at = 0.0
self.visited: Dict[Tuple[frozenset, Tuple[str, ...]], Tuple[int, int, int]] = {}
self.nodes_visited = 0
@@ -213,6 +217,8 @@ class CrosswordGenerator:
reverse=True,
)
candidates = candidates[: self.max_candidates_per_word]
if len(candidates) > 1:
self.rng.shuffle(candidates)
next_remaining = [word for word in remaining_words if word != next_word]
for placement in candidates:
@@ -253,6 +259,10 @@ class CrosswordGenerator:
word,
),
)
if len(ranked_words) > 1:
top_slice = ranked_words[: min(5, len(ranked_words))]
self.rng.shuffle(top_slice)
ranked_words = top_slice + ranked_words[min(5, len(ranked_words)) :]
best_word = ranked_words[0]
best_key: Optional[Tuple[int, int, int, str]] = None