Пример #1
0
def output_json_book_chapter_verse(input_file):
    BOOK, CHAPTER, VERSE, LENGTH = 0, 1, 2, 5
    i_file = open(input_file, 'r')
    i_file.readline()
    d_book = {}
    for txt in i_file.readlines():
        col = split_line(txt)
#    d_book[col[BOOK]] = d_book.get(col[BOOK], {})
#    d_chapter = d_book.get(col[CHAPTER], {})
#    d_verse = d_chapter.get(col[VERSE], col[LENGTH])
        d_book[col[BOOK]] = d_book.get(col[BOOK], {})
        d_book[col[BOOK]][col[CHAPTER]] = d_book[col[BOOK]].get(col[CHAPTER], {})
#    d_chapter = d_book[col[BOOK]].get(col[CHAPTER], {})
#    d_verse = d_chapter[col[CHAPTER]].get(col[VERSE], col[LENGTH])
        d_book[col[BOOK]][col[CHAPTER]][col[VERSE]] =  d_book[col[BOOK]][col[CHAPTER]].get(col[VERSE], col[LENGTH])

    sorted_chp = sorted(d_book.iteritems(), key=operator.itemgetter(0))

    directory, file_name, extension = file_name_ext(input_file)
    output_filename = directory + '/' + file_name + '-chapter_verse.json'
    o_file = open(output_filename, 'w')

#  json.dump(sorted_chp, o_file)
    json.dump(d_book, o_file)
    o_file.close()
Пример #2
0
def json_out(input_file):

    i_file = open(input_file, 'r')
    i_file.readline()
    d_chapter_names = {}
    for txt in i_file.readlines():
        fields = split_line(txt)
        d_chapter_names[fields[0]] = d_chapter_names.get(fields[0], 0) + 1


    sorted_chp = sorted(d_chapter_names.iteritems(), key=operator.itemgetter(0))

    directory, file_name, extension = file_name_ext(input_file)
    output_filename = directory + '/' + file_name + '-chp_names.json'
    o_file = open(output_filename, 'w')

    json.dump(sorted_chp, o_file)
    o_file.close()
Пример #3
0
def chords_add_header(chapter_index_filename, verse_location, n_gram_path):
    directory, file_name, extension = file_name_ext(chapter_index_filename)
#  chapters = make_dictionary_from_file(chapter_index_filename, sep='\t', key_col=0)
    files = os.listdir(verse_location)

    for f in files:
        directory, file_name, extension = file_name_ext(f)
        chord_filename = n_gram_path + file_name + '_chord.' + extension
        dic_filename = n_gram_path + file_name + '_dic_index.' + extension
        d_file = open(dic_filename, 'r')
        word_header = []
        for txt in d_file.readlines():
            cols = split_line(txt)
            word_header.append(cols[0])
        d_file.close()

        c_txt = get_file_text(chord_filename)

        o_file = open(chord_filename, 'w')
        o_file.write(','.join(word_header) + '\n')
        o_file.write(c_txt)
        o_file.close()