Exemple #1
0
        public static Question GetQuestionUnknown(XmlNode myNode)
        {
            Question q = new Question();

            q.name    = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text"));
            q.text    = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text"));
            q.type    = JwXML.GetNodeAttribute(myNode, "type");
            q.xmlNode = myNode;

            // feedback
            q.generalfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text"));
            q.correctfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text"));
            q.incorrectfeedback        = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text"));
            q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text"));

            XmlNodeList answers = JwXML.GetNodes(myNode, "answer");

            foreach (XmlNode answer in answers)
            {
                string optionText     = JwString.Clean(JwXML.GetNodeValue(answer, "text"));
                string optionFeedback = JwString.Clean(JwXML.GetNodeValue(answer, "feedback"));
                float  optionGrade    = float.Parse(JwXML.GetNodeAttribute(answer, "fraction", "0"));

                q.AddOption(optionText, optionFeedback, optionGrade);
            }

            return(q);
        }
Exemple #2
0
 public static string GetNodeValue(XmlNode parentNode, string nodeName, string defaultValue = "")
 {
     try
     {
         string nodeValue = JwString.Clean(parentNode.SelectSingleNode(nodeName).InnerText);
         return(nodeValue);
     }
     catch
     {
         return(defaultValue);
     }
 }
Exemple #3
0
        public static List <Question> ReadFile(string xmlFile)
        {
            List <Question> qList = new List <Question>();

            XmlDocument doc = JwXML.Load(xmlFile);

            string currentCategory = "";

            XmlNodeList questionNodes = JwXML.GetNodes(doc, "/quiz/question");

            for (int i = 0; i < questionNodes.Count; i++)
            {
                string type = JwXML.GetNodeAttribute(questionNodes[i], "type");

                if (type == "category")
                {
                    currentCategory = JwString.CleanCategory(questionNodes[i].InnerText);
                }
                else if (type == "multichoice" || type == "multichoiceset" || type == "truefalse")
                {
                    Question q = Moodle.GetQuestionMultichoice(questionNodes[i]);
                    q.category = currentCategory;
                    qList.Add(q);
                }
                else if (type == "cloze")
                {
                    Question q = Moodle.GetQuestionCloze(questionNodes[i]);
                    q.category = currentCategory;
                    qList.Add(q);
                }
                else if (type == "ddwtos")
                {
                    Question q = Moodle.GetQuestionDragDropText(questionNodes[i]);
                    q.category = currentCategory;
                    qList.Add(q);
                }
                else if (type == "hotspot")
                {
                    Question q = Moodle.GetQuestionHotspot(questionNodes[i]);
                    q.category = currentCategory;
                    qList.Add(q);
                }
                else
                {
                    // default option - don't know what to do with question
                    Question q = Moodle.GetQuestionUnknown(questionNodes[i]);
                    q.category = currentCategory;
                    qList.Add(q);
                }
            }

            return(qList);
        }
Exemple #4
0
        public static Question GetQuestionCloze(XmlNode myNode)
        {
            string qData = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text"));

            if (qData.Contains("{:MULTICHOICE"))
            {
                return(GetQuestionClozeType2(myNode));
            }
            else
            {
                return(GetQuestionClozeType1(myNode));
            }
        }
Exemple #5
0
        public static Question GetQuestionHotspot(XmlNode myNode)
        {
            Question q = new Question();

            q.name = JwXML.GetNodeValue(myNode, "name/text");
            q.text = JwXML.GetNodeValue(myNode, "questiontext/text");
            q.type = JwXML.GetNodeAttribute(myNode, "type");

            // feedback
            q.generalfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text"));
            q.correctfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text"));
            q.incorrectfeedback        = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text"));
            q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text"));

            // get data
            string data = "{";

            // compile data from XML nodes
            data  += "areashape:" + JwXML.GetNodeValue(myNode, "areashape") + ",";
            data  += "rectangleleft:" + JwXML.GetNodeValue(myNode, "rectangleleft") + ",";
            data  += "rectangletop:" + JwXML.GetNodeValue(myNode, "rectangletop") + ",";
            data  += "rectangleright:" + JwXML.GetNodeValue(myNode, "rectangleright") + ",";
            data  += "rectanglebottom:" + JwXML.GetNodeValue(myNode, "rectanglebottom") + ",";
            data  += "imagewidth:" + JwXML.GetNodeValue(myNode, "imagewidth") + ",";
            data  += "imageheight:" + JwXML.GetNodeValue(myNode, "imageheight") + ",";
            data  += "areacorrect:" + JwXML.GetNodeValue(myNode, "areacorrect");
            data  += "}";
            q.data = data;


            // images?

            XmlNodeList imageNodes = JwXML.GetNodes(myNode, "file"); // "questiontext/file");

            foreach (XmlNode imageNode in imageNodes)
            {
                string imageName = JwXML.GetNodeAttribute(imageNode, "name");
                string imageData = "";
                if (imageNode != null)
                {
                    imageData = imageNode.InnerText;
                }

                if (imageName != String.Empty)
                {
                    q.AddImage(imageName, imageData);
                }
            }

            return(q);
        }
Exemple #6
0
        public static Question GetQuestionMultichoice(XmlNode myNode)
        {
            Question q = new Question();

            q.name                     = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text"));
            q.text                     = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text"));
            q.type                     = JwXML.GetNodeAttribute(myNode, "type");
            q.generalfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text"));
            q.correctfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text"));
            q.incorrectfeedback        = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text"));
            q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text"));

            // images?

            XmlNodeList imageNodes = JwXML.GetNodes(myNode, "questiontext/file");

            foreach (XmlNode imageNode in imageNodes)
            {
                string imageName = JwXML.GetNodeAttribute(imageNode, "name");
                string imageData = "";
                if (imageNode != null)
                {
                    imageData = imageNode.InnerText;
                }

                if (imageName != String.Empty)
                {
                    q.AddImage(imageName, imageData);
                }
            }

            XmlNodeList answers = JwXML.GetNodes(myNode, "answer");

            foreach (XmlNode answer in answers)
            {
                string optionText     = JwString.Clean(JwXML.GetNodeValue(answer, "text"));
                string optionFeedback = JwString.Clean(JwXML.GetNodeValue(answer, "feedback"));
                float  optionGrade    = float.Parse(JwXML.GetNodeAttribute(answer, "fraction", "0"));

                q.AddOption(optionText, optionFeedback, optionGrade);
            }

            return(q);
        }
Exemple #7
0
        public static Question GetQuestionDragDropText(XmlNode myNode)
        {
            Question q = new Question();

            q.name = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text"));
            q.type = JwXML.GetNodeAttribute(myNode, "type");

            string qData = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text"));

            qData = qData.Replace("<![CDATA[", "");
            qData = qData.Replace("]]>", "");

            // get question text
            string pattern = @"[[\d+]]";
            string qText   = Regex.Replace(qData, pattern, " ________ ");

            q.text = qText.Trim();

            q.xmlNode = myNode;

            return(q);
        }
Exemple #8
0
        public static Question GetQuestionClozeType2(XmlNode myNode)
        {
            Question q = new Question();

            q.name = JwString.CleanQuestionName(JwXML.GetNodeValue(myNode, "name/text"));
            q.type = JwXML.GetNodeAttribute(myNode, "type");

            // feedback
            q.generalfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "generalfeedback/text"));
            q.correctfeedback          = JwString.Clean(JwXML.GetNodeValue(myNode, "correctfeedback/text"));
            q.incorrectfeedback        = JwString.Clean(JwXML.GetNodeValue(myNode, "incorrectfeedback/text"));
            q.partiallycorrectfeedback = JwString.Clean(JwXML.GetNodeValue(myNode, "partiallycorrectfeedback/text"));

            string qData = JwString.Clean(JwXML.GetNodeValue(myNode, "questiontext/text"));

            qData = qData.Replace("<![CDATA[", "");
            qData = qData.Replace("]]>", "");

            // get question text
            string pattern = @"{:MULTICHOICE(.*?)}";
            string qText   = Regex.Replace(qData, pattern, " ________ ");

            q.text = qText.Trim();


            // images?

            XmlNodeList imageNodes = JwXML.GetNodes(myNode, "questiontext/file");

            foreach (XmlNode imageNode in imageNodes)
            {
                string imageName = JwXML.GetNodeAttribute(imageNode, "name");
                string imageData = "";
                if (imageNode != null)
                {
                    imageData = imageNode.InnerText;
                }

                if (imageName != String.Empty)
                {
                    q.AddImage(imageName, imageData);
                }
            }


            // get answer options
            MatchCollection blanks = Regex.Matches(qData, pattern);

            if (blanks.Count > 1)
            {
                q.type    = "UNSUPPORTED: " + q.type;
                q.xmlNode = myNode;
            }

            for (int i = 0; i < blanks.Count; i++)
            {
                // get correct options
                string          pattern2 = @"=([^~]+)[~}]";
                MatchCollection matches2 = Regex.Matches(blanks[i].Value, pattern2);

                for (int j = 0; j < matches2.Count; j++)
                {
                    string optionText     = matches2[j].Groups[1].ToString().Trim();
                    string optionFeedback = "";
                    float  optionGrade    = 1.0f;
                    q.AddOption(optionText, optionFeedback, optionGrade);
                }


                // get incorrect options
                string          pattern3 = @"%-?\d*%([^~}]+)";
                MatchCollection matches3 = Regex.Matches(blanks[i].Value, pattern3);

                for (int j = 0; j < matches3.Count; j++)
                {
                    string optionText     = matches3[j].Groups[1].ToString().Trim();
                    string optionFeedback = "";
                    float  optionGrade    = 0.0f;
                    q.AddOption(optionText, optionFeedback, optionGrade);
                }
            }

            return(q);
        }
Exemple #9
0
        public static List <Question> ReadFile(string xmlFile)
        {
            List <Question> qList = new List <Question>();

            XmlDocument doc = JwXML.Load(xmlFile);

            XmlNodeList itemNodes = JwXML.GetNodes(doc, "/questestinterop/item");

            for (int i = 0; i < itemNodes.Count; i++)
            {
                Question q = new Question();

                q.name = JwXML.GetNodeAttribute(itemNodes[i], "ident");

                //XmlNodeList children = itemNodes[i].ChildNodes;

                // get item data
                XmlNode metaData = JwXML.GetSingleNode(itemNodes[i], "itemmetadata");
                q.type     = JwXML.GetNodeValue(metaData, "qmd_itemtype");
                q.category = JwXML.GetNodeValue(metaData, "qmd_topic");

                // get question text
                q.text = JwXML.GetNodeValue(itemNodes[i], "presentation/material/mattext");

                // get options
                XmlNodeList options = JwXML.GetNodes(itemNodes[i], "presentation/response_lid/render_choice/response_label");

                for (int index = 0; index < options.Count; index++)
                {
                    string optionText = JwString.Clean(options[index].InnerText);
                    q.AddOption(optionText, "", 0);
                }


                // find correct answer
                XmlNodeList responses = JwXML.GetNodes(itemNodes[i], "resprocessing/respcondition");

                for (int index = 0; index < responses.Count; index++)
                {
                    string setVar = JwXML.GetNodeValue(responses[index], "setvar", "0");
                    if (index < q.options.Count)
                    {
                        q.options[index].grade = float.Parse(setVar) * 100;
                    }
                }

                // get feedback
                XmlNodeList feedbacks = JwXML.GetNodes(itemNodes[i], "itemfeedback");

                for (int index = 0; index < feedbacks.Count; index++)
                {
                    string feedback = JwXML.GetNodeValue(feedbacks[index], "material/mattext");
                    if (index < q.options.Count)
                    {
                        q.options[index].feedback = feedback;
                    }
                }


                // add question to qList
                qList.Add(q);
            }

            return(qList);
        }
Exemple #10
0
        public static List <Question> ReadFileGerman(string excelFile)
        {
            List <Question> qList = new List <Question>();

            // open excel file
            Excel.Application excel     = new Excel.Application();
            Excel.Workbook    workbook  = excel.Workbooks.Open(excelFile);
            Excel._Worksheet  worksheet = workbook.Sheets[1];

            int rowCount = worksheet.UsedRange.Rows.Count;
            int colCount = worksheet.UsedRange.Columns.Count;

            // find data indexes
            Main main = new Main();

            main.ShowOutput("Finding data indexes....", false);
            int questionTextIndex = 0;
            int nameIndex         = 0;
            int categoryIndex     = 0;
            int answerIndex       = 0;

            int[] optionIndexes = new int[] { 0, 0, 0, 0 };

            for (int col = 1; col <= colCount; col++)
            {
                string v = worksheet.Cells[1, col].Value.ToString();

                if (v == "Fragetext")
                {
                    questionTextIndex = col;
                }
                if (v == "Themenname")
                {
                    categoryIndex = col;
                }
                if (v == "Korrekte Antwort(en)")
                {
                    answerIndex = col;
                }
                if (v == "ID")
                {
                    nameIndex = col;
                }

                for (int i = 1; i <= 4; i++)
                {
                    if (v == "Antwort " + i.ToString())
                    {
                        optionIndexes[i - 1] = col;
                    }
                }
            }

            // check data indexes
            if (questionTextIndex > 0 &&
                optionIndexes[0] > 0 &&
                optionIndexes[1] > 0 &&
                optionIndexes[2] > 0 &&
                optionIndexes[3] > 0 &&
                answerIndex > 0 &&
                categoryIndex > 0 &&
                nameIndex > 0)
            {
                main.ShowOutput("OK");
            }
            else
            {
                main.ShowOutput("Error. Indexes not found.");
                workbook.Close();
                excel.Quit();
                return(qList);
            }

            // get question data
            for (int row = 2; row <= rowCount; row++)
            {
                Question q = new Question();
                q.name     = JwString.Clean(worksheet.Cells[row, nameIndex].Value.ToString());
                q.category = JwString.Clean(worksheet.Cells[row, categoryIndex].Value.ToString());
                q.text     = JwString.Clean(worksheet.Cells[row, questionTextIndex].Value.ToString());
                q.type     = "multichoice";

                int answer = Int32.Parse(worksheet.Cells[row, answerIndex].Value);

                for (int i = 1; i <= 4; i++)
                {
                    Option o = new Option();
                    o.text     = JwString.Clean(worksheet.Cells[row, optionIndexes[i - 1]].Value.ToString());
                    o.feedback = "";
                    o.grade    = 0;
                    if (answer == i)
                    {
                        o.grade = 100;
                    }
                    q.options.Add(o);
                }

                qList.Add(q);
            }

            // close excel and return questions
            workbook.Close();
            excel.Quit();

            return(qList);
        }
Exemple #11
0
        public static List <Question> ReadFile(string excelFile)
        {
            int headersRow = 2;

            List <Question> qList = new List <Question>();

            // open excel file
            Excel.Application excel     = new Excel.Application();
            Excel.Workbook    workbook  = excel.Workbooks.Open(excelFile);
            Excel._Worksheet  worksheet = workbook.Sheets[1];

            int rowCount = worksheet.UsedRange.Rows.Count;
            int colCount = worksheet.UsedRange.Columns.Count;

            // find data indexes
            //main.ShowOutput("Finding data indexes....", false);
            int questionTextIndex = 0;
            int nameIndex         = 0;
            int categoryIndex     = 0;
            int answerIndex       = 0;
            int imageIndex        = 0;

            int[] optionIndexes = new int[] { 0, 0, 0, 0 };

            for (int col = 1; col <= colCount; col++)
            {
                string v = worksheet.Cells[headersRow, col].Value.ToString();

                if (v == "Question Stem")
                {
                    questionTextIndex = col;
                }
                if (v == "Syllabus")
                {
                    categoryIndex = col;
                }
                if (v == "Correct Answer")
                {
                    answerIndex = col;
                }
                if (v == "Question ID")
                {
                    nameIndex = col;
                }
                if (v == "Annex")
                {
                    imageIndex = col;
                }

                string[] answerFields = new string[] { "A", "B", "C", "D" };

                for (int i = 0; i < 4; i++)
                {
                    if (v == answerFields[i])
                    {
                        optionIndexes[i] = col;
                    }
                }
            }

            // check data indexes
            if (questionTextIndex > 0 &&
                optionIndexes[0] > 0 &&
                optionIndexes[1] > 0 &&
                optionIndexes[2] > 0 &&
                optionIndexes[3] > 0 &&
                answerIndex > 0 &&
                imageIndex > 0 &&
                categoryIndex > 0 &&
                nameIndex > 0)
            {
                //main.ShowOutput("OK");
            }
            else
            {
                Main.myThis.ShowOutput("INDEX ERROR!!");
                if (questionTextIndex == 0)
                {
                    Main.myThis.ShowOutput("questionTextIndex not found. Should be\"Question Stem\"");
                }
                if (optionIndexes[0] == 0)
                {
                    Main.myThis.ShowOutput("optionIndexes(A) not found. Should be\"A\"");
                }
                if (optionIndexes[0] == 0)
                {
                    Main.myThis.ShowOutput("optionIndexes(B) not found. Should be\"B\"");
                }
                if (optionIndexes[0] == 0)
                {
                    Main.myThis.ShowOutput("optionIndexes(C) not found. Should be\"C\"");
                }
                if (optionIndexes[0] == 0)
                {
                    Main.myThis.ShowOutput("optionIndexes(D) not found. Should be\"D\"");
                }
                if (answerIndex == 0)
                {
                    Main.myThis.ShowOutput("answerIndex not found. Should be\"Correct Answer\"");
                }
                if (imageIndex == 0)
                {
                    Main.myThis.ShowOutput("imageIndex not found. Should be\"Annex\"");
                }
                if (categoryIndex == 0)
                {
                    Main.myThis.ShowOutput("categoryIndex not found. Should be\"Syllabus\"");
                }
                if (nameIndex == 0)
                {
                    Main.myThis.ShowOutput("nameIndex not found. Should be\"Question ID\"");
                }

                workbook.Close();
                excel.Quit();
                return(qList);
            }

            // get question data
            for (int row = (headersRow + 1); row <= rowCount; row++)
            {
                Question q = new Question();
                q.name     = JwString.Clean(worksheet.Cells[row, nameIndex].Value.ToString());
                q.category = CleanCategory(JwString.Clean(worksheet.Cells[row, categoryIndex].Value.ToString()));
                q.text     = JwString.Clean(worksheet.Cells[row, questionTextIndex].Value.ToString());

                if (worksheet.Cells[row, imageIndex].Value != null)
                {
                    string imageName = CleanImage(JwString.Clean(worksheet.Cells[row, imageIndex].Value.ToString()));
                    q.AddImage(imageName, "");
                }

                q.type = "multichoice";

                string   answer       = worksheet.Cells[row, answerIndex].Value.Trim();
                string[] answerValues = new string[] { "A", "B", "C", "D" };

                for (int i = 1; i <= 4; i++)
                {
                    Option o = new Option();
                    o.text     = JwString.Clean(worksheet.Cells[row, optionIndexes[i - 1]].Value.ToString());
                    o.feedback = "";
                    o.grade    = 0;
                    if (answer == answerValues[i - 1])
                    {
                        o.grade = 100;
                    }
                    q.options.Add(o);
                }

                qList.Add(q);
            }

            // close excel and return questions
            workbook.Close();
            excel.Quit();

            return(qList);
        }