(self)
| 110 | self.clean_text() |
| 111 | |
| 112 | def clean_text(self): |
| 113 | sp = StringProcess() |
| 114 | word_lst = list() |
| 115 | with open(self.corpus_name, mode="rb", encoding=self.encoding) as fin: |
| 116 | for indx, item in tqdm(enumerate(fin), desc="clean the text"): |
| 117 | data = item.strip().decode('latin1') |
| 118 | data = sp.clean_str(data) |
| 119 | if self.dataset not in {"mr"}: |
| 120 | data = sp.remove_stopword(data) |
| 121 | word_lst.extend(data.split()) |
| 122 | |
| 123 | word_st = set() |
| 124 | if self.dataset not in {"mr"}: |
| 125 | for word, value in Counter(word_lst).items(): |
| 126 | if value < 5: |
| 127 | continue |
| 128 | word_st.add(word) |
| 129 | else: |
| 130 | word_st = set(word_lst) |
| 131 | |
| 132 | doc_len_lst = list() |
| 133 | with open(self.save_name, mode='w') as fout: |
| 134 | with open(self.corpus_name, mode="rb", encoding=self.encoding) as fin: |
| 135 | for line in tqdm(fin): |
| 136 | lines_str = line.strip().decode('latin1') |
| 137 | lines_str = sp.clean_str(lines_str) |
| 138 | if self.dataset not in {"mr"}: |
| 139 | lines_str = sp.remove_stopword(lines_str) |
| 140 | lines_str = remove_less_word(lines_str, word_st) |
| 141 | |
| 142 | fout.write(lines_str) |
| 143 | fout.write(" \n") |
| 144 | |
| 145 | doc_len_lst.append(len(lines_str.split())) |
| 146 | |
| 147 | print("Average length:", np.mean(doc_len_lst)) |
| 148 | print("doc count:", len(doc_len_lst)) |
| 149 | print("Total number of words:", len(word_st)) |
| 150 | |
| 151 | |
| 152 | def main(): |
no test coverage detected