Added QA to Gift parser and cleaned up code
This commit is contained in:
Родитель
b193269a5c
Коммит
5309b7f23b
|
@ -1,7 +1,8 @@
|
|||
import { parse, GIFTQuestion, TextChoice, TextFormat } from "gift-pegjs";
|
||||
import { parse, GIFTQuestion, TextChoice, TextFormat, NumericalChoice, NumericalFormat } from "gift-pegjs";
|
||||
import { ParsedQuestionBank } from "./ParsedQuestionBank";
|
||||
import { AssessmentAppParser } from "./Parser";
|
||||
import { Question } from "../Question";
|
||||
import { questionTypeSpecificParse } from "./ParserHelper";
|
||||
|
||||
// Currently only parses in MCQs and TFs
|
||||
export class GiftParser extends AssessmentAppParser{
|
||||
|
@ -17,63 +18,50 @@ export class GiftParser extends AssessmentAppParser{
|
|||
if (q.type === "Category"){
|
||||
questionBankTitle = q.title;
|
||||
}
|
||||
|
||||
if (q.type === "MC"){ // multiple choice
|
||||
|
||||
var choices:TextChoice[] = q.choices;
|
||||
var answerTexts = Array();
|
||||
var correctAnswer = [];
|
||||
for (var choice in choices){
|
||||
var details:TextChoice = choices[choice];
|
||||
answerTexts.push(this.removeTags(details.text['text']));
|
||||
var weight = details.weight
|
||||
if (weight != null && weight > 0){
|
||||
correctAnswer.push(choice); // plus operator converts to number
|
||||
}
|
||||
}
|
||||
else{
|
||||
var stem:TextFormat = q.stem;
|
||||
var answerTexts:string[] = [];
|
||||
var correctAnswers:string[] = []
|
||||
var questionType:string = '';
|
||||
var results:questionTypeSpecificParse = {options:[], correctAnswer:[]}
|
||||
|
||||
if (q.type === "MC"){
|
||||
questionType = "MCQ";
|
||||
results = this.getMCQ(q);
|
||||
|
||||
}
|
||||
else if(q.type === "TF"){
|
||||
questionType = "MCQ";
|
||||
results = this.getTF(q);
|
||||
|
||||
}
|
||||
else if (q.type === "Short"){
|
||||
questionType = "QA";
|
||||
results = this.getShort(q);
|
||||
}
|
||||
else if (q.type === "Numerical"){
|
||||
questionType = "QA";
|
||||
results = this.getNumerical(q);
|
||||
}
|
||||
else{
|
||||
continue;
|
||||
}
|
||||
correctAnswers = results.correctAnswer;
|
||||
answerTexts = results.options;
|
||||
|
||||
const question: Question = {
|
||||
id: "",
|
||||
name: this.removeTags(stem.text),
|
||||
description: this.removeTags(stem.text),
|
||||
lastModified: new Date (),
|
||||
options: answerTexts,
|
||||
answer: correctAnswer,
|
||||
answer: correctAnswers,
|
||||
textType:stem.format,
|
||||
questionType: "MCQ",
|
||||
questionType: questionType,
|
||||
}
|
||||
questions.push(question);
|
||||
|
||||
}
|
||||
|
||||
if (q.type === "TF"){
|
||||
var stem:TextFormat = q.stem;
|
||||
var ans:Boolean = q.isTrue;
|
||||
const question: Question = {
|
||||
id: "",
|
||||
name: this.removeTags(stem.text),
|
||||
description: stem.text,
|
||||
lastModified: new Date (),
|
||||
options: ["True", "False"],
|
||||
answer: ans? ['0']:['1'],
|
||||
textType:stem.format,
|
||||
questionType: "TF",
|
||||
}
|
||||
questions.push(question);
|
||||
}
|
||||
if (q.type === "Description"|| q.type === "Essay" || q.type === "Short"){
|
||||
var stem:TextFormat = q.stem;
|
||||
const question: Question = {
|
||||
id: "",
|
||||
name: this.removeTags(stem.text),
|
||||
description: stem.text,
|
||||
lastModified: new Date (),
|
||||
options: ["", ""],
|
||||
answer: ["This is an example"], // Gift format does not give "ideal" anwer for these types
|
||||
textType:stem.format,
|
||||
questionType:"QA",
|
||||
}
|
||||
questions.push(question);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +73,68 @@ export class GiftParser extends AssessmentAppParser{
|
|||
this.questionbanks.push(qb);
|
||||
}
|
||||
|
||||
|
||||
public getMCQ(q:GIFTQuestion){
|
||||
var answerTexts:string[] = Array();
|
||||
var correctAnswer:string[] = [];
|
||||
if (q.type === "MC"){
|
||||
var choices:TextChoice[] = q.choices;
|
||||
for (var choice in choices){
|
||||
var details:TextChoice = choices[choice];
|
||||
answerTexts.push(this.removeTags(details.text['text']));
|
||||
var weight = details.weight
|
||||
if ((weight != null && weight > 0) || details.isCorrect == true){
|
||||
correctAnswer.push(choice.toString()); // plus operator converts to number
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return {options:answerTexts, correctAnswer:correctAnswer}
|
||||
}
|
||||
|
||||
public getTF(q:GIFTQuestion){
|
||||
var ans:Boolean = false;
|
||||
if (q.type === "TF"){
|
||||
ans = q.isTrue;
|
||||
}
|
||||
return {options:["True", "False"], correctAnswer:ans? ['0']:['1'] }
|
||||
}
|
||||
|
||||
public getShort(q:GIFTQuestion){
|
||||
var answerTexts:string[] = Array();
|
||||
var correctAnswer:string[] = [];
|
||||
if (q.type === "Short"){
|
||||
var choices: TextChoice[] = q.choices;
|
||||
for (var choice in choices){
|
||||
var details:TextChoice = choices[choice];
|
||||
var weight = details.weight
|
||||
if (weight != null && weight > 0){
|
||||
correctAnswer.push(details.text.text); // plus operator converts to number
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return {options:answerTexts, correctAnswer:correctAnswer}
|
||||
|
||||
}
|
||||
|
||||
public getNumerical(q:GIFTQuestion){
|
||||
|
||||
var correctAnswer = [];
|
||||
if (q.type === "Numerical"){
|
||||
var numChoices:any = q.choices;
|
||||
for (var c in numChoices){
|
||||
var choiceDetails:NumericalChoice = numChoices[c]
|
||||
var weight = choiceDetails.weight
|
||||
if (weight != null && weight > 0){
|
||||
if (choiceDetails.text.number){
|
||||
correctAnswer.push(choiceDetails.text.number.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return {options:[], correctAnswer:correctAnswer}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,10 @@ import { XMLParser} from "fast-xml-parser";
|
|||
import { ParsedQuestionBank } from "./ParsedQuestionBank";
|
||||
import { AssessmentAppParser } from "./Parser";
|
||||
import { Question } from "../Question";
|
||||
import { questionTypeSpecificParse } from "./ParserHelper";
|
||||
|
||||
|
||||
|
||||
interface questionTypeSpecificParse {
|
||||
correctAnswer:string[]
|
||||
options:string[]
|
||||
};
|
||||
export class QTIParser extends AssessmentAppParser{
|
||||
options = {
|
||||
ignoreAttributes:false
|
||||
|
|
Загрузка…
Ссылка в новой задаче