천현우

TTP: update functions for ttp

1 -1.
2 -2.
3 -3.
...\ No newline at end of file ...\ No newline at end of file
1 +'기본 함수 사용',
2 + '인풋', -> input()
3 + '스플릿', -> .split()
4 +
5 + '프린트', -> print(
6 + '섬', -> sum(
7 + '맥스', -> max(
8 + '민' -> min(
9 + '렌' -> len(
10 + '수식' -> +, -, *, /, 몫, 나머지
11 + => 뒤에 나오는걸 parameter로 넣어야 함
12 +
13 +'변수 선언' -> 문자, 숫자, 리스트, 함수
14 + 는 -> =
15 + 첫번째 - -> =
16 + 리스트 -> c는 빈 리스트-> c = []
17 + c는 숫자 리스트 1 2 3 4 5 6 -> c = [1, 2, 3, 4, 5, 6]
18 + c는 문자 리스트 a b c d -> c = ['a', 'b', 'c', 'd']
19 +
20 +'반복문 선언'
21 + for a in range -> for a in range(
22 + for i in (li):
23 + while -> while(
24 +
25 +'조건문 선언'
26 + if -> if(
27 + else if -> elif(
28 + else -> else:
29 +
30 +'함수 선언'
31 + aaa -> def aaa(
32 +
33 +'완료' -> tab 빼기
34 +
35 +'파라미터 선언'
36 + a b c -> a, b, c):
37 +
38 +'논리 식 선언'
39 + 1: A는 B 와 같다 -> A == B):
40 + 2: A는 B 보다 크다 -> A > B):
41 + 5: A는 B 보다 크거나 같다 -> A >= B):
42 + 6: A는 B 보다 작거나 같다 -> A <= B):
43 + 7: A는 B 보다 작다 -> A < B):
......
...@@ -1390,8 +1390,7 @@ function uploadTranscriptData(txt) { ...@@ -1390,8 +1390,7 @@ function uploadTranscriptData(txt) {
1390 request.onload = function(e) { 1390 request.onload = function(e) {
1391 if(this.readyState === 4) { 1391 if(this.readyState === 4) {
1392 console.log(e.target.responseText) 1392 console.log(e.target.responseText)
1393 - input_line += e.target.responseText + '\n'; 1393 + input_line += e.target.responseText;
1394 - console.log(input_line)
1395 sourceEditor.setValue(input_line); 1394 sourceEditor.setValue(input_line);
1396 } 1395 }
1397 }; 1396 };
......
...@@ -20,7 +20,14 @@ async function testGoogleTextToSpeech(audioBuffer) { ...@@ -20,7 +20,14 @@ async function testGoogleTextToSpeech(audioBuffer) {
20 '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE', 20 '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
21 '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크다', 21 '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크다',
22 '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작다', 22 '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작다',
23 - 'for OOV_CLASS_ALPHA_SEQUENCE in range $OOV_CLASS_ALPHANUMERIC_SEQUENCE', 23 + '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 와 같다',
24 + '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 작거나 같다',
25 + '$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 $OOV_CLASS_ALPHANUMERIC_SEQUENCE 보다 크거나 같다',
26 + 'for $OOV_CLASS_ALPHA_SEQUENCE in',
27 + 'for $OOV_CLASS_ALPHA_SEQUENCE in',
28 + '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 빈 리스트',
29 + '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 숫자 리스트 $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
30 + '$$OOV_CLASS_ALPHANUMERIC_SEQUENCE 는 문자 리스트 $OOV_CLASS_ALPHANUMERIC_SEQUENCE',
24 'if', 31 'if',
25 '이프', 32 '이프',
26 'else if', 33 'else if',
...@@ -30,12 +37,22 @@ async function testGoogleTextToSpeech(audioBuffer) { ...@@ -30,12 +37,22 @@ async function testGoogleTextToSpeech(audioBuffer) {
30 'while', 37 'while',
31 '와일', 38 '와일',
32 '함수', 39 '함수',
33 - '파라미터', 40 + '파라미터 선언',
34 'parameter', 41 'parameter',
35 '변수 선언', 42 '변수 선언',
36 '함수 선언', 43 '함수 선언',
37 '반복문 선언', 44 '반복문 선언',
38 - '조건문 선언' 45 + '조건문 선언',
46 + '기본 함수 사용',
47 + '인풋',
48 + '스플릿',
49 + '프린트',
50 + '섬',
51 + '맥스',
52 + '민',
53 + '렌',
54 + '리턴',
55 + '리스트'
39 ], 56 ],
40 boost: 20 57 boost: 20
41 }] 58 }]
...@@ -56,6 +73,164 @@ async function testGoogleTextToSpeech(audioBuffer) { ...@@ -56,6 +73,164 @@ async function testGoogleTextToSpeech(audioBuffer) {
56 .map(result => result.alternatives[0].transcript); 73 .map(result => result.alternatives[0].transcript);
57 return transcription; 74 return transcription;
58 } 75 }
76 +let before_val = '';
77 +let tab = '';
78 +let ent = '';
79 +async function TextToPython(trans_data) {
80 + let text_list = trans_data.split(' ');
81 + console.log(text_list);
82 + switch (text_list[0]){
83 + case '기본':
84 + before_val = text_list[0];
85 + switch (text_list[3]){
86 + case '프린트':
87 + return tab + 'print(';
88 + case '인풋':
89 + return tab + 'input()';
90 + case '스플릿':
91 + return '.split()';
92 + case '섬':
93 + return 'sum(';
94 + case '맥스':
95 + return 'max(';
96 + case '민':
97 + return 'min(';
98 + case '렌':
99 + return 'len(';
100 + }
101 + break;
102 + case '파라미터':
103 + if (text_list.length < 3) return '';
104 + if (before_val == '기본'){
105 + before_val = '파라미터';
106 + return text_list.slice(2).join() + ')\n';
107 + }
108 + else{
109 + before_val = '파라미터';
110 + tab += '\t';
111 + return text_list.slice(2).join() + '):\n';
112 + }
113 + break;
114 + case '변수':
115 + if (before_val == '기본'){
116 + ent = '\n';
117 + }
118 + else{
119 + ent = '';
120 + }
121 + before_val = '변수';
122 + if (text_list.length < 4) return '';
123 + if (text_list[2] == '문자'){
124 + if (text_list[3][text_list[3].length-1] == '는'){
125 + return ent + tab + text_list[3].slice(0, text_list[3].length-1) + ' = "' + text_list.slice(4).join(' ') + '"\n';
126 + }
127 + else{
128 + text_list[4] = '= "';
129 + return ent + tab + text_list.slice(3).join(' ') + '"\n';
130 + }
131 + }
132 + else if (text_list[2] == '숫자'){
133 + if (text_list[3][text_list[3].length-1] == '는'){
134 + return ent + tab + text_list[3].slice(0, text_list[3].length-1) + ' = ' + text_list.slice(4).join(' ') + '\n';
135 + }
136 + else if (text_list[4] == '-'){
137 + text_list[4] = '=';
138 + return ent + tab + text_list.slice(3).join(' ') + '\n';
139 + }
140 + }
141 + else if (text_list[2] == '함수'){
142 + if (text_list[3][text_list[3].length-1] == '는'){
143 + return ent + tab + text_list[3].slice(0, text_list[3].length-1) + ' = ';
144 + }
145 + else{
146 + text_list[4] = '=';
147 + return ent + tab + text_list.slice(3)
148 + }
149 + }
150 + else if (text_list[2] == '리스트'){
151 + if (text_list[3][text_list[3].length-1] == '는'){
152 + if (text_list[4] == '빈') return ent + tab + text_list[3].slice(0, text_list[3].length-1) + ' = []\n';
153 + else if (text_list[4] == '숫자') ent + tab + text_list[3].slice(0, text_list[3].length-1) + ' = [' + text_list.slice(6).join(',') + ']\n';
154 + else return ent + tab + text_list[3].slice(0, text_list[3].length-1) + ' = ["' + text_list.slice(6).join('","') + '"]\n';
155 + }
156 + }
157 + else return '';
158 + break;
159 + case '반복문':
160 + if (before_val == '기본'){
161 + ent = '\n';
162 + }
163 + else{
164 + ent = '';
165 + }
166 + if (text_list[3] == 'for'){
167 + return ent + tab + text_list.slice(3).join(' ') + ' ('
168 + }
169 + else if (text_list[3] == 'while' || text_list[3] == '와일'){
170 + return ent + tab + 'while (';
171 + }
172 + else return '';
173 + break;
174 + case '완료':
175 + tab.slice(1);
176 + return '';
177 + break;
178 + case '함수':
179 + if (before_val == '기본'){
180 + ent = '\n';
181 + }
182 + else{
183 + ent = '';
184 + }
185 + if (text_list.length >= 3) return 'def ' + text_list.slice(2).join('') + '(';
186 + else return '';
187 + case '조건문':
188 + if (before_val == '기본'){
189 + ent = '\n';
190 + }
191 + else{
192 + ent = '';
193 + }
194 + if (text_list.length >= 3){
195 + if (text_list[3] == 'if' || text_list[3] == '이프'){
196 + return tab + 'if (';
197 + }
198 + else if ((text_list[3] == 'else' || text_list[3] == '엘스')){
199 + tab += 1;
200 + return '\t'*(tab-1) + 'else:\n'
201 + }
202 + else if((text_list[3] == 'else' || text_list[3] == '엘스') && (text_list[4] == 'if' || text_list[4] == '이프')){
203 + return tab + 'elif (';
204 + }
205 + }
206 + else return '';
207 + break;
208 + case '논리':
209 + if (text_list.length >= 7){
210 + tab += 1;
211 + if (text_list[6] == '같다'){
212 + return tab + text_list[3].slice(0, text_list[3].length-1) + ' == ' + text_list[4] + '):\n';
213 + }
214 + else if(text_list[6] == '크다'){
215 + return tab + text_list[3].slice(0, text_list[3].length-1) + ' > ' + text_list[4] + '):\n';
216 + }
217 + else if(text_list[6] == '작다'){
218 + return tab + text_list[3].slice(0, text_list[3].length-1) + ' < ' + text_list[4] + '):\n';
219 + }
220 + else if(text_list[6] == '크거나'){
221 + return tab + text_list[3].slice(0, text_list[3].length-1) + ' >= ' + text_list[4] + '):\n';
222 + }
223 + else if(text_list[6] == '작거나'){
224 + return tab + text_list[3].slice(0, text_list[3].length-1) + ' <= ' + text_list[4] + '):\n';
225 + }
226 + }
227 + else return '';
228 + break;
229 + default: return ''
230 + }
231 +
232 +}
233 +
59 app.post('/upload_sound', upload.any(), async (req, res) => { 234 app.post('/upload_sound', upload.any(), async (req, res) => {
60 console.log("Getting text transcription.."); 235 console.log("Getting text transcription..");
61 let transcription = await testGoogleTextToSpeech(req.files[0].buffer); 236 let transcription = await testGoogleTextToSpeech(req.files[0].buffer);
...@@ -64,7 +239,7 @@ app.post('/upload_sound', upload.any(), async (req, res) => { ...@@ -64,7 +239,7 @@ app.post('/upload_sound', upload.any(), async (req, res) => {
64 }); 239 });
65 app.post('/ttp', upload.any(), async (req, res) => { 240 app.post('/ttp', upload.any(), async (req, res) => {
66 console.log("Getting python code.."); 241 console.log("Getting python code..");
67 - let python_code = req.body.transcript_data; 242 + let python_code = await TextToPython(req.body.transcript_data);
68 console.log("Pyton code: " + python_code); 243 console.log("Pyton code: " + python_code);
69 res.status(200).send(python_code); 244 res.status(200).send(python_code);
70 }); 245 });
......