Spaces:
Sleeping
Sleeping
Update convert2list.py
Browse files- convert2list.py +36 -55
convert2list.py
CHANGED
@@ -1,55 +1,36 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if unmatched_text:
|
38 |
-
matched_words.append(unmatched_text)
|
39 |
-
|
40 |
-
# Join matched words and unmatched text with a space
|
41 |
-
result = ' '.join(matched_words)
|
42 |
-
return result
|
43 |
-
|
44 |
-
# text = "जीरोएकदोतीनचारपांचछहसातआठनौदसजीरोएकदोतीनचारपांच"
|
45 |
-
|
46 |
-
# if __name__=="__main__":
|
47 |
-
# converted=convert_to_list(text, text_to_list())
|
48 |
-
# print(converted)
|
49 |
-
|
50 |
-
|
51 |
-
# In[ ]:
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
1 |
+
# import nbimporter
|
2 |
+
import nbimporter
|
3 |
+
from Text2List import text_to_list
|
4 |
+
def convert_to_list(text, text_list):
|
5 |
+
matched_words = []
|
6 |
+
unmatched_text = '' # To accumulate unmatched characters
|
7 |
+
|
8 |
+
# Sort text_list by length in descending order to prioritize longest matches first
|
9 |
+
text_list_sorted = sorted(text_list, key=len, reverse=True)
|
10 |
+
|
11 |
+
while text:
|
12 |
+
matched = False
|
13 |
+
for word in text_list_sorted:
|
14 |
+
if text.startswith(word):
|
15 |
+
# Add any accumulated unmatched text before appending the matched word
|
16 |
+
if unmatched_text:
|
17 |
+
matched_words.append(unmatched_text)
|
18 |
+
unmatched_text = '' # Reset unmatched text accumulator
|
19 |
+
|
20 |
+
matched_words.append(word)
|
21 |
+
text = text[len(word):] # Remove the matched part from text
|
22 |
+
matched = True
|
23 |
+
break
|
24 |
+
|
25 |
+
if not matched:
|
26 |
+
# Accumulate unmatched characters
|
27 |
+
unmatched_text += text[0]
|
28 |
+
text = text[1:]
|
29 |
+
|
30 |
+
# If there's any remaining unmatched text, add it to the result
|
31 |
+
if unmatched_text:
|
32 |
+
matched_words.append(unmatched_text)
|
33 |
+
|
34 |
+
# Join matched words and unmatched text with a space
|
35 |
+
result = ' '.join(matched_words)
|
36 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|