Lorem Ipsum is placeholder text used when
preparing layout without wanted to have content already filled.
任意のテキストを使用する上での主な機能の1つは、ナンセンスであることです。
それは有効なラテンではありません(それは近いですが)。
これにより、レイアウトを見せている人が気を散らしてテキストを読むのを防ぐことができます。
もう1つの重要な機能は、実際の言語のように見えますです。
単語は正しい長さであり、文字は正しい分布で発生します。
問題は、Lorem Ipsumが必ずしもすべての言語、またはすべての主題のgobbldy-gookであるとは限りません。
文字の分布は、科学的な記事よりも小説では異なると予想しています。
あなたの仕事は、テキストの例が与えられたときに、そのテキストの特性の適切な模倣である、lorum
ipsumスタイルgobbldy-gookを生成するツールを作成することです。
タスク
与えられた入力は、UTF8テキスト input-text と数字xで与えられます。
そのテキストのスタイルに従ってgobbldy-gookのx文字を出力します。
単語は、入力テキスト中の空白文字を使用して区切られていると仮定することができる。
任意の合理的な形式で入力することができます(ただし、UTF-8を受け入れる必要があります)。例えばSTDINからの読み込み、ファイルからの読み込み、関数に渡される文字列としての読み込みなど
出力と同様です。
Critria
- Must not be real correct text in the language of
input-text- In particular must contain no words with more than 3 characters
from input-text. - This can be trivially avoided by using a hashset to ban all
words from input-text from occurring in the output
- In particular must contain no words with more than 3 characters
- Must look like it could have been real text from the language
of input-text.- That is to say it must have the correct letter and word length
distributions that is convincing to the eye of the reader.- It is up to the implementation if they take this to mean
unigram, bigram, trigram or other statistics for the
distributions. - The goal is for it to look right
- It is up to the implementation if they take this to mean
- That is to say it must have the correct letter and word length
テキストを判断する
審査の目的で、次のパブリックドメインテキストに基づいて256文字の出力を提供してください:
これらはすべてUTF-8でエンコードされており、特にDie
Verwandlungはドイツ語であるため、[a-zA-Z]以外の多くの文字を使用しています
Python 3
import string
import random
with open('lorem.txt') as f:
text = f.read()
number = eval(input("Input number: "))
dictionary = ''.join(ch for ch in text if ch not in set(string.punctuation)).split(" ")
chars = []
for word in dictionary:
for char in word:
chars.append(char)
chars = list(set(chars))
occurences = {}
for char in chars:
occurences[char] = []
for word in dictionary:
for idx, char in enumerate(word):
try:
occurences[char].append(word[idx+1])
except IndexError:
pass
lengths = [len(x) for x in dictionary]
result = ""
for _ in range(number):
length = random.choice(lengths)
word = random.choice(chars)
for _ in range(length):
try:
word += random.choice(occurences[word[-1]])
except IndexError:
break
result += word + " "
print(result)
lorem.txt
という名前のファイルとSTDINで単語数を入力します。
サンプル:
De Finibus:
ボルテール・モレス・ド・ラムス・セービング・ラム・トゥ・タムクンプ・セコリモ・ミンチ・ア・エム・エンプティ・プル・トゥ・クイーン
ダイ・ヴァンウェンジュン:
Frehwauchmi«
ヴェインジュンヴェンシュヴァンシュタインゲンデュ
Darenenserttem Semint estt
Scklode ツァール
g Zen»
s
ベット
くんレナウン
高慢と偏見:
paime k ホットノック5
”230
エリスZZWedomincab Mrevoueim
Vifedrctogei来るKidi yol qul
”Thant Kie Rag 41
mf vate 12
Eled 8
データ1
mbベッド
”悲しいことに、悲しいことに、
何か
ハルヒンディン
そして最後に、マグナカルタ:
wincand zisend s
CEFured indons fequ
dindshay ranenゴフン OURore
ibec 6248 Rofonestheasaven
スルナール
232レンダリング
マーティンr
Uiconlicend
ucriof 7 ashesevenye Gerd
ビーンズ・オブ・ザ・ビーイング20000
UREndit mandira 0000000000s a
wic 47 Enccet
それは私の最高の仕事ではありません。
私がここでやっているのは、元のテキストを単純なマルコフ連鎖で再現したものであり、与えられたテキストのすべての長さのリストから単語長を取ったものです。
私はより良い結果が期待されていますが、まあまあです。