Exemplo n.º 1
0
        public void LoadRandomProblem()
        {
            while (true)
            {
                int index = GenerateRandomProblemIndex();

                if (Problems[index - 1] != null)
                {
                    CurrentProblemIndex = index - 1;
                    CurrentProblem      = Problems[index - 1];
                    return;
                }
            }
        }
Exemplo n.º 2
0
        static void LoadProblemFile()
        {
            var currentAssembly = Assembly.GetExecutingAssembly();
            var resourceName    = "Loader.Problems.json";

            using (Stream stream = currentAssembly.GetManifestResourceStream(resourceName))
                using (var file = new StreamReader(stream))
                    using (var reader = new JsonTextReader(file))
                    {
                        var jProblems = (JArray)JToken.ReadFrom(reader);

                        foreach (var jToken in jProblems)
                        {
                            var jo = (JObject)jToken;
                            if (jo == null)
                            {
                                continue;
                            }

                            var problemIndex       = jo["id"].Value <int>();
                            var problemDescription = jo["problem"].Value <string>();
                            var problemtype        = jo["type"].Value <string>();
                            var pt = (MathProblem.ProblemType)Enum.Parse(typeof(MathProblem.ProblemType), problemtype);
                            var mp = new MathProblem(problemIndex, problemDescription, pt);

                            #region Syntax Loading
                            //Problem Tagging Information
                            var tagArray = jo["syntaxTagging"].Value <JArray>();
                            if (tagArray == null)
                            {
                                continue;
                            }

                            foreach (var tagToken in tagArray)
                            {
                                var tagO = (JObject)tagToken;
                                if (tagO == null)
                                {
                                    continue;
                                }

                                var tagIndex        = tagO["id"].Value <int>();
                                var tagStr          = tagO["tag"].Value <string>();
                                var tagInteractType = tagO["interaction"].Value <string>();
                                var it =
                                    (ProblemWord.InteractionType)
                                    Enum.Parse(typeof(ProblemWord.InteractionType), tagInteractType);

                                var pw = new ProblemWord(tagIndex, tagStr, it);

                                if (it == ProblemWord.InteractionType.Input)
                                {
                                    pw.DragObject = pw.Word;
                                    if (tagO["input"] != null) // kr of input knowledge
                                    {
                                        var inputFormat = tagO["input"].Value <string>();
                                        if (inputFormat != null)
                                        {
                                            pw.DragObject = inputFormat;
                                        }
                                    }

                                    //pw.PQType = ProblemWord.ProblemQuestionType.Problem;
                                    //TODO
                                }
                                else if (it == ProblemWord.InteractionType.Concept)
                                {
                                    var conceptFormat = tagO["concept"].Value <string>();
                                    if (conceptFormat != null)
                                    {
                                        object explain = GeometryConcept.
                                                         ConceptCrawler.Instance.RetrieveConceptExplain(conceptFormat);
                                        string concept = "Concept: " + conceptFormat;
                                        if (explain != null)
                                        {
                                            pw.DragObject = new Tuple <string, string>(concept, (string)explain);
                                        }
                                        else
                                        {
                                            pw.DragObject = new Tuple <string, string>(conceptFormat, "TODO");
                                        }
                                    }
                                }
                                else if (it == ProblemWord.InteractionType.Hybrid)
                                {
                                    var    conceptFormat = tagO["concept"].Value <string>();
                                    object conceptTuple1 = null;
                                    if (conceptFormat != null)
                                    {
                                        object explain = GeometryConcept.
                                                         ConceptCrawler.Instance.RetrieveConceptExplain(conceptFormat);
                                        string concept = "Concept: " + conceptFormat;
                                        if (explain != null)
                                        {
                                            conceptTuple1 = new Tuple <string, string>(concept, (string)explain);
                                        }
                                        else
                                        {
                                            conceptTuple1 = new Tuple <string, string>(conceptFormat, "TODO");
                                        }
                                    }

                                    object inputTuple2 = null;
                                    inputTuple2 = pw.Word;
                                    if (tagO["input"] != null) // kr of input knowledge
                                    {
                                        var inputFormat = tagO["input"].Value <string>();
                                        if (inputFormat != null)
                                        {
                                            inputTuple2 = inputFormat;
                                        }
                                    }
                                    pw.DragObject = new Tuple <object, object>(conceptTuple1, inputTuple2);
                                }
                                mp.Words.Add(pw);
                            }
                            #endregion

                            Problems.Insert(mp.Index - 1, mp);
                        }
                    }
        }
Exemplo n.º 3
0
 private void Load(int index)
 {
     CurrentProblemIndex = index - 1;
     CurrentProblem      = Problems[CurrentProblemIndex];
 }
Exemplo n.º 4
0
        static void LoadProblemFile()
        {
            var currentAssembly = Assembly.GetExecutingAssembly();
            var resourceName = "Loader.Problems.json";
            using (Stream stream = currentAssembly.GetManifestResourceStream(resourceName))
            using (var file = new StreamReader(stream))
            using (var reader = new JsonTextReader(file))
            {
                var jProblems = (JArray)JToken.ReadFrom(reader);

                foreach (var jToken in jProblems)
                {
                    var jo = (JObject)jToken;
                    if (jo == null) continue;

                    var problemIndex = jo["id"].Value<int>();
                    var problemDescription = jo["problem"].Value<string>();
                    var problemtype = jo["type"].Value<string>();
                    var pt = (MathProblem.ProblemType)Enum.Parse(typeof(MathProblem.ProblemType), problemtype);
                    var mp = new MathProblem(problemIndex, problemDescription, pt);

                    #region Syntax Loading
                    //Problem Tagging Information
                    var tagArray = jo["syntaxTagging"].Value<JArray>();
                    if (tagArray == null) continue;

                    foreach (var tagToken in tagArray)
                    {
                        var tagO = (JObject)tagToken;
                        if (tagO == null) continue;

                        var tagIndex = tagO["id"].Value<int>();
                        var tagStr = tagO["tag"].Value<string>();
                        var tagInteractType = tagO["interaction"].Value<string>();
                        var it =
                            (ProblemWord.InteractionType)
                                Enum.Parse(typeof(ProblemWord.InteractionType), tagInteractType);

                        var pw = new ProblemWord(tagIndex, tagStr, it);

                        if (it == ProblemWord.InteractionType.Input)
                        {
                            pw.DragObject = pw.Word;
                            if (tagO["input"] != null) // kr of input knowledge
                            {
                                var inputFormat = tagO["input"].Value<string>();
                                if (inputFormat != null)
                                {
                                    pw.DragObject = inputFormat;
                                }
                            }

                            //pw.PQType = ProblemWord.ProblemQuestionType.Problem;
                            //TODO
                        }
                        else if (it == ProblemWord.InteractionType.Concept)
                        {
                            var conceptFormat = tagO["concept"].Value<string>();
                            if (conceptFormat != null)
                            {
                                object explain = GeometryConcept.
                                    ConceptCrawler.Instance.RetrieveConceptExplain(conceptFormat);
                                string concept = "Concept: " + conceptFormat;
                                if (explain != null)
                                {
                                    pw.DragObject = new Tuple<string, string>(concept, (string)explain);
                                }
                                else
                                {
                                    pw.DragObject = new Tuple<string, string>(conceptFormat, "TODO");
                                }
                            }
                        }
                        else if (it == ProblemWord.InteractionType.Hybrid)
                        {
                            var conceptFormat = tagO["concept"].Value<string>();
                            object conceptTuple1 = null;
                            if (conceptFormat != null)
                            {
                                object explain = GeometryConcept.
                                   ConceptCrawler.Instance.RetrieveConceptExplain(conceptFormat);
                                string concept = "Concept: " + conceptFormat;
                                if (explain != null)
                                {
                                    conceptTuple1 = new Tuple<string, string>(concept, (string)explain);
                                }
                                else
                                {
                                    conceptTuple1 = new Tuple<string, string>(conceptFormat, "TODO");
                                }
                            }

                            object inputTuple2 = null;
                            inputTuple2 = pw.Word;
                            if (tagO["input"] != null) // kr of input knowledge
                            {
                                var inputFormat = tagO["input"].Value<string>();
                                if (inputFormat != null)
                                {
                                    inputTuple2 = inputFormat;
                                }
                            }
                            pw.DragObject = new Tuple<object, object>(conceptTuple1, inputTuple2);
                        }
                        mp.Words.Add(pw);
                    }
                    #endregion
                 
                    Problems.Insert(mp.Index-1, mp);
                }
            }
        }
Exemplo n.º 5
0
        public void LoadRandomProblem()
        {
            while(true)
            {
                int index = GenerateRandomProblemIndex();

                if (Problems[index - 1] != null)
                {
                    CurrentProblemIndex = index - 1;
                    CurrentProblem = Problems[index - 1];
                    return;
                }
            }
        }
Exemplo n.º 6
0
 private void Load(int index)
 {
     CurrentProblemIndex = index - 1;
     CurrentProblem = Problems[CurrentProblemIndex];
 }