only_ever_generator 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap/app.js +47 -44
- package/dist/card_gen/generate_cards.js +47 -32
- package/dist/constants/prompt_data.js +273 -273
- package/dist/constants/prompts/card_gen_prompt.js +180 -180
- package/dist/constants/prompts/typology_prompt.js +93 -93
- package/dist/logger.js +41 -0
- package/dist/parse/parse_source_content.js +23 -9
- package/dist/typology_gen/generate_typology.js +21 -12
- package/dist/utils/generate_args.js +1 -11
- package/package.json +33 -33
- package/readme.md +23 -23
- package/src/bootstrap/app.ts +150 -141
- package/src/card_gen/generate_cards.ts +251 -239
- package/src/config.ts +6 -6
- package/src/constants/api_constants.ts +2 -2
- package/src/constants/prompt_data.ts +296 -296
- package/src/constants/prompts/card_gen_prompt.ts +372 -372
- package/src/constants/prompts/typology_prompt.ts +202 -202
- package/src/constants/source_data.ts +47 -47
- package/src/gap_fill/calculate_gap_fill.ts +52 -52
- package/src/index.ts +61 -61
- package/src/logger.ts +31 -0
- package/src/parse/parse_card_response.ts +289 -289
- package/src/parse/parse_source_content.ts +94 -81
- package/src/parse/response_format_card.ts +210 -210
- package/src/parse/response_format_typology.ts +43 -43
- package/src/services/open_ai_service.ts +55 -54
- package/src/typology_gen/generate_typology.ts +71 -64
- package/src/utils/generate_args.ts +28 -37
- package/src/utils/parse_openai_response.ts +20 -20
- package/tsconfig.json +12 -12
- package/dist/class/parse/parse_source_content.js +0 -62
- package/dist/class/services/open_ai_service.js +0 -25
- package/dist/parse_response/parse_card_response.js +0 -288
- package/dist/parse_response/response_format_card.js +0 -210
- package/dist/parse_response/response_format_typology.js +0 -47
- package/dist/service/open_ai_request.js +0 -57
|
@@ -1,82 +1,95 @@
|
|
|
1
|
-
export class ParseSourceContent{
|
|
2
|
-
public content: any;
|
|
3
|
-
|
|
4
|
-
titles_to_remove = ['See also', 'References', 'Further reading', 'External links', 'Notes and references', 'Bibliography', 'Notes', 'Cited sources'];
|
|
5
|
-
|
|
6
|
-
constructor(sourceContent:any){
|
|
7
|
-
this.content = sourceContent;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
parseData() {
|
|
11
|
-
if(this.content.type == 'source') {
|
|
12
|
-
let dataAfterRemovingUnWantedBlocks = this.removeSectionsByTitle(this.content.content);
|
|
13
|
-
let afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
|
|
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
|
-
|
|
1
|
+
export class ParseSourceContent{
|
|
2
|
+
public content: any;
|
|
3
|
+
|
|
4
|
+
titles_to_remove = ['See also', 'References', 'Further reading', 'External links', 'Notes and references', 'Bibliography', 'Notes', 'Cited sources'];
|
|
5
|
+
|
|
6
|
+
constructor(sourceContent:any){
|
|
7
|
+
this.content = sourceContent;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
parseData() {
|
|
11
|
+
// if(this.content.type == 'source') {
|
|
12
|
+
let dataAfterRemovingUnWantedBlocks = this.removeSectionsByTitle(this.content.content);
|
|
13
|
+
let afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
|
|
14
|
+
let taxonomy;
|
|
15
|
+
if(this.content.taxonomy){
|
|
16
|
+
taxonomy = this.content.taxonomy
|
|
17
|
+
}else{
|
|
18
|
+
taxonomy = null;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
type: this.content.type,
|
|
22
|
+
title: this.content.title,
|
|
23
|
+
content: afterSanitized,
|
|
24
|
+
headings: this.content.headings,
|
|
25
|
+
taxonomy: this.content.taxonomy,
|
|
26
|
+
}
|
|
27
|
+
// } else if(this.content.type == 'cards'){
|
|
28
|
+
// return {
|
|
29
|
+
// type :'card',
|
|
30
|
+
// title: this.content.title,
|
|
31
|
+
// content: afterSanitized,
|
|
32
|
+
// headings: this.content.headings
|
|
33
|
+
// taxonomy: this.content.taxonomy,
|
|
34
|
+
// };
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
// return JSON.stringify(afterSanitized);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
removeSectionsByTitle(data: Array<any>){
|
|
41
|
+
let dataAfterRemoving = [];
|
|
42
|
+
for(let elem of data){
|
|
43
|
+
if(elem.block_type == 'heading' && this.titles_to_remove.includes(elem.content)){
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if(elem.children){
|
|
47
|
+
elem.children = this.removeSectionsByTitle(elem.children)
|
|
48
|
+
}
|
|
49
|
+
dataAfterRemoving.push(elem)
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
return dataAfterRemoving;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
sanitizeWikiContent(content: String) {
|
|
57
|
+
// Remove newline characters
|
|
58
|
+
content = content.replace(/\\n/g, ' ');
|
|
59
|
+
|
|
60
|
+
// Remove internal link references, keeping only the link text
|
|
61
|
+
// Pattern explanation: [[link|text|index|wiki]] --> text
|
|
62
|
+
content = content.replace(/\[\[.*?\|(.*?)\|.*?\|wiki\]\]/g, '$1');
|
|
63
|
+
|
|
64
|
+
// Remove external links, keeping only the link text
|
|
65
|
+
// Pattern explanation: [url text] --> text
|
|
66
|
+
content = content.replace(/\[http[s]?:\/\/[^\s]+ ([^\]]+)\]/g, '$1');
|
|
67
|
+
|
|
68
|
+
// Remove Markdown link references, keeping only the link text
|
|
69
|
+
// Pattern explanation:  --> link text
|
|
70
|
+
content = content.replace(/\!\[([^\]]+)\]\([^\)]+\)/g, '$1');
|
|
71
|
+
|
|
72
|
+
return content;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
sanitizeBlocks(blocks: Array<any>) {
|
|
76
|
+
let sanitizedBlocks = <any>[] ;
|
|
77
|
+
blocks.forEach(block => {
|
|
78
|
+
let sanitizedBlock: any = {};
|
|
79
|
+
for (let key in block) {
|
|
80
|
+
let value = block[key];
|
|
81
|
+
if (typeof value === 'string') {
|
|
82
|
+
sanitizedBlock[key] = this.sanitizeWikiContent(value);
|
|
83
|
+
} else if (Array.isArray(value)) {
|
|
84
|
+
sanitizedBlock[key] = this.sanitizeBlocks(value);
|
|
85
|
+
} else {
|
|
86
|
+
sanitizedBlock[key] = value;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
sanitizedBlocks.push(sanitizedBlock);
|
|
90
|
+
});
|
|
91
|
+
return sanitizedBlocks;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
82
95
|
}
|
|
@@ -1,211 +1,211 @@
|
|
|
1
|
-
const responseData = {
|
|
2
|
-
"flash_cards": [
|
|
3
|
-
{
|
|
4
|
-
"question": "What is the primary function of the 'Electrolysis'?",
|
|
5
|
-
"answer": "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
6
|
-
"heading": "Overview"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"question": "What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
|
|
10
|
-
"answer": "Michael Faraday discovered two laws of electrolysis.",
|
|
11
|
-
"heading": "History"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"question": "What can electrolysis be used for in the manufacturing sector?",
|
|
15
|
-
"answer": "Electrolysis can be used for electroplating and electrochemical machining.",
|
|
16
|
-
"heading": "Manufacturing processes"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"question": "In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
|
|
20
|
-
"answer": "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
|
|
21
|
-
"heading": "Decomposition potential"
|
|
22
|
-
}
|
|
23
|
-
],
|
|
24
|
-
"mcqs": [
|
|
25
|
-
{
|
|
26
|
-
"question": "What is the primary purpose of 'Electrometallurgy'?",
|
|
27
|
-
"answers": [
|
|
28
|
-
{
|
|
29
|
-
"answer": "Production of aluminium",
|
|
30
|
-
"is_correct": true
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"answer": "Chlorine production",
|
|
34
|
-
"is_correct": false
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"answer": "Purifying copper",
|
|
38
|
-
"is_correct": false
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"answer": "Rust removal",
|
|
42
|
-
"is_correct": false
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"answer": "Hydrogen production",
|
|
46
|
-
"is_correct": false
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
"heading": "Industrial uses"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"question": "What can electrolysis be used for in the context of batteries?",
|
|
53
|
-
"answers": [
|
|
54
|
-
{
|
|
55
|
-
"answer": "Spontaneous redox reactions",
|
|
56
|
-
"is_correct": true
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"answer": "Energy-releasing reactions",
|
|
60
|
-
"is_correct": false
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"answer": "Disinfectant production",
|
|
64
|
-
"is_correct": false
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"answer": "Fuel production",
|
|
68
|
-
"is_correct": false
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"answer": "Gas diffusion in reactors",
|
|
72
|
-
"is_correct": false
|
|
73
|
-
}
|
|
74
|
-
],
|
|
75
|
-
"heading": "Related processes"
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
"cloze_cards": [
|
|
79
|
-
{
|
|
80
|
-
"question": "Electrolysis is the passing of a {{c0:direct electric current}} through an {{c1:electrolyte}} producing {{c2:chemical reactions}} at the {{c3:electrodes}} and {{c4:decomposition}} of the materials.",
|
|
81
|
-
"options": [
|
|
82
|
-
{
|
|
83
|
-
"option": "direct electric current",
|
|
84
|
-
"cloze": "c0"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"option": "electrolyte",
|
|
88
|
-
"cloze": "c1"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"option": "chemical reactions",
|
|
92
|
-
"cloze": "c2"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"option": "electrodes",
|
|
96
|
-
"cloze": "c3"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"option": "decomposition",
|
|
100
|
-
"cloze": "c4"
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
"option": "metallic objects",
|
|
104
|
-
"cloze": null
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
"question": "In electrolysis, the decomposition potential or decomposition voltage refers to the minimum voltage between {{c0:anode}} and {{c1:cathode}} of an electrolytic cell needed for electrolysis to occur.",
|
|
110
|
-
"options": [
|
|
111
|
-
{
|
|
112
|
-
"option": "anode",
|
|
113
|
-
"cloze": "c0"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"option": "cathode",
|
|
117
|
-
"cloze": "c1"
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"option": "electrolyte",
|
|
121
|
-
"cloze": null
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
"option": "chemical reactions",
|
|
125
|
-
"cloze": null
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
"option": "oxygen",
|
|
129
|
-
"cloze": null
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
"option": "hydrogen",
|
|
133
|
-
"cloze": null
|
|
134
|
-
}
|
|
135
|
-
]
|
|
136
|
-
}
|
|
137
|
-
]
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
export function returnResponse(){
|
|
142
|
-
return responseData;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function parseResponse(){
|
|
146
|
-
let cardData = [];
|
|
147
|
-
let data = returnResponse();
|
|
148
|
-
let keys = Object.keys(data);
|
|
149
|
-
if(keys){
|
|
150
|
-
for(let elem of keys){
|
|
151
|
-
if(elem == 'flash_cards'){
|
|
152
|
-
cardData.push(...parseFlashCard(data.flash_cards))
|
|
153
|
-
}else if(elem == 'cloze_cards'){
|
|
154
|
-
cardData.push(...parseClozeCards(data.cloze_cards))
|
|
155
|
-
}else if(elem == 'mcqs'){
|
|
156
|
-
cardData.push(...parseMcq(data.mcqs))
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return cardData;
|
|
161
|
-
}
|
|
162
|
-
/// takes array of
|
|
163
|
-
function parseFlashCard(cards: Array<any>){
|
|
164
|
-
let flashCardData = [];
|
|
165
|
-
for(let elem of cards){
|
|
166
|
-
flashCardData.push({
|
|
167
|
-
"type":"flash",
|
|
168
|
-
"heading": elem.heading,
|
|
169
|
-
"content": JSON.stringify({
|
|
170
|
-
"front_content": elem.question,
|
|
171
|
-
"back_content": elem.answer
|
|
172
|
-
})
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return flashCardData;
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/// takes array of
|
|
180
|
-
function parseMcq(cardsData: Array<any>){
|
|
181
|
-
let mcqCards= [];
|
|
182
|
-
for(let elem of cardsData){
|
|
183
|
-
mcqCards.push({
|
|
184
|
-
"type":"mcq",
|
|
185
|
-
"heading": elem.heading,
|
|
186
|
-
"content": JSON.stringify({
|
|
187
|
-
"question": elem.question,
|
|
188
|
-
"answers": elem.answers
|
|
189
|
-
})
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
return mcqCards;
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/// takes array of
|
|
197
|
-
function parseClozeCards(cardsData: Array<any>){
|
|
198
|
-
let clozeCards= [];
|
|
199
|
-
for(let elem of cardsData){
|
|
200
|
-
clozeCards.push({
|
|
201
|
-
"type":"cloze",
|
|
202
|
-
"heading": elem.heading,
|
|
203
|
-
"content": JSON.stringify({
|
|
204
|
-
"question": elem.question,
|
|
205
|
-
"options": elem.options
|
|
206
|
-
})
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return clozeCards;
|
|
210
|
-
|
|
1
|
+
const responseData = {
|
|
2
|
+
"flash_cards": [
|
|
3
|
+
{
|
|
4
|
+
"question": "What is the primary function of the 'Electrolysis'?",
|
|
5
|
+
"answer": "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
6
|
+
"heading": "Overview"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"question": "What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
|
|
10
|
+
"answer": "Michael Faraday discovered two laws of electrolysis.",
|
|
11
|
+
"heading": "History"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"question": "What can electrolysis be used for in the manufacturing sector?",
|
|
15
|
+
"answer": "Electrolysis can be used for electroplating and electrochemical machining.",
|
|
16
|
+
"heading": "Manufacturing processes"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"question": "In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
|
|
20
|
+
"answer": "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
|
|
21
|
+
"heading": "Decomposition potential"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"mcqs": [
|
|
25
|
+
{
|
|
26
|
+
"question": "What is the primary purpose of 'Electrometallurgy'?",
|
|
27
|
+
"answers": [
|
|
28
|
+
{
|
|
29
|
+
"answer": "Production of aluminium",
|
|
30
|
+
"is_correct": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"answer": "Chlorine production",
|
|
34
|
+
"is_correct": false
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"answer": "Purifying copper",
|
|
38
|
+
"is_correct": false
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"answer": "Rust removal",
|
|
42
|
+
"is_correct": false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"answer": "Hydrogen production",
|
|
46
|
+
"is_correct": false
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"heading": "Industrial uses"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"question": "What can electrolysis be used for in the context of batteries?",
|
|
53
|
+
"answers": [
|
|
54
|
+
{
|
|
55
|
+
"answer": "Spontaneous redox reactions",
|
|
56
|
+
"is_correct": true
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"answer": "Energy-releasing reactions",
|
|
60
|
+
"is_correct": false
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"answer": "Disinfectant production",
|
|
64
|
+
"is_correct": false
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"answer": "Fuel production",
|
|
68
|
+
"is_correct": false
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"answer": "Gas diffusion in reactors",
|
|
72
|
+
"is_correct": false
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"heading": "Related processes"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"cloze_cards": [
|
|
79
|
+
{
|
|
80
|
+
"question": "Electrolysis is the passing of a {{c0:direct electric current}} through an {{c1:electrolyte}} producing {{c2:chemical reactions}} at the {{c3:electrodes}} and {{c4:decomposition}} of the materials.",
|
|
81
|
+
"options": [
|
|
82
|
+
{
|
|
83
|
+
"option": "direct electric current",
|
|
84
|
+
"cloze": "c0"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"option": "electrolyte",
|
|
88
|
+
"cloze": "c1"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"option": "chemical reactions",
|
|
92
|
+
"cloze": "c2"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"option": "electrodes",
|
|
96
|
+
"cloze": "c3"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"option": "decomposition",
|
|
100
|
+
"cloze": "c4"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"option": "metallic objects",
|
|
104
|
+
"cloze": null
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"question": "In electrolysis, the decomposition potential or decomposition voltage refers to the minimum voltage between {{c0:anode}} and {{c1:cathode}} of an electrolytic cell needed for electrolysis to occur.",
|
|
110
|
+
"options": [
|
|
111
|
+
{
|
|
112
|
+
"option": "anode",
|
|
113
|
+
"cloze": "c0"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"option": "cathode",
|
|
117
|
+
"cloze": "c1"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"option": "electrolyte",
|
|
121
|
+
"cloze": null
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"option": "chemical reactions",
|
|
125
|
+
"cloze": null
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"option": "oxygen",
|
|
129
|
+
"cloze": null
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"option": "hydrogen",
|
|
133
|
+
"cloze": null
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
export function returnResponse(){
|
|
142
|
+
return responseData;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function parseResponse(){
|
|
146
|
+
let cardData = [];
|
|
147
|
+
let data = returnResponse();
|
|
148
|
+
let keys = Object.keys(data);
|
|
149
|
+
if(keys){
|
|
150
|
+
for(let elem of keys){
|
|
151
|
+
if(elem == 'flash_cards'){
|
|
152
|
+
cardData.push(...parseFlashCard(data.flash_cards))
|
|
153
|
+
}else if(elem == 'cloze_cards'){
|
|
154
|
+
cardData.push(...parseClozeCards(data.cloze_cards))
|
|
155
|
+
}else if(elem == 'mcqs'){
|
|
156
|
+
cardData.push(...parseMcq(data.mcqs))
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return cardData;
|
|
161
|
+
}
|
|
162
|
+
/// takes array of
|
|
163
|
+
function parseFlashCard(cards: Array<any>){
|
|
164
|
+
let flashCardData = [];
|
|
165
|
+
for(let elem of cards){
|
|
166
|
+
flashCardData.push({
|
|
167
|
+
"type":"flash",
|
|
168
|
+
"heading": elem.heading,
|
|
169
|
+
"content": JSON.stringify({
|
|
170
|
+
"front_content": elem.question,
|
|
171
|
+
"back_content": elem.answer
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return flashCardData;
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// takes array of
|
|
180
|
+
function parseMcq(cardsData: Array<any>){
|
|
181
|
+
let mcqCards= [];
|
|
182
|
+
for(let elem of cardsData){
|
|
183
|
+
mcqCards.push({
|
|
184
|
+
"type":"mcq",
|
|
185
|
+
"heading": elem.heading,
|
|
186
|
+
"content": JSON.stringify({
|
|
187
|
+
"question": elem.question,
|
|
188
|
+
"answers": elem.answers
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return mcqCards;
|
|
193
|
+
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/// takes array of
|
|
197
|
+
function parseClozeCards(cardsData: Array<any>){
|
|
198
|
+
let clozeCards= [];
|
|
199
|
+
for(let elem of cardsData){
|
|
200
|
+
clozeCards.push({
|
|
201
|
+
"type":"cloze",
|
|
202
|
+
"heading": elem.heading,
|
|
203
|
+
"content": JSON.stringify({
|
|
204
|
+
"question": elem.question,
|
|
205
|
+
"options": elem.options
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return clozeCards;
|
|
210
|
+
|
|
211
211
|
}
|