def test_read_file():
    word_list = read_file('oxford3000')
    for word_item in word_list:
        print(word_item)
    print('\n')

    new_item = get_word_item('dgrtyhaha,/hhh/')
    # word_list[1] = new_item
    add_word_item(word_list, new_item)
    for word_item in word_list:
        print(word_item)
    # list_not_exercised, list_all_correct, list_fault = divide_list(word_list)
    #
    # for word_item in list_not_exercised:
    #     print(word_item)
    # print('\n')
    #
    # for word_item in list_all_correct:
    #     print(word_item)
    # print('\n')
    #
    # for word_item in list_fault:
    #     print(word_item)
    # print('\n')

    write_file(word_list, 'oxford3000')
Esempio n. 2
0
def test_read_file():
    word_list = read_file('oxford3000')
    for word_item in word_list:
        print(word_item)
    print('\n')

    new_item = get_word_item('dgrtyhaha,/hhh/')
    # word_list[1] = new_item
    add_word_item(word_list, new_item)
    for word_item in word_list:
        print(word_item)
    # list_not_exercised, list_all_correct, list_fault = divide_list(word_list)
    #
    # for word_item in list_not_exercised:
    #     print(word_item)
    # print('\n')
    #
    # for word_item in list_all_correct:
    #     print(word_item)
    # print('\n')
    #
    # for word_item in list_fault:
    #     print(word_item)
    # print('\n')

    write_file(word_list, 'oxford3000')
def read_file(file_name, what_to_get="sorted_list"):  # returns a list sorted by score
    with open('/home/junlingwang/Desktop/Vocabulary training/'+file_name+'.txt', 'r') as word_file:
        lines = word_file.readlines()  # lines is a list of strings
    word_list = []
    good_word_list = []
    for line in lines:  # line is a string in lines
        word_item_of_line = get_word_item(line.strip())
        if word_item_of_line.weight != 10000: # if weight is 10000, it means this item doesn't need to be practiced any more.
            word_list.append(word_item_of_line)  # strip(), delete blank characters including '\n'
        else:
            good_word_list.append(word_item_of_line)
    sorted_list = sorted(word_list, key=lambda item: item.score, reverse=True)  # word_list is not changed
    #  lambda function. Before the colon is parameter, after the colon is the result.
    # this lambda function is to sort the word list's item by their scores
    if what_to_get == "good_word_list":
        return good_word_list
    else:
        return sorted_list
Esempio n. 4
0
def read_file(file_name,
              what_to_get="sorted_list"):  # returns a list sorted by score
    times_of_wrong = 0
    if what_to_get.isdigit():
        times_of_wrong = int(what_to_get)

    with open(
            '/home/junlingwang/Desktop/Vocabulary training/' + file_name +
            '.txt', 'r') as word_file:
        lines = word_file.readlines()  # lines is a list of strings
    word_list = []
    good_word_list = []
    never_practiced_list = []
    wrong_certain_times_list = []
    for line in lines:  # line is a string in lines
        word_item_of_line = get_word_item(line.strip())
        if word_item_of_line.weight != 10000:  # if weight is 10000, it means this item doesn't need to be practiced any more.
            word_list.append(
                word_item_of_line
            )  # strip(), delete blank characters including '\n'
        if word_item_of_line.score == -2:
            never_practiced_list.append(
                word_item_of_line
            )  # -2 is the score code of "never practiced".
        if word_item_of_line.weight == 10000:
            good_word_list.append(word_item_of_line)
        if word_item_of_line.weight >= times_of_wrong and word_item_of_line.weight != 10000:
            wrong_certain_times_list.append(word_item_of_line)
    sorted_list = sorted(word_list, key=lambda item: item.score,
                         reverse=True)  # word_list is not changed
    #  lambda function. Before the colon is parameter, after the colon is the result.
    # this lambda function is to sort the word list's item by their scores
    if what_to_get == "good_word_list":
        return good_word_list
    elif what_to_get == "never_practiced":
        return never_practiced_list  # currently not in use.
    elif times_of_wrong > 0:
        return wrong_certain_times_list
    else:
        return sorted_list