-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONizer.py
55 lines (49 loc) · 1.47 KB
/
JSONizer.py
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
import json
class JSONizer:
attempts = []
analysis_res = []
curr_shatr_num = 0
iter_nums = {} #dictionary of int->int
@staticmethod
def attempt(attempt_txt, aroodi_style, wazn_10, wazn_mismatch, cut_attempt, text_mismatch, tf3lat, wazn_name, feedback=None):
if JSONizer.curr_shatr_num not in JSONizer.iter_nums.keys():
JSONizer.iter_nums[JSONizer.curr_shatr_num] = 0
JSONizer.iter_nums[JSONizer.curr_shatr_num] += 1
d = {"shatr_idx":JSONizer.curr_shatr_num,
"iteration_number":JSONizer.iter_nums[JSONizer.curr_shatr_num],
"attempt_text":attempt_txt,
"aroodi_style":aroodi_style,
"wazn_comb":wazn_10,
"wazn_mismatch":wazn_mismatch,
"cut_attempt_text":cut_attempt,
"text_mismatch": text_mismatch,
"tf3elat": tf3lat if tf3lat else "(لم يعثر على تفعيلات)",
"feedback":feedback,
"wazn_name":wazn_name}
JSONizer.attempts.append(d)
@staticmethod
def nextShatr():
JSONizer.curr_shatr_num += 1
@staticmethod
def getGenResponse():
return json.dumps(
{ "type":"generate",
"attempts":JSONizer.attempts
}
)
@staticmethod
def resetResponse():
JSONizer.attempts.clear()
JSONizer.curr_shatr_num = 0
JSONizer.iter_nums.clear() #dictionary of int->int
@staticmethod
def getAnalyzerResponse():
return json.dumps(
{
"type":"analyze",
"analyzed_shatrs": JSONizer.attempts
}
)
if __name__ == "__main__":
#JSONizer.attempt(32, 2, "hi", "hiii", "101011", "GGRRR")
print(JSONizer.getGenResponse())