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