only_ever_generator 0.0.6 → 0.0.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 +77 -63
- package/dist/card_gen/generate_cards.js +184 -0
- package/dist/constants/api_constants.js +7 -0
- package/dist/constants/prompts/card_gen_prompt.js +30 -24
- package/dist/constants/source_data.js +5 -1
- package/dist/index.js +4 -78
- package/dist/parse/parse_card_response.js +288 -0
- package/dist/parse/parse_source_content.js +62 -0
- package/dist/parse/response_format_card.js +210 -0
- package/dist/parse/response_format_typology.js +47 -0
- package/dist/service/open_ai_request.js +0 -1
- package/dist/services/open_ai_service.js +60 -0
- package/dist/typology_gen/generate_typology.js +14 -6
- package/package.json +1 -1
- package/src/bootstrap/app.ts +74 -64
- package/src/card_gen/generate_cards.ts +192 -0
- package/src/constants/api_constants.ts +3 -0
- package/src/constants/prompts/card_gen_prompt.ts +30 -25
- package/src/constants/source_data.ts +5 -0
- package/src/index.ts +4 -81
- package/src/services/open_ai_service.ts +54 -0
- package/src/typology_gen/generate_typology.ts +18 -10
- package/src/class/services/open_ai_service.ts +0 -18
- package/src/service/open_ai_request.ts +0 -46
- /package/src/{parse_response → parse}/parse_card_response.ts +0 -0
- /package/src/{class/parse → parse}/parse_source_content.ts +0 -0
- /package/src/{parse_response → parse}/response_format_card.ts +0 -0
- /package/src/{parse_response → parse}/response_format_typology.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,90 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.OnlyEverGenerator = void 0;
|
|
13
4
|
// import express from "express";
|
|
14
5
|
// import { returnCardGenPrompt } from "./constants/prompts/card_gen_prompt";
|
|
15
6
|
// import { returnTypologyPrompt } from "./constants/prompts/typology_prompt";
|
|
16
7
|
// import { GenerateArgs } from "./utils/generate_args";
|
|
17
|
-
// import { returnHeadings, returnSourceData } from "./constants/source_data";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const open_ai_service_1 = require("./class/services/open_ai_service");
|
|
21
|
-
const card_gen_prompt_1 = require("./constants/prompts/card_gen_prompt");
|
|
22
|
-
const typology_prompt_1 = require("./constants/prompts/typology_prompt");
|
|
23
|
-
const generate_typology_1 = require("./typology_gen/generate_typology");
|
|
24
|
-
const generate_args_1 = require("./utils/generate_args");
|
|
25
|
-
// import config from "./config";
|
|
26
|
-
// const app = express();
|
|
27
|
-
// const port = 3000;
|
|
28
|
-
/// While Publishing the package , and using this code as a separate npm module
|
|
29
|
-
/// uncomment the below line and comment all the others, expect the import of OnlyEverGenerator
|
|
30
|
-
class OnlyEverGenerator {
|
|
31
|
-
constructor(apiKey, model, content) {
|
|
32
|
-
this.api_key = '';
|
|
33
|
-
this.parsedContent = '';
|
|
34
|
-
this.typologyResponse = {};
|
|
35
|
-
this.cardgenResponse = {};
|
|
36
|
-
this.summarizeResponse = {};
|
|
37
|
-
this.api_key = apiKey;
|
|
38
|
-
this.openAiService = new open_ai_service_1.OpenAiService(apiKey, model !== null && model !== void 0 ? model : 'gpt-3.5-turbo-1106');
|
|
39
|
-
this.parsedContent = new parse_source_content_1.ParseSourceContent(content).parse();
|
|
40
|
-
}
|
|
41
|
-
;
|
|
42
|
-
generate() {
|
|
43
|
-
return __awaiter(this, arguments, void 0, function* (generate_card = false, generate_typology = false) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
let typologyPrompt = (0, typology_prompt_1.returnTypologyPrompt)();
|
|
46
|
-
let cardPrompt = (0, card_gen_prompt_1.returnCardGenPrompt)();
|
|
47
|
-
let args = new generate_args_1.GenerateArgs(generate_card, generate_typology, false, {
|
|
48
|
-
typology_prompt: typologyPrompt,
|
|
49
|
-
card_gen_prompt: cardPrompt,
|
|
50
|
-
summary_prompt: ''
|
|
51
|
-
});
|
|
52
|
-
const responseToReturn = [];
|
|
53
|
-
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
54
|
-
for (let elem of whatNeedsToBeGenerated)
|
|
55
|
-
if (elem == 'generate_tyopology') {
|
|
56
|
-
this.typologyResponse = yield this.generateTypology((_a = args.prompts.typology_prompt) !== null && _a !== void 0 ? _a : '');
|
|
57
|
-
responseToReturn.push(this.typologyResponse);
|
|
58
|
-
}
|
|
59
|
-
else if (elem == 'generate_card') {
|
|
60
|
-
this.cardgenResponse = yield this.generateCard((_b = args.prompts.card_gen_prompt) !== null && _b !== void 0 ? _b : '', this.parsedContent + JSON.stringify(this.typologyResponse));
|
|
61
|
-
responseToReturn.push(this.cardgenResponse);
|
|
62
|
-
}
|
|
63
|
-
return responseToReturn;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
_returnParsedContent() {
|
|
67
|
-
return this.parsedContent;
|
|
68
|
-
}
|
|
69
|
-
generateCard(prompt, content) {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
var _a;
|
|
72
|
-
let response = yield ((_a = this.openAiService) === null || _a === void 0 ? void 0 : _a.sendRequest(prompt, this.parsedContent));
|
|
73
|
-
response['type'] = 'card_gen';
|
|
74
|
-
return response;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
generateTypology(prompt) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
let response = yield new generate_typology_1.GenerateTypology(this.openAiService, prompt, this.parsedContent).generate();
|
|
80
|
-
return response;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.OnlyEverGenerator = OnlyEverGenerator;
|
|
8
|
+
// import { returnFields, returnHeadings, returnSourceData } from "./constants/source_data";
|
|
9
|
+
const app_1 = require("./bootstrap/app");
|
|
10
|
+
Object.defineProperty(exports, "OnlyEverGenerator", { enumerable: true, get: function () { return app_1.OnlyEverGenerator; } });
|
|
85
11
|
/// All the Codes Below uses express and are strictly for development purpose, while publishing the package, comment everything
|
|
86
12
|
/// below this line
|
|
87
|
-
// let oeGen = new OnlyEverGenerator(config.openAIKey,"gpt-3.5-turbo-1106" ,returnSourceData())
|
|
13
|
+
// let oeGen = new OnlyEverGenerator(config.openAIKey,"gpt-3.5-turbo-1106" ,returnSourceData(),returnFields())
|
|
88
14
|
// app.get('/', async (req, res) => {
|
|
89
15
|
// let data = oeGen._returnParsedContent();
|
|
90
16
|
// // let parsedData = parseResponse()
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseCardResponse = void 0;
|
|
4
|
+
const cardResponse = {
|
|
5
|
+
"status_code": 200,
|
|
6
|
+
"usage_data": {
|
|
7
|
+
"prompt_tokens": 9781,
|
|
8
|
+
"completion_tokens": 1915,
|
|
9
|
+
"total_tokens": 11696
|
|
10
|
+
},
|
|
11
|
+
"generated_content": {
|
|
12
|
+
"missing_concepts": [
|
|
13
|
+
"Faraday's laws of electrolysis",
|
|
14
|
+
"Humphry Davy",
|
|
15
|
+
"Electrolytic cell",
|
|
16
|
+
"Decomposition potential",
|
|
17
|
+
"Oxidation",
|
|
18
|
+
"Reduction",
|
|
19
|
+
"Electrolysis of seawater",
|
|
20
|
+
"Electrometallurgy",
|
|
21
|
+
"Electroplating",
|
|
22
|
+
"Electrochemical machining",
|
|
23
|
+
"Electrochemistry",
|
|
24
|
+
"Electrocatalysis",
|
|
25
|
+
"Electrorefining",
|
|
26
|
+
"Electrolysis of carbon dioxide",
|
|
27
|
+
"Energy changes during electrolysis",
|
|
28
|
+
"Electrocrystallization",
|
|
29
|
+
"Electrolysis of Iron Ore"
|
|
30
|
+
],
|
|
31
|
+
"missing_facts": [
|
|
32
|
+
"Michael Faraday introduced the term 'electrolysis' in 1834",
|
|
33
|
+
"The first demonstration of key electrolysis concepts was by William Nicholson and Anthony Carlisle in the early nineteenth century",
|
|
34
|
+
"Humphry Davy discovered several alkali and alkaline earth metals by electrolysis",
|
|
35
|
+
"Electrolysis played a key role in isolating and identifying new elements like lithium, chlorine, and fluorine",
|
|
36
|
+
"The Hall–Héroult process led to a significant drop in the price of aluminum",
|
|
37
|
+
"Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water",
|
|
38
|
+
"The electrolysis of seawater can result in the production of alkali hydroxides",
|
|
39
|
+
"Electrometallurgy is used in the production of various metals",
|
|
40
|
+
"Electroplating involves the deposition of a thin metal film onto a substrate material",
|
|
41
|
+
"Electrochemical machining is used for deburring or etching metal surfaces",
|
|
42
|
+
"Electrocatalysis involves the acceleration of electrochemical reactions",
|
|
43
|
+
"Electrorefining is used to obtain pure metals from impure ones",
|
|
44
|
+
"The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
|
|
45
|
+
"Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses",
|
|
46
|
+
"Electrocrystallization is a method for obtaining conductive crystals using electrolysis",
|
|
47
|
+
"Electrolysis of Iron Ore can eventually result in the reduction of emissions from steel production"
|
|
48
|
+
],
|
|
49
|
+
"test_cards": [
|
|
50
|
+
{
|
|
51
|
+
"type": "flash",
|
|
52
|
+
"card_content": {
|
|
53
|
+
"front": "Who introduced the term 'electrolysis' and in which year?",
|
|
54
|
+
"back": "Michael Faraday introduced the term 'electrolysis' in 1834"
|
|
55
|
+
},
|
|
56
|
+
"card_reference": "Electrolysis#Etymology",
|
|
57
|
+
"concepts": [],
|
|
58
|
+
"facts": [
|
|
59
|
+
"Michael Faraday introduced the term 'electrolysis' in 1834"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"type": "flash",
|
|
64
|
+
"card_content": {
|
|
65
|
+
"front": "What was the significance of the Hall–Héroult process?",
|
|
66
|
+
"back": "The Hall–Héroult process led to a significant drop in the price of aluminum"
|
|
67
|
+
},
|
|
68
|
+
"card_reference": "Electrolysis#Industrial uses",
|
|
69
|
+
"concepts": [
|
|
70
|
+
"Hall–Héroult process"
|
|
71
|
+
],
|
|
72
|
+
"facts": [
|
|
73
|
+
"The Hall–Héroult process led to a significant drop in the price of aluminum"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"type": "mcq",
|
|
78
|
+
"card_content": {
|
|
79
|
+
"prompt": "What does the electrolysis of water produce?",
|
|
80
|
+
"choices": [
|
|
81
|
+
{
|
|
82
|
+
"choice": "Oxygen and carbon dioxide",
|
|
83
|
+
"is_correct": false
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"choice": "Hydrogen and oxygen",
|
|
87
|
+
"is_correct": true
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"choice": "Nitrogen and helium",
|
|
91
|
+
"is_correct": false
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"card_reference": "Electrolysis#Process of electrolysis",
|
|
96
|
+
"concepts": [
|
|
97
|
+
"Electrometallurgy"
|
|
98
|
+
],
|
|
99
|
+
"facts": [
|
|
100
|
+
"Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water"
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"type": "cloze",
|
|
105
|
+
"card_content": {
|
|
106
|
+
"prompt": "Electrolysis is the passing of a direct electric current through an {{c0:electrolyte}} producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
107
|
+
"options": [
|
|
108
|
+
{
|
|
109
|
+
"option": "electrolyte",
|
|
110
|
+
"cloze": "c0"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"option": "anode",
|
|
114
|
+
"cloze": "null"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"option": "cathode",
|
|
118
|
+
"cloze": "null"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"card_reference": "Electrolysis#Overview",
|
|
123
|
+
"concepts": [],
|
|
124
|
+
"facts": []
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"type": "match",
|
|
128
|
+
"card_content": {
|
|
129
|
+
"right_choice 1": "Electrometallurgy",
|
|
130
|
+
"right_choice 2": "Electroplating",
|
|
131
|
+
"right_choice 3": "Electrochemical machining",
|
|
132
|
+
"right_choice 4": "Electrochemistry",
|
|
133
|
+
"right_choice 5": "Electrocatalysis",
|
|
134
|
+
"right_choice 6": "Electrorefining",
|
|
135
|
+
"right_choice 7": "Electrolysis of carbon dioxide",
|
|
136
|
+
"right_choice 8": "Energy changes during electrolysis",
|
|
137
|
+
"Electrometallurgy": "The process of producing metals using electricity",
|
|
138
|
+
"Electroplating": "Deposition of thin metal film onto a substrate material",
|
|
139
|
+
"Electrochemical machining": "Deburring or etching metal surfaces",
|
|
140
|
+
"Electrochemistry": "Study of the interchange of chemical and electrical energy",
|
|
141
|
+
"Electrocatalysis": "Acceleration of electrochemical reactions",
|
|
142
|
+
"Electrorefining": "Obtaining pure metals from impure ones"
|
|
143
|
+
},
|
|
144
|
+
"card_reference": "Electrolysis#Industrial uses",
|
|
145
|
+
"concepts": [
|
|
146
|
+
"Electrometallurgy",
|
|
147
|
+
"Electroplating",
|
|
148
|
+
"Electrochemical machining",
|
|
149
|
+
"Electrochemistry",
|
|
150
|
+
"Electrocatalysis",
|
|
151
|
+
"Electrorefining",
|
|
152
|
+
"Electrolysis of carbon dioxide",
|
|
153
|
+
"Energy changes during electrolysis"
|
|
154
|
+
],
|
|
155
|
+
"facts": [
|
|
156
|
+
"Electrometallurgy is used in the production of various metals",
|
|
157
|
+
"Electroplating involves the deposition of a thin metal film onto a substrate material",
|
|
158
|
+
"Electrochemical machining is used for deburring or etching metal surfaces",
|
|
159
|
+
"Electrochemistry is the study of the interchange of chemical and electrical energy",
|
|
160
|
+
"Electrocatalysis involves the acceleration of electrochemical reactions",
|
|
161
|
+
"Electrorefining is used to obtain pure metals from impure ones",
|
|
162
|
+
"The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
|
|
163
|
+
"Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses"
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"type": "mcq",
|
|
168
|
+
"card_content": {
|
|
169
|
+
"prompt": "What is a key application of electrolysis?",
|
|
170
|
+
"choices": [
|
|
171
|
+
{
|
|
172
|
+
"choice": "Production of metal from ore",
|
|
173
|
+
"is_correct": false
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"choice": "Pulsing current results",
|
|
177
|
+
"is_correct": false
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"choice": "Generating electrical potential",
|
|
181
|
+
"is_correct": false
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"choice": "Production of chlorine and sodium hydroxide",
|
|
185
|
+
"is_correct": true
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
},
|
|
189
|
+
"card_reference": "Electrolysis#Industrial uses",
|
|
190
|
+
"concepts": [
|
|
191
|
+
"Electrochemistry",
|
|
192
|
+
"Electrocatalysis",
|
|
193
|
+
"Electrorefining"
|
|
194
|
+
],
|
|
195
|
+
"facts": [
|
|
196
|
+
"Production of chlorine and sodium hydroxide, called the Chloralkali process"
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"type": "cloze",
|
|
201
|
+
"card_content": {
|
|
202
|
+
"prompt": "Oxidation of ions or neutral molecules occurs at the {{c0:anode}}. Reduction of ions or neutral molecules occurs at the {{c1:cathode}}.",
|
|
203
|
+
"options": [
|
|
204
|
+
{
|
|
205
|
+
"option": "anode",
|
|
206
|
+
"cloze": "c0"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"option": "cathode",
|
|
210
|
+
"cloze": "c1"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"option": "electrolyte",
|
|
214
|
+
"cloze": "null"
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"card_reference": "Electrolysis#Oxidation and reduction at the electrodes",
|
|
219
|
+
"concepts": [
|
|
220
|
+
"Oxidation",
|
|
221
|
+
"Reduction"
|
|
222
|
+
],
|
|
223
|
+
"facts": []
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"type": "match",
|
|
227
|
+
"card_content": {
|
|
228
|
+
"right_choice 1": "Electrolysis",
|
|
229
|
+
"right_choice 2": "Electrocrystallization",
|
|
230
|
+
"right_choice 3": "Electrolysis of Iron Ore",
|
|
231
|
+
"right_choice 4": "Electrolysis of seawater",
|
|
232
|
+
"right_choice 5": "Electrometallurgy"
|
|
233
|
+
},
|
|
234
|
+
"card_reference": "Electrolysis#Research trends",
|
|
235
|
+
"concepts": [
|
|
236
|
+
"Electrolysis",
|
|
237
|
+
"Electrocrystallization",
|
|
238
|
+
"Electrolysis of Iron Ore",
|
|
239
|
+
"Electrolysis of seawater",
|
|
240
|
+
"Electrometallurgy"
|
|
241
|
+
],
|
|
242
|
+
"facts": []
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
},
|
|
246
|
+
"generated_at": 1718625081,
|
|
247
|
+
"type": "card_gen"
|
|
248
|
+
};
|
|
249
|
+
class ParseCardResponse {
|
|
250
|
+
constructor(generatedData) {
|
|
251
|
+
this.generatedData = generatedData;
|
|
252
|
+
}
|
|
253
|
+
parse() {
|
|
254
|
+
const cardData = [];
|
|
255
|
+
const usage_data = this.generatedData.usage_data;
|
|
256
|
+
const created_at = this.generatedData.created_at;
|
|
257
|
+
const unparsedTestCards = this.generatedData.test_cards;
|
|
258
|
+
for (let elem of unparsedTestCards) {
|
|
259
|
+
if (elem.type == 'flash') {
|
|
260
|
+
cardData.push(this.parseFlashCard(elem));
|
|
261
|
+
}
|
|
262
|
+
else if (elem.type == 'mcq') {
|
|
263
|
+
cardData.push(this.parseFlashCard(elem));
|
|
264
|
+
}
|
|
265
|
+
else if (elem.type == 'cloze') {
|
|
266
|
+
cardData.push(this.parseClozeCard(elem));
|
|
267
|
+
}
|
|
268
|
+
else if (elem.type == 'match') {
|
|
269
|
+
cardData.push(this.parseMatchCard(elem));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
usage_data['created_at'] = created_at;
|
|
273
|
+
usage_data['type'] = 'card_gen';
|
|
274
|
+
return {
|
|
275
|
+
'usage_data': usage_data,
|
|
276
|
+
'cards_data': cardData
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
parseFlashCard(data) {
|
|
280
|
+
}
|
|
281
|
+
parseMcqCard(data) {
|
|
282
|
+
}
|
|
283
|
+
parseClozeCard(data) {
|
|
284
|
+
}
|
|
285
|
+
parseMatchCard(data) {
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.ParseCardResponse = ParseCardResponse;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseSourceContent = void 0;
|
|
4
|
+
class ParseSourceContent {
|
|
5
|
+
constructor(sourceContent) {
|
|
6
|
+
this.titles_to_remove = ['See also', 'References', 'Further reading', 'External links', 'Notes and references', 'Bibliography', 'Notes', 'Cited sources'];
|
|
7
|
+
this.content = sourceContent;
|
|
8
|
+
}
|
|
9
|
+
parse() {
|
|
10
|
+
let dataAfterRemovingUnWantedBlocks = this.removeSectionsByTitle(this.content);
|
|
11
|
+
let afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
|
|
12
|
+
return JSON.stringify(afterSanitized);
|
|
13
|
+
}
|
|
14
|
+
removeSectionsByTitle(data) {
|
|
15
|
+
let dataAfterRemoving = [];
|
|
16
|
+
for (let elem of data) {
|
|
17
|
+
if (elem.block_type == 'heading' && this.titles_to_remove.includes(elem.content)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (elem.children) {
|
|
21
|
+
elem.children = this.removeSectionsByTitle(elem.children);
|
|
22
|
+
}
|
|
23
|
+
dataAfterRemoving.push(elem);
|
|
24
|
+
}
|
|
25
|
+
return dataAfterRemoving;
|
|
26
|
+
}
|
|
27
|
+
sanitizeWikiContent(content) {
|
|
28
|
+
// Remove newline characters
|
|
29
|
+
content = content.replace(/\\n/g, ' ');
|
|
30
|
+
// Remove internal link references, keeping only the link text
|
|
31
|
+
// Pattern explanation: [[link|text|index|wiki]] --> text
|
|
32
|
+
content = content.replace(/\[\[.*?\|(.*?)\|.*?\|wiki\]\]/g, '$1');
|
|
33
|
+
// Remove external links, keeping only the link text
|
|
34
|
+
// Pattern explanation: [url text] --> text
|
|
35
|
+
content = content.replace(/\[http[s]?:\/\/[^\s]+ ([^\]]+)\]/g, '$1');
|
|
36
|
+
// Remove Markdown link references, keeping only the link text
|
|
37
|
+
// Pattern explanation:  --> link text
|
|
38
|
+
content = content.replace(/\!\[([^\]]+)\]\([^\)]+\)/g, '$1');
|
|
39
|
+
return content;
|
|
40
|
+
}
|
|
41
|
+
sanitizeBlocks(blocks) {
|
|
42
|
+
let sanitizedBlocks = [];
|
|
43
|
+
blocks.forEach(block => {
|
|
44
|
+
let sanitizedBlock = {};
|
|
45
|
+
for (let key in block) {
|
|
46
|
+
let value = block[key];
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
sanitizedBlock[key] = this.sanitizeWikiContent(value);
|
|
49
|
+
}
|
|
50
|
+
else if (Array.isArray(value)) {
|
|
51
|
+
sanitizedBlock[key] = this.sanitizeBlocks(value);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
sanitizedBlock[key] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
sanitizedBlocks.push(sanitizedBlock);
|
|
58
|
+
});
|
|
59
|
+
return sanitizedBlocks;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ParseSourceContent = ParseSourceContent;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseResponse = exports.returnResponse = void 0;
|
|
4
|
+
const responseData = {
|
|
5
|
+
"flash_cards": [
|
|
6
|
+
{
|
|
7
|
+
"question": "What is the primary function of the 'Electrolysis'?",
|
|
8
|
+
"answer": "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
9
|
+
"heading": "Overview"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"question": "What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
|
|
13
|
+
"answer": "Michael Faraday discovered two laws of electrolysis.",
|
|
14
|
+
"heading": "History"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"question": "What can electrolysis be used for in the manufacturing sector?",
|
|
18
|
+
"answer": "Electrolysis can be used for electroplating and electrochemical machining.",
|
|
19
|
+
"heading": "Manufacturing processes"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"question": "In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
|
|
23
|
+
"answer": "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
|
|
24
|
+
"heading": "Decomposition potential"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"mcqs": [
|
|
28
|
+
{
|
|
29
|
+
"question": "What is the primary purpose of 'Electrometallurgy'?",
|
|
30
|
+
"answers": [
|
|
31
|
+
{
|
|
32
|
+
"answer": "Production of aluminium",
|
|
33
|
+
"is_correct": true
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"answer": "Chlorine production",
|
|
37
|
+
"is_correct": false
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"answer": "Purifying copper",
|
|
41
|
+
"is_correct": false
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"answer": "Rust removal",
|
|
45
|
+
"is_correct": false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"answer": "Hydrogen production",
|
|
49
|
+
"is_correct": false
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"heading": "Industrial uses"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"question": "What can electrolysis be used for in the context of batteries?",
|
|
56
|
+
"answers": [
|
|
57
|
+
{
|
|
58
|
+
"answer": "Spontaneous redox reactions",
|
|
59
|
+
"is_correct": true
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"answer": "Energy-releasing reactions",
|
|
63
|
+
"is_correct": false
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"answer": "Disinfectant production",
|
|
67
|
+
"is_correct": false
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"answer": "Fuel production",
|
|
71
|
+
"is_correct": false
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"answer": "Gas diffusion in reactors",
|
|
75
|
+
"is_correct": false
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"heading": "Related processes"
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"cloze_cards": [
|
|
82
|
+
{
|
|
83
|
+
"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.",
|
|
84
|
+
"options": [
|
|
85
|
+
{
|
|
86
|
+
"option": "direct electric current",
|
|
87
|
+
"cloze": "c0"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"option": "electrolyte",
|
|
91
|
+
"cloze": "c1"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"option": "chemical reactions",
|
|
95
|
+
"cloze": "c2"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"option": "electrodes",
|
|
99
|
+
"cloze": "c3"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"option": "decomposition",
|
|
103
|
+
"cloze": "c4"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"option": "metallic objects",
|
|
107
|
+
"cloze": null
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"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.",
|
|
113
|
+
"options": [
|
|
114
|
+
{
|
|
115
|
+
"option": "anode",
|
|
116
|
+
"cloze": "c0"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"option": "cathode",
|
|
120
|
+
"cloze": "c1"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"option": "electrolyte",
|
|
124
|
+
"cloze": null
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"option": "chemical reactions",
|
|
128
|
+
"cloze": null
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"option": "oxygen",
|
|
132
|
+
"cloze": null
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"option": "hydrogen",
|
|
136
|
+
"cloze": null
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
};
|
|
142
|
+
function returnResponse() {
|
|
143
|
+
return responseData;
|
|
144
|
+
}
|
|
145
|
+
exports.returnResponse = returnResponse;
|
|
146
|
+
function parseResponse() {
|
|
147
|
+
let cardData = [];
|
|
148
|
+
let data = returnResponse();
|
|
149
|
+
let keys = Object.keys(data);
|
|
150
|
+
if (keys) {
|
|
151
|
+
for (let elem of keys) {
|
|
152
|
+
if (elem == 'flash_cards') {
|
|
153
|
+
cardData.push(...parseFlashCard(data.flash_cards));
|
|
154
|
+
}
|
|
155
|
+
else if (elem == 'cloze_cards') {
|
|
156
|
+
cardData.push(...parseClozeCards(data.cloze_cards));
|
|
157
|
+
}
|
|
158
|
+
else if (elem == 'mcqs') {
|
|
159
|
+
cardData.push(...parseMcq(data.mcqs));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return cardData;
|
|
164
|
+
}
|
|
165
|
+
exports.parseResponse = parseResponse;
|
|
166
|
+
/// takes array of
|
|
167
|
+
function parseFlashCard(cards) {
|
|
168
|
+
let flashCardData = [];
|
|
169
|
+
for (let elem of cards) {
|
|
170
|
+
flashCardData.push({
|
|
171
|
+
"type": "flash",
|
|
172
|
+
"heading": elem.heading,
|
|
173
|
+
"content": JSON.stringify({
|
|
174
|
+
"front_content": elem.question,
|
|
175
|
+
"back_content": elem.answer
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return flashCardData;
|
|
180
|
+
}
|
|
181
|
+
/// takes array of
|
|
182
|
+
function parseMcq(cardsData) {
|
|
183
|
+
let mcqCards = [];
|
|
184
|
+
for (let elem of cardsData) {
|
|
185
|
+
mcqCards.push({
|
|
186
|
+
"type": "mcq",
|
|
187
|
+
"heading": elem.heading,
|
|
188
|
+
"content": JSON.stringify({
|
|
189
|
+
"question": elem.question,
|
|
190
|
+
"answers": elem.answers
|
|
191
|
+
})
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return mcqCards;
|
|
195
|
+
}
|
|
196
|
+
/// takes array of
|
|
197
|
+
function parseClozeCards(cardsData) {
|
|
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
|
+
}
|