holylovenia
commited on
Commit
•
ff92401
1
Parent(s):
4f7c463
Upload processing.py with huggingface_hub
Browse files- processing.py +75 -0
processing.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
|
4 |
+
import re
|
5 |
+
|
6 |
+
def parse_text(data):
|
7 |
+
"""
|
8 |
+
Parses a list of text data into English and Lio language lists.
|
9 |
+
|
10 |
+
Args:
|
11 |
+
data (list): A list of strings containing text data.
|
12 |
+
|
13 |
+
Returns:
|
14 |
+
tuple: A tuple containing two lists: English language data and Lio language data.
|
15 |
+
"""
|
16 |
+
# Clean the data by removing unwanted characters and formatting
|
17 |
+
cleaned_data = [re.sub(r'^\ufeff?\d+\t|\b\d+\)\s*', '', re.sub(r'\t+', '\t', text)).replace('\t\n', '').replace('\ufeff', '') for text in data]
|
18 |
+
|
19 |
+
# Split the data into English and Lio lists
|
20 |
+
eng_data, lio_data = [], []
|
21 |
+
sublist = []
|
22 |
+
|
23 |
+
for item in cleaned_data:
|
24 |
+
# Replace tabs with spaces
|
25 |
+
item = item.replace('\t', ' ')
|
26 |
+
if item != '':
|
27 |
+
sublist.append(item)
|
28 |
+
else:
|
29 |
+
if sublist:
|
30 |
+
# Append sublist to result if not empty
|
31 |
+
eng_data.append(sublist[-1])
|
32 |
+
lio_data.append(sublist[0])
|
33 |
+
sublist = []
|
34 |
+
|
35 |
+
# Append the remaining sublist if any
|
36 |
+
if sublist:
|
37 |
+
eng_data.append(sublist[-1])
|
38 |
+
lio_data.append(sublist[0])
|
39 |
+
|
40 |
+
return eng_data, lio_data
|
41 |
+
|
42 |
+
def parse_wordlist(data):
|
43 |
+
"""
|
44 |
+
Parses a word list for translation into English, Indonesian, and Nage languages.
|
45 |
+
|
46 |
+
Args:
|
47 |
+
data (list): A list of strings containing word list data.
|
48 |
+
|
49 |
+
Returns:
|
50 |
+
tuple: A tuple containing three lists: English words, Indonesian words, and Nage words.
|
51 |
+
"""
|
52 |
+
# Clean the data by removing unwanted characters and formatting
|
53 |
+
cleaned_data = [re.sub(r'^\ufeff?\d+\t|\b\d+\)\s*', '', re.sub(r'\t+', '\t', text)).replace('\t\n', '').replace('\ufeff', '') for text in data]
|
54 |
+
|
55 |
+
# Remove empty elements
|
56 |
+
cleaned_data = [elem for elem in cleaned_data if elem != '']
|
57 |
+
|
58 |
+
eng_word = []
|
59 |
+
nage_word = []
|
60 |
+
ind_word = []
|
61 |
+
|
62 |
+
for item in cleaned_data:
|
63 |
+
split_data = item.split()
|
64 |
+
# make sure that we only get [eng, ind, nage] because the actual wordlist have
|
65 |
+
# added 'comment' column and not all the words have their comments
|
66 |
+
if len(split_data) == 3:
|
67 |
+
eng_word.append(split_data[0])
|
68 |
+
ind_word.append(split_data[1])
|
69 |
+
nage_word.append(split_data[2])
|
70 |
+
|
71 |
+
return eng_word, ind_word, nage_word
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|