only_ever_generator 0.5.3 → 0.5.5

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/src/index.ts CHANGED
@@ -20,7 +20,7 @@ import { OnlyEverGenerator } from "./bootstrap/app";
20
20
 
21
21
  /// While Publishing the package , and using this code as a separate npm module
22
22
  /// uncomment the below line and comment all the others, expect the import of OnlyEverGenerator
23
- export {OnlyEverGenerator};
23
+ export {OnlyEverGenerator};
24
24
 
25
25
  // . All the Codes Below uses express and are strictly for development purpose, while publishing the package, comment everything
26
26
  // below this line
@@ -57,7 +57,7 @@ import { OnlyEverGenerator } from "./bootstrap/app";
57
57
  // "res_tokens": cardResp.usage_data?.completion_tokens,
58
58
  // "model": '40-mini'
59
59
  // };
60
- // let parsedData = new ParseCardResponse().parse(cardResp,false);
60
+ // let parsedData = new ParseCardResponse().parse(cardResp,false, {});
61
61
  // res.send(parsedData)
62
62
  // });
63
63
 
@@ -21,7 +21,7 @@ export class ParseClozeCard {
21
21
  category: "learning",
22
22
  sub_type: data.type,
23
23
  },
24
- heading: data.card_reference,
24
+ heading:"",
25
25
  displayTitle: displayTitle,
26
26
  content: {
27
27
  question: finalQuestion,
@@ -29,7 +29,7 @@ export class ParseClozeCard {
29
29
  },
30
30
  concepts: data.concepts,
31
31
  facts: data.facts,
32
- bloomLevel: data.bloom_level,
32
+ explanation: data.card_content.explanation,
33
33
  };
34
34
 
35
35
  return this._validateCloze(clozeCardData);
@@ -22,13 +22,13 @@ export class ParseMatchCard {
22
22
  category: "learning",
23
23
  sub_type: cardData.type,
24
24
  },
25
- heading: cardData.card_content.card_reference,
25
+ heading:"",
26
26
  content: finalContent,
27
27
  // content: cardData.card_content,
28
28
  displayTitle: displayTitle,
29
29
  concepts: cardData.concepts,
30
30
  facts: cardData.facts,
31
- bloomLevel: cardData.bloom_level,
31
+ explanation: cardData.card_content.explanation,
32
32
  };
33
33
 
34
34
  return this._validateMatch(matchCard);
@@ -24,7 +24,7 @@ export class ParseMcqCard {
24
24
  category: "learning",
25
25
  sub_type: data.type,
26
26
  },
27
- heading: data.card_reference,
27
+ heading: "",
28
28
  displayTitle: displayTitle,
29
29
  content: {
30
30
  question: data.card_content.prompt,
@@ -32,7 +32,7 @@ export class ParseMcqCard {
32
32
  },
33
33
  concepts: data.concepts,
34
34
  facts: data.facts,
35
- bloomLevel: data.bloom_level,
35
+ explanation: data.card_content.explanation,
36
36
  };
37
37
  // return mcqCard;
38
38
  const isValid = this._validate(mcqCard);
@@ -4,7 +4,7 @@ import { ParseMatchCard } from "./parse_card/parse_match_card";
4
4
  import { ParseMcqCard } from "./parse_card/parse_mcq_card";
5
5
 
6
6
  export class ParseCardResponse {
7
- parse(generatedData: any, isGapFill: boolean) {
7
+ parse(generatedData: any, isGapFill: boolean, sourceTaxonomy: any) {
8
8
  let usage_data = generatedData.metadata;
9
9
  try {
10
10
  const cardData = [];
@@ -15,21 +15,25 @@ export class ParseCardResponse {
15
15
  if (elem.type == "flash") {
16
16
  const flashCard = this.parseFlashCard(elem);
17
17
  if (flashCard != null && flashCard) {
18
+ flashCard.heading = this._getCardReference(flashCard, sourceTaxonomy);
18
19
  cardData.push(flashCard);
19
20
  }
20
21
  } else if (elem.type == "mcq") {
21
22
  const mcqCard = new ParseMcqCard().parse(elem);
22
23
  if (mcqCard != null && mcqCard) {
24
+ mcqCard.heading = this._getCardReference(mcqCard, sourceTaxonomy);
23
25
  cardData.push(mcqCard);
24
26
  }
25
27
  } else if (elem.type == "cloze") {
26
28
  const clozeCard = new ParseClozeCard().parse(elem);
27
29
  if (clozeCard && clozeCard != null) {
30
+ clozeCard.heading = this._getCardReference(clozeCard, sourceTaxonomy);
28
31
  cardData.push(clozeCard);
29
32
  }
30
33
  } else if (elem.type == "match") {
31
34
  const matchCard = new ParseMatchCard().parse(elem);
32
35
  if (matchCard && matchCard != null) {
36
+ matchCard.heading = this._getCardReference(matchCard, sourceTaxonomy);
33
37
  cardData.push(matchCard);
34
38
  }
35
39
  }
@@ -77,15 +81,15 @@ export class ParseCardResponse {
77
81
  category: "learning",
78
82
  sub_type: data.type,
79
83
  },
80
- heading: data.card_reference,
84
+ heading : "",
81
85
  displayTitle: displayTitle,
82
86
  content: {
83
87
  front_content: data.card_content.front,
84
88
  back_content: data.card_content.back,
85
89
  },
86
90
  concepts: data.concepts,
91
+ explanation: data.card_content.explanation,
87
92
  facts: data.facts,
88
- bloomLevel: data.bloom_level,
89
93
  };
90
94
 
91
95
  return flashCardData;
@@ -97,4 +101,36 @@ export class ParseCardResponse {
97
101
  generateFlashCardDisplayTitle(front: string, back: string) {
98
102
  return `${front} ---- ${back}`;
99
103
  }
104
+
105
+ _getCardReference(generatedCardData: any, sourceTaxonomy: any) {
106
+ const cardConcepts = generatedCardData.concepts ?? [];
107
+ const cardFacts = generatedCardData.facts ?? [];
108
+ const combinedCardFactsAndConcepts = [...cardConcepts, ...cardFacts];
109
+
110
+ const sourceConcepts = sourceTaxonomy.concepts ?? [];
111
+ const sourceFacts = sourceTaxonomy.facts ?? [];
112
+
113
+ const mappedSourceConcepts = sourceConcepts.map((elem: any) => {
114
+ return {
115
+ "text": elem.concept_text,
116
+ reference: elem.reference,
117
+ };
118
+ });
119
+ const mappedSourceFacts = sourceFacts.map((elem: any) => {
120
+ return {
121
+ "text": elem.fact_text,
122
+ reference: elem.reference,
123
+ };
124
+ });
125
+
126
+ const compinedConceptsAndFacts = [...mappedSourceConcepts, ...mappedSourceFacts];
127
+ const firstMatchedConcept = compinedConceptsAndFacts.find((elem: any) => combinedCardFactsAndConcepts.includes(elem.text));
128
+
129
+
130
+ if(firstMatchedConcept){
131
+ return firstMatchedConcept.reference;
132
+ }else{
133
+ return "";
134
+ }
135
+ }
100
136
  }