print("\n# CHAP03 -- Python-Script-SAMPLE 10: =========")
print("---------- Calculate cost value of given string with LanguageStatisticsLibPy ----------")

# Import the library
from LanguageStatistics import LanguageStatistics

# Path to the language statistics folder of your local CrypTool 2 installation -- to be adaped
ct2_language_statistics_folder = "C:\\Program Files\\CrypTool 2\\LanguageStatistics"

# Load trigrams for English
grams = LanguageStatistics.create_grams_by_size(3, "en", ct2_language_statistics_folder, False)

# Normalize all frequency values between 0 and 1,000,000
grams.normalize(1000000.0)

# Map the text into "number space" (integer array)
hellonumbers = LanguageStatistics.map_text_into_number_space("HELLOWORLDTHISISATESTTEXT", grams.alphabet)

# Calculate the cost of the text
cost = grams.calculate_cost(hellonumbers)

# Print the cost value
print(cost)

# --------------------------------------------------
# CHAP03 -- Python-Script-SAMPLE 10: =========
# ---------- Calculate cost value of given string with LanguageStatisticsLibPy ----------
# 529744.6834239131

