MCPcopy Index your code
hub / github.com/chengsen/PyTorch_TextGCN / clean_text

Method clean_text

data_processor.py:112–149  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
152def main():

Callers 1

__init__Method · 0.95

Calls 4

clean_strMethod · 0.95
remove_stopwordMethod · 0.95
StringProcessClass · 0.85
remove_less_wordFunction · 0.85

Tested by

no test coverage detected