Technical documentation

class CemantixSolver(config)[source]

Bases: object

Automatic solver for the Cemantix word game.

This solver uses a Word2Vec model and a beam search strategy to guess the hidden word by querying the Cemantix API for similarity scores.

__fetch_scores_parallel(words, day, max_workers=5)

Fetches the scores for a list of words in parallel.

Parameters:
  • words (list) – List of words to score.

  • day (int) – Puzzle number.

  • max_workers (int) – Maximum number of concurrent threads.

Returns:

Dictionary {word: score} of valid words and their scores.

__get_puzzle_number()

Fetch the current day’s puzzle number from the Cemantix website.

Returns:

The puzzle number as an integer if found, otherwise None.

Return type:

int or None

__get_score(word, day)

Send a word to the API and retrieve its similarity score.

Parameters:
  • word (str) – The word to test.

  • day (int) – The puzzle number for which to retrieve the score.

Returns:

The similarity score (float between 0.0 and 1.0), or None if the request failed or word is invalid.

Return type:

float or None

__log_and_notify(word, score, exec_time)

Send a notification when the solution is found.

Parameters:
  • word (str) – The found word (the solution).

  • exec_time (float) – Execution time in seconds.

__ntfy(msg)

Send a notification containing msg using NTFY API

Parameters:

msg (str) – Message to send as notification

Returns:

None

solve(day=None, ntfy=False)[source]

Optimized Cemantix solver using NumPy vectorization to find words whose similarity with the start words exactly matches the expected values (within a small epsilon).

Parameters:
  • day (int) – (Optional) Puzzle number to solve. If None, the current day’s puzzle will be used.

  • ntfy (bool) – (Optional) Send a notification using NTFY .env configuration

Returns:

A tuple (best_word, best_score) or None if no solution was found.

Return type:

tuple or None

load_config(filename='src/resources/config.ini')[source]

Load configuration values from a .ini file.

Parameters:

filename (str) – Path to the configuration file.

Raises:
  • FileNotFoundError – If the configuration file does not exist.

  • KeyError – If the [GENERAL] section is missing in the configuration file.

Returns:

A dictionary containing the configuration values.

Return type:

dict

setup_logging(log_level: str, log_file: str)[source]

Set up global logging based on configuration.

Parameters:
  • log_level (str) – Logging level as a string (e.g., ‘INFO’, ‘DEBUG’).

  • log_file (str) – Path to the log file. If empty, logs are output to stdout.