forked from gaddisa/Movie-Review-Classification_RNN_LSTM_GRU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoro_number_to_text.php
214 lines (186 loc) · 7.41 KB
/
oro_number_to_text.php
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
function convert_number($number)
{
$Number_Decimal=explode('.',$number);
$number=str_replace(',','',$Number_Decimal[0]);
$rt_1=count($Number_Decimal);
if (($number < 0) || ($number > 9999999999)) {
throw new Exception("Number is out of range");
}
$Bn = floor($number / 1000000000);
/* Billions */
$number -= $Bn * 1000000000;
$Gn = floor($number / 1000000);
/* Millions */
$number -= $Gn * 1000000;
$kn = floor($number / 1000);
/* Thousands */
$number -= $kn * 1000;
$Hn = floor($number / 100);
/* Hundreds */
$number -= $Hn * 100;
$Dn = floor($number / 10);
/* Tens */
$n = $number % 10;
/* Ones */
$res = "";
if ($Bn) {
$res .= " "."Biliyoona ".convert_number($Bn);
}
if ($Gn) {
$res .=" "."Miliyoona ".convert_number($Gn);
}
if ($kn) {
$res .=" "."Kuma"." ".convert_number($kn).(empty($res) ? "" : " ");
}
if ($Hn) {
$res .= " "."Dhibba".(empty($res) ? "" : " ")." " .convert_number($Hn);
}
$ones = array("", "Tokko", "Lama", "Sadii", "Afur", "Shan", "Jaha", "Torba", "Saddeet", "Sagal", "Kudhan", "Kudha-tokko", "Kudha-lama", "Kudha-sadii", "Kudha-afur", "Kudha-shan", "Kudha-jaha", "Kudha-torba", "Kudha-saddet", "Kudha-sagal");
$ones_ext = array("", "tokko", "lama", "sadii", "afur", "shan", "jaha", "torba", "saddeet", "sagal", "Kudhan", "Kudha-tokko", "Kudha-lama", "Kudha-sadii", "Kudha-afur", "Kudha-shan", "Kudha-jaha", "Kudha-torba", "Kudha-saddet", "Kudha-sagal");
$tens = array("", "", "Digdama", "Soddoma", "Afurtama", "Shantama", "Jaatama", "Torbaatama", "Saddettama", "Sagaltama");
if ($Dn || $n) {
if (!empty($res)) {
$xx=substr($res,-1);
if($xx=='n'|| $xx=='r' || $xx=='t'){
$xx.="ii";
$res=substr_replace($res,$xx,-1);
$res .=" fi ";
}
else{
$res .= $xx." fi ";
}
}
if ($Dn < 2) {
$res .= $ones[$Dn * 10 + $n];
} else {
$res .= $tens[$Dn];
if ($n) {
$tt=substr($res,-2);
if($tt=="ma")
$res=substr_replace($res,"mii",-2);
$res .= "-" . $ones_ext[$n];
}
}
}
if (empty($res)) {
$res = "Duwwaa";
}
if($rt_1==2)
{
$number_dc=$Number_Decimal[1];
}
if($rt_1==2){
$array = array_map('intval', str_split($Number_Decimal[1]));
$dec_read='';
for($i=0; $i<count($array);$i++)
{
$dec_read.=' '.convert_number($array[$i]);
}
return $res. " fii Saantima".$dec_read;
}else{
return $res;
}
$output = process_string($res);
// Replace two spaces with one space
$output = preg_replace('/\s{2,}/', ' ', $output);
// Remove spaces before and after hyphens
$res = preg_replace('/\s*-\s*/', '-', $output);
return $res;
}
function process_string($input) {
// Explode the input string into an array of words
$words = explode(" ", $input);
// Check if "Saantima" is present in the array
$index = array_search("Saantima", $words);
if ($index !== false && isset($words[$index + 1]) && isset($words[$index + 2])) {
// Check if there are at least two more words after "Saantima"
$next_word = $words[$index + 1];
$next_next_word = $words[$index + 2];
// Check if the next word is "Tokko"
if ($next_word == "Tokko") {
// Replace "Tokko" with "Kudha" and add a hyphen followed by the last word
$words[$index + 1] = "Kudha-";
$words[$index + 2] = $next_next_word;
}
// Check if the next word is "Lama"
elseif ($next_word == "Lama") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Digdamii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Sadii") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Soddomii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Afur") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Afurtamii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Shan") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Shantamii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Jaha") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Jaatamii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Torba") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Torbaatamii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Saddet") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Saddeettamii-";
$words[$index + 2] = $next_next_word;
}
elseif ($next_word == "Sagal") {
// Replace "Lama" with "Digdama" and add a hyphen followed by the last word
$words[$index + 1] = "Sagaltamii-";
$words[$index + 2] = $next_next_word;
}
}
elseif ($index !== false && isset($words[$index + 1])) {
$next_word = $words[$index + 1];
// Handle the case where there's only one word after "Saantima"
// Replace with your logic here
// For example:
if ($next_word == "Tokko") {
// Replace "Tokko" with "Kudhan"
$words[$index + 1] = "Kudhan";
} elseif ($next_word == "Lama") {
// Replace "Lama" with "Digdama"
$words[$index + 1] = "Digdama";
} elseif ($next_word == "Sadii") {
// Replace "Sadii" with "Soddoma"
$words[$index + 1] = "Soddoma";
} elseif ($next_word == "Afur") {
// Replace "Afur" with "Afurtama"
$words[$index + 1] = "Afurtama";
} elseif ($next_word == "Shan") {
// Replace "Shan" with "Shantama"
$words[$index + 1] = "Shantama";
} elseif ($next_word == "Jaha") {
// Replace "Jaha" with "Jaatama"
$words[$index + 1] = "Jaatama";
} elseif ($next_word == "Torba") {
// Replace "Torba" with "Torbaatama"
$words[$index + 1] = "Torbaatama";
} elseif ($next_word == "Saddet") {
// Replace "Saddet" with "Saddeettama"
$words[$index + 1] = "Saddeettama";
} elseif ($next_word == "Sagal") {
// Replace "Sagal" with "Sagaltama"
$words[$index + 1] = "Sagaltama";
}
}
// Implode the array of words back into a string
$result = implode(" ", $words);
return $result;
}
?>