Delete convert2list.ipynb
Browse files- convert2list.ipynb +0 -151
convert2list.ipynb
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": 30,
|
| 6 |
-
"id": "b52e9a66-a8e9-4f56-91fd-8564b5b636fc",
|
| 7 |
-
"metadata": {},
|
| 8 |
-
"outputs": [
|
| 9 |
-
{
|
| 10 |
-
"name": "stdout",
|
| 11 |
-
"output_type": "stream",
|
| 12 |
-
"text": [
|
| 13 |
-
"जीरो एक दो तीन चार पांच छह सात आठ नौ दस जीरो एक दो तीन चार पांच\n"
|
| 14 |
-
]
|
| 15 |
-
}
|
| 16 |
-
],
|
| 17 |
-
"source": [
|
| 18 |
-
"# import nbimporter\n",
|
| 19 |
-
"import nbimporter\n",
|
| 20 |
-
"from Text2List import text_to_list\n",
|
| 21 |
-
"def convert_to_list(text, text_list):\n",
|
| 22 |
-
" matched_words = []\n",
|
| 23 |
-
" unmatched_text = '' # To accumulate unmatched characters\n",
|
| 24 |
-
"\n",
|
| 25 |
-
" # Sort text_list by length in descending order to prioritize longest matches first\n",
|
| 26 |
-
" text_list_sorted = sorted(text_list, key=len, reverse=True)\n",
|
| 27 |
-
"\n",
|
| 28 |
-
" while text:\n",
|
| 29 |
-
" matched = False\n",
|
| 30 |
-
" for word in text_list_sorted:\n",
|
| 31 |
-
" if text.startswith(word):\n",
|
| 32 |
-
" # Add any accumulated unmatched text before appending the matched word\n",
|
| 33 |
-
" if unmatched_text:\n",
|
| 34 |
-
" matched_words.append(unmatched_text)\n",
|
| 35 |
-
" unmatched_text = '' # Reset unmatched text accumulator\n",
|
| 36 |
-
"\n",
|
| 37 |
-
" matched_words.append(word)\n",
|
| 38 |
-
" text = text[len(word):] # Remove the matched part from text\n",
|
| 39 |
-
" matched = True\n",
|
| 40 |
-
" break\n",
|
| 41 |
-
"\n",
|
| 42 |
-
" if not matched:\n",
|
| 43 |
-
" # Accumulate unmatched characters\n",
|
| 44 |
-
" unmatched_text += text[0]\n",
|
| 45 |
-
" text = text[1:]\n",
|
| 46 |
-
"\n",
|
| 47 |
-
" # If there's any remaining unmatched text, add it to the result\n",
|
| 48 |
-
" if unmatched_text:\n",
|
| 49 |
-
" matched_words.append(unmatched_text)\n",
|
| 50 |
-
"\n",
|
| 51 |
-
" # Join matched words and unmatched text with a space\n",
|
| 52 |
-
" result = ' '.join(matched_words)\n",
|
| 53 |
-
" return result\n",
|
| 54 |
-
" \n",
|
| 55 |
-
"text = \"जीरोएकदोतीनचारपांचछहसातआठनौदसजीरोएकदोतीनचारपांच\"\n",
|
| 56 |
-
"\n",
|
| 57 |
-
"if __name__==\"__main__\":\n",
|
| 58 |
-
" converted=convert_to_list(text, text_to_list())\n",
|
| 59 |
-
" print(converted)"
|
| 60 |
-
]
|
| 61 |
-
},
|
| 62 |
-
{
|
| 63 |
-
"cell_type": "code",
|
| 64 |
-
"execution_count": 33,
|
| 65 |
-
"id": "f6655a7c-7481-4a73-a2e6-5327f589bb8b",
|
| 66 |
-
"metadata": {},
|
| 67 |
-
"outputs": [
|
| 68 |
-
{
|
| 69 |
-
"name": "stdout",
|
| 70 |
-
"output_type": "stream",
|
| 71 |
-
"text": [
|
| 72 |
-
"जीरो तीन तीन चार र\n"
|
| 73 |
-
]
|
| 74 |
-
}
|
| 75 |
-
],
|
| 76 |
-
"source": [
|
| 77 |
-
"# # import nbimporter\n",
|
| 78 |
-
"# import nbimporter\n",
|
| 79 |
-
"# from Text2List import text_to_list\n",
|
| 80 |
-
"# def convert_to_list(text, text_list):\n",
|
| 81 |
-
"# matched_words = []\n",
|
| 82 |
-
"# unmatched_text = '' # To accumulate unmatched characters\n",
|
| 83 |
-
"\n",
|
| 84 |
-
"# # Sort text_list by length in descending order to prioritize longest matches first\n",
|
| 85 |
-
"# text_list_sorted = sorted(text_list, key=len, reverse=True)\n",
|
| 86 |
-
"\n",
|
| 87 |
-
"# while text:\n",
|
| 88 |
-
"# matched = False\n",
|
| 89 |
-
"# for word in text_list_sorted:\n",
|
| 90 |
-
"# if word in text:\n",
|
| 91 |
-
"# # Add any accumulated unmatched text before appending the matched word\n",
|
| 92 |
-
"# if unmatched_text:\n",
|
| 93 |
-
"# matched_words.append(unmatched_text)\n",
|
| 94 |
-
"# unmatched_text = '' # Reset unmatched text accumulator\n",
|
| 95 |
-
"\n",
|
| 96 |
-
"# matched_words.append(word)\n",
|
| 97 |
-
"# text = text[len(word):] # Remove the matched part from text\n",
|
| 98 |
-
"# matched = True\n",
|
| 99 |
-
"# break\n",
|
| 100 |
-
"\n",
|
| 101 |
-
"# if not matched:\n",
|
| 102 |
-
"# # Accumulate unmatched characters\n",
|
| 103 |
-
"# unmatched_text += text[0]\n",
|
| 104 |
-
"# text = text[1:]\n",
|
| 105 |
-
"\n",
|
| 106 |
-
"# # If there's any remaining unmatched text, add it to the result\n",
|
| 107 |
-
"# if unmatched_text:\n",
|
| 108 |
-
"# matched_words.append(unmatched_text)\n",
|
| 109 |
-
"\n",
|
| 110 |
-
"# # Join matched words and unmatched text with a space\n",
|
| 111 |
-
"# result = ' '.join(matched_words)\n",
|
| 112 |
-
"# return result\n",
|
| 113 |
-
" \n",
|
| 114 |
-
"# text = \"जीरोएकदोतीनचार\"\n",
|
| 115 |
-
"\n",
|
| 116 |
-
"# if __name__==\"__main__\":\n",
|
| 117 |
-
"# converted=convert_to_list(text, text_to_list())\n",
|
| 118 |
-
"# print(converted)"
|
| 119 |
-
]
|
| 120 |
-
},
|
| 121 |
-
{
|
| 122 |
-
"cell_type": "code",
|
| 123 |
-
"execution_count": null,
|
| 124 |
-
"id": "26b725cd-d14f-4d8a-9829-99a7b9a5eeb3",
|
| 125 |
-
"metadata": {},
|
| 126 |
-
"outputs": [],
|
| 127 |
-
"source": []
|
| 128 |
-
}
|
| 129 |
-
],
|
| 130 |
-
"metadata": {
|
| 131 |
-
"kernelspec": {
|
| 132 |
-
"display_name": "Python 3 (ipykernel)",
|
| 133 |
-
"language": "python",
|
| 134 |
-
"name": "python3"
|
| 135 |
-
},
|
| 136 |
-
"language_info": {
|
| 137 |
-
"codemirror_mode": {
|
| 138 |
-
"name": "ipython",
|
| 139 |
-
"version": 3
|
| 140 |
-
},
|
| 141 |
-
"file_extension": ".py",
|
| 142 |
-
"mimetype": "text/x-python",
|
| 143 |
-
"name": "python",
|
| 144 |
-
"nbconvert_exporter": "python",
|
| 145 |
-
"pygments_lexer": "ipython3",
|
| 146 |
-
"version": "3.11.7"
|
| 147 |
-
}
|
| 148 |
-
},
|
| 149 |
-
"nbformat": 4,
|
| 150 |
-
"nbformat_minor": 5
|
| 151 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|