ここに私の基準があります:
聖書全体のテキストのコピーを入手する
これは、開いたり、読んだり、フィールドに分割したりする準備ができているはずです
これを使用して、bible という名前の永続的な辞書変数を作成します
私が示したように入力すると、プログラムがコマンドラインに入力した内容を認識できるように、Python プログラムをセットアップします。言葉を求めさせないでください。
その参照の意味を解析して、本、章、開始節、および終了節を取得します。その他のバリエーションは、rev 1:1、rev 12、または rev 10:1-3 です。
印刷時には、新しい行に折り返す前に幅 100 文字の出力制限があり、左側に参照が表示され、いくつかのスペースとテキストが右側に配置されるように十分にインデントする必要があります。
テキスト ファイル内のテキストは次のようになります。
0 | gen 1:1 | In the beginning God created the heaven and the earth.
1 | gen 1:2 | And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.
2 | gen 1:3 | And God said, Let there be light: and there was light.
これまでの私のコードは次のようになります。
import os
import sys
import re
word_search = raw_input(r'Enter a word to search: ')
book = open("kjv.txt", "r")
first_lines = {36: 'Genesis', 4812: 'Exodus', 8867: 'Leviticus', 11749: 'Numbers', 15718: 'Deuteronomy',
18909: 'Joshua', 21070: 'Judges', 23340: 'Ruth', 23651: 'I Samuel', 26641: 'II Samuel',
29094: 'I Kings', 31990: 'II Kings', 34706: 'I Chronicles', 37378: 'II Chronicles',
40502: 'Ezra', 41418: 'Nehemiah', 42710: 'Esther', 43352: 'Job', 45937: 'Psalms', 53537: 'Proverbs',
56015: 'Ecclesiastes', 56711: 'The Song of Solomon', 57076: 'Isaih', 61550: 'Jeremiah',
66480: 'Lamentations', 66961: 'Ezekiel', 71548: 'Daniel' }
for ln, line in enumerate(book):
if word_search in line:
first_line = max(l for l in first_lines if l < ln)
bibook = first_lines[first_line]
template = "\nLine: {0}\nString: {1}\nBook:\n"
output = template.format(ln, line, bibook)
print output
私はそれがかなりめちゃくちゃであることを知っているので、私をまっすぐにするのを手伝ってください.
私がやっていると思うことの要約:
テキスト ファイルから辞書を作成し、何らかの方法でユーザーに章と節を入力してもらい、プログラムがそれらの章と節を吐き出せるようにします。