bi3mw > 17-08-2024, 12:33 AM
import sys
import numpy as np
from scipy.special import comb
def calculate_binomial_distribution(n, max_length):
"""Berechnet eine Binomialverteilung für Wortlängen."""
k_values = np.arange(1, max_length + 1)
# Berechne die Binomialverteilung für die Formel choose(9, k-1) / 2^9
probabilities = [comb(n, k-1) / (2 ** n) for k in k_values]
# Normiere die Verteilung
probabilities /= np.sum(probabilities)
return probabilities
def adjust_word_lengths(words, target_distribution):
"""Passt die Wortlängen an die Zielverteilung an, indem Wörter gekürzt oder verlängert werden."""
adjusted_words = []
max_word_length = len(target_distribution)
length_bins = np.arange(1, max_word_length + 1)
length_probs = np.array(target_distribution)
for word in words:
current_length = len(word)
target_length = np.random.choice(length_bins, p=length_probs)
# Falls die Zielwortlänge kleiner ist, kürze das Wort
if target_length < current_length:
adjusted_words.append(word[:target_length])
# Falls die Zielwortlänge größer ist, verlängere das Wort mit 'X'
elif target_length > current_length:
adjusted_words.append(word + 'X' * (target_length - current_length))
else:
adjusted_words.append(word) # Wenn die Länge passt, bleibt das Wort unverändert
return adjusted_words
def process_text(file_path):
"""Liest den Text aus der Datei, passt die Wortlängen an und gibt den neuen Text zurück."""
try:
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
except FileNotFoundError:
print(f"Error: The file {file_path} was not found.")
sys.exit(1)
except IOError as e:
print(f"Error: An error occurred while reading the file: {e}")
sys.exit(1)
max_word_length = 15 # Maximale Wortlänge festlegen
n = 9 # Anzahl der Würfe für die Binomialverteilung
# Berechne die Binomialverteilung
target_distribution = calculate_binomial_distribution(n, max_word_length)
adjusted_lines = []
for line in lines:
words = line.split()
adjusted_words = adjust_word_lengths(words, target_distribution)
adjusted_lines.append(' '.join(adjusted_words))
return '\n'.join(adjusted_lines)
def main():
if len(sys.argv) != 2:
print("Usage: python adjust_word_length.py <filename>")
sys.exit(1)
file_path = sys.argv[1]
new_text = process_text(file_path)
print("Modified text:")
print(new_text)
if __name__ == "__main__":
main()
Quote:ChatGPT
One could design a volvelle that aims to change the word lengths of a text according to a specific distribution. This could be done through the use of rotating disks, each giving specific instructions on how words should be edited.
Example of a volvelle for word length manipulation
Here is a hypothetical description of what a volvelle could look like for this task:
Circle 1: Defines the possible word lengths from 1 to 15 (depending on the maximum word length).
Circle 2: Gives the probability for each word length based on a certain distribution (e.g. binomial distribution).
Circle 3: Instructions for shortening or expanding words to achieve the target distribution.
Use of a volvelle
1. user enters the text.
2. volvelle is rotated to obtain the rules for shortening or expanding words.
3. instructions are applied to the text.
Ruby Novacna > 17-08-2024, 12:14 PM
bi3mw > 17-08-2024, 12:28 PM
(17-08-2024, 12:14 PM)Ruby Novacna Wrote: You are not allowed to view links. Register or Login to view.And, by replacing the endings, what will that give?
Capitul9 prim9 De regul9 sumpt9 ex parte elemeng nostro corpori occurrenti9 ab extra
Ruby Novacna > 17-08-2024, 12:42 PM
bi3mw > 17-08-2024, 12:47 PM
RobGea > 17-08-2024, 03:35 PM
RobGea > 17-08-2024, 04:38 PM
(17-08-2024, 12:33 AM)bi3mw Wrote: You are not allowed to view links. Register or Login to view.Question: What if the words in the VMS have been shortened or expanded with fill characters (here X) so that they end up corresponding to a binomial distribution (with whatever system)?
bi3mw > 17-08-2024, 06:38 PM
bi3mw > 18-08-2024, 01:44 PM
(17-08-2024, 03:35 PM)RobGea Wrote: You are not allowed to view links. Register or Login to view.-- Just a thought, does the binomial distribution hold per folio or even per section ?
RobGea > 18-08-2024, 04:14 PM