Esempio n. 1
0
def get_most_common_used_word(str_file_path):
    '''
    Get the most commonly used word from text file
    :param str_file_path: text file path
    :return: A tuple most common used word
    '''
    return Counter(read(str_file_path).lower().split()).most_common(1)[0]
Esempio n. 2
0
def get_words_next_to_right(str_file_path, key_word):
    '''
    Get all words next to right by the key word
    :param str_file_path: Text file path
    :param key_word: The key word
    :return: A List of words next to right by the key word
    '''
    word_next_to_rights = findall(key_word + ' [a-z]+',
                                  read(str_file_path).lower())
    return Counter(word_next_to_rights).most_common()
Esempio n. 3
0
 def tao_dl_tu_dong(self, str_file_data):
     txt = read(str_file_data)
     for line in txt.split('\n'):
         arr_line = line.split(';')
         if arr_line[0] is '0':  # Sach
             self.ds_tai_lieu.append(Sach(arr_line[1], arr_line[2], int(arr_line[3]), arr_line[4], int(arr_line[5])))
         elif arr_line[0] is '1':  # Tap chi
             self.ds_tai_lieu.append(
                 TapChi(arr_line[1], arr_line[2], int(arr_line[3]), int(arr_line[4]), int(arr_line[5])))
         elif arr_line[0] is '2':  # Bao
             self.ds_tai_lieu.append(Bao(arr_line[1], arr_line[2], int(arr_line[3]), int(arr_line[4])))
         else:
             pass
Esempio n. 4
0
 def load_dl(self, str_file_data):
     # f = open(str_file_data, 'r')
     # data = json.load(f)
     # f.close()
     data_rd = read(str_file_data).splitlines()
     for item in data_rd:
         dict_item = literal_eval(item)
         if dict_item['_TaiLieu__loai_tl'] is 0: #Sach
             sach = Sach(dict_item['ma_tl'], dict_item['ten_nxb'], dict_item['so_ban'],dict_item['ten_tg'], dict_item['so_trang'])
             sach.set_loai_tl(0)
             self.ds_tai_lieu.append(sach)
         elif dict_item['_TaiLieu__loai_tl'] is 1: #tap chi
             tapchi = TapChi(dict_item['ma_tl'], dict_item['ten_nxb'], dict_item['so_ban'],dict_item['so_ph'],dict_item['thang_ph'])
             tapchi.set_loai_tl(1)
             self.ds_tai_lieu.append(tapchi)
         elif dict_item['_TaiLieu__loai_tl'] is 2: #bao
             bao = Bao(dict_item['ma_tl'], dict_item['ten_nxb'], dict_item['so_ban'],dict_item['ngay_ph'])
             bao.set_loai_tl(2)
             self.ds_tai_lieu.append(bao)
         else:
             continue
Esempio n. 5
0
import text_utility

file_lyrics = 'lyrics.txt'
file_data = 'data.txt'

str_lyrics = text_utility.read(file_lyrics)
print(str_lyrics)

number_of_lines = text_utility.count_by_lines(file_lyrics)
number_of_words = text_utility.count_by_words(file_lyrics)
number_of_chars = text_utility.count_by_chars(file_lyrics)
print('Number of lines: ', number_of_lines)
print('Number of words: ', number_of_words)
print('Number of chars: ', number_of_chars)

text_utility.erase(file_lyrics)

text_utility.write(file_data, str_lyrics)