示例#1
0
        public bool PostQuery(Object q)
        {
            Console.WriteLine("---Inside-PostQuery---");
            JObject jo        = (JObject)(q);
            string  categId   = jo["categ"].ToString();
            string  topicId   = jo["topic"].ToString();
            string  categName = jo["categName"].ToString();
            string  topicName = jo["topicName"].ToString();

            if (context.QuizRTTemplateT.FirstOrDefault(n => n.Categ == categId) == null)
            {
                QuizRTTemplate qT = new QuizRTTemplate();
                qT.Categ     = categId;
                qT.CategName = categName;
                qT.Topic     = topicId;
                qT.TopicName = topicName;
                context.QuizRTTemplateT.Add(qT);
                context.SaveChanges();  Console.WriteLine("---Template-Table-Inserted---");

                if (context.QuestionsT.FirstOrDefault(n => n.Categ == categId) == null)
                {
                    if (qT.TopicName == "Occupation")
                    {
                        Console.WriteLine("---Inside-Occupation---");
                        if (GenerateQuestion(qT) && GenerateOptions(qT))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (GenerateQuestion(qT))
                        {
                            return(true);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
示例#2
0
        public bool GenerateOptions(QuizRTTemplate q)
        {
            Console.WriteLine("---Inside-GenerateOptions---");
            sparQL = "SELECT ?cid ?options WHERE {?cid wdt:P31 wd:Q28640. OPTIONAL {?cid rdfs:label ?options filter (lang(?options) = 'en') . }}Limit " + NumberOfQuestions * 10 + "";
            Task <List <string> > dataReturns = System.Threading.Tasks.Task <string> .Run(() => GetOptionData(sparQL).Result);

            List <string> optionReviewList = dataReturns.Result;

            List <Questions> qL = context.QuestionsT
                                  .Where(n => n.Categ == q.CategName)
                                  .ToList();

            for (int i = 0; i < qL.Count; i++)
            {
                List <Options> oL = new List <Options>();
                oL = randomizeOptions(optionReviewList, q.CategName, qL[i].QuestionsId);
                context.OptionsT.AddRange(oL);
            }
            context.SaveChanges();
            return(true);
        }
示例#3
0
        public List <Questions> GetQuestion_directly(QuizRTTemplate template)
        {
            List <Questions>      g_question_notable = new List <Questions>();
            Task <string>         id        = Gettopic_id("https://www.wikidata.org/w/api.php?action=wbsearchentities&search=" + template.TopicName + "&language=en&format=json");
            string                f_id      = id.Result;
            string                sparQL    = "SELECT ?personLabel WHERE { ?person wdt:P106 wd:" + f_id + " . SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . } }";
            Task <List <string> > questions = GetQuestionData(sparQL);
            List <string>         all_questions_without_tables = questions.Result;
            Task <List <string> > options     = GetOptionData("SELECT ?cid ?options WHERE {?cid wdt:P31 wd:Q28640. OPTIONAL {?cid rdfs:label ?options filter (lang(?options) = 'en') . }}Limit 100");
            List <string>         all_options = options.Result;

            for (int i = 0; i < all_questions_without_tables.Count; i++)
            {
                Questions s_object = new Questions();
                s_object.QuestionGiven = "What is " + all_questions_without_tables[i] + " Occupation ?";
                List <Options> mut_options_single_q = randomizeOptions(all_options, template.TopicName);
                s_object.QuestionOptions = mut_options_single_q;
                g_question_notable.Add(s_object);
            }
            return(g_question_notable);
            // Console.WriteLine(all_options+"opopop");
            // Console.WriteLine(all_questions_without_tables+"qqqqq");
        }
示例#4
0
        public List <string> GenerateOptions1(QuizRTTemplate q)  // For generating options other than Occupation
        {
            if (q.TopicName == "Book")
            {
                sparQL = "SELECT ?cid ?options WHERE {?cid wdt:P106 wd:Q482980. OPTIONAL {?cid rdfs:label ?options filter (lang(?options) = 'en') . }}Limit " + NumberOfQuestions * 10 + "";
            }
            else if (q.TopicName == "princely state of the British Raj")
            {
                sparQL = "SELECT ?cid ?options WHERE {?cid wdt:P31 wd:Q6256. OPTIONAL {?cid rdfs:label ?options filter (lang(?options) = 'en') . }}Limit " + NumberOfQuestions * 10 + "";
            }
            else if (q.TopicName == "state of the United States")
            {
                sparQL = "SELECT ?cid ?options WHERE {?cid wdt:P166/wdt:P31 wd:Q7191. OPTIONAL {?cid rdfs:label ?options filter (lang(?options) = 'en') . }}Limit " + NumberOfQuestions * 10 + "";
            }
            else if (q.TopicName == "business")
            {
                sparQL = "SELECT DISTINCT ?person ?personLabel ?options WHERE {?person wdt:P31 wd:Q3918.?person wdt:P571 ?options SERVICE wikibase:label {bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en' .}}Limit " + NumberOfQuestions * 10 + "";
            }
            Task <List <string> > dataReturns = System.Threading.Tasks.Task <string> .Run(() => GetOptionData(sparQL).Result);

            List <string> optionReviewList = dataReturns.Result;

            return(optionReviewList);
        }
示例#5
0
        // ------------------------

        public bool GenerateQuestion(QuizRTTemplate q)
        {
            Console.WriteLine("---Inside-GenerateQuestion---");
            if (q.TopicName == "Occupation")
            {
                sparQL = "SELECT ?personLabel WHERE { ?person wdt:" + q.Topic + " wd:" + q.Categ + " . SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . } }LIMIT " + NumberOfQuestions + "";
                Task <List <string> > dataReturns = System.Threading.Tasks.Task <string> .Run(() => GetQuestionData(sparQL).Result);

                List <string> quesReviewList = dataReturns.Result;

                List <Questions> qL = new List <Questions>();
                for (int i = 0; i < quesReviewList.Count; i++)
                {
                    Questions ques = new Questions();
                    ques.QuestionGiven = "What is " + quesReviewList[i] + " " + q.TopicName + "?";
                    ques.Topic         = q.TopicName;
                    ques.Categ         = q.CategName;
                    qL.Add(ques);
                }
                context.QuestionsT.AddRange(qL);
                context.SaveChanges();
                return(true);
            }
            else if (q.TopicName != "Occupation")
            {
                //List<string> other_options = new List<string>();
                Task <string> id   = Gettopic_id("https://www.wikidata.org/w/api.php?action=wbsearchentities&search=" + q.TopicName + "&language=en&format=json");
                string        f_id = id.Result;
                if (q.TopicName == "Book")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + f_id + ".?cid wdt:P50 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName == "princely state of the British Raj")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:Q1336152 . ?cid wdt:P17 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                    Console.WriteLine("rajjjjj");
                }
                else if (q.TopicName == "state of the United States")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P138 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName == "business")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P571 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName != "princely state of the British Raj")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P17 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName != "princely state of the British Raj")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P17 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName != "princely state of the British Raj")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P17 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName != "princely state of the British Raj")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P17 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                else if (q.TopicName != "princely state of the British Raj")
                {
                    sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.Topic + ".?cid wdt:P17 ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}Limit 10";
                }

                Task <List <universal_object> > dataReturns = System.Threading.Tasks.Task <string> .Run(() => GetQuestionData_others(sparQL).Result);

                List <universal_object> quesReviewList = dataReturns.Result;
                Console.WriteLine(quesReviewList.Count + "aaaaaaaaaaaaaaaaaa");
                List <Questions> qL = new List <Questions>();

                List <string> books_etc_options = GenerateOptions1(q);

                for (int i = 0; i < quesReviewList.Count; i++)
                {
                    Questions ques = new Questions();
                    if (q.TopicName == "Book")
                    {
                        ques.QuestionGiven = "Who is the author of " + quesReviewList[i].mainobject + "?";
                    }
                    else if (q.TopicName == "princely state of the British Raj")
                    {
                        ques.QuestionGiven = " " + quesReviewList[i].mainobject + " belongs to which country ?";
                        Console.WriteLine("qqqqqqqqqqqqqqqqqqqqq");
                    }
                    else if (q.TopicName == "state of the United States")
                    {
                        ques.QuestionGiven = " " + quesReviewList[i].mainobject + " is named after ?";
                    }
                    else if (q.TopicName == "business")
                    {
                        Console.WriteLine("qqqqqqqqqqqqqqqqqqqqq");
                        ques.QuestionGiven = "When was " + quesReviewList[i].mainobject + " established ?";
                    }
                    ques.Topic = q.TopicName;
                    ques.Categ = q.CategName;
                    //qL.Add(ques);
                    context.QuestionsT.Add(ques);
                    Options op = new Options();
                    op.IsCorrect   = true;
                    op.QuestionsId = ques.QuestionsId;
                    op.OptionGiven = quesReviewList[i].predicate;
                    context.OptionsT.Add(op);
                    List <int> randomNumber = getRandonNumber(0, books_etc_options.Count - 1, optionNumber + 2);
                    for (int j = 0; j < 3; j++)
                    {
                        Options op1 = new Options();
                        op1.IsCorrect   = false;
                        op1.QuestionsId = ques.QuestionsId;
                        // if(books_etc_options[randomNumber[k]]!=op.OptionGiven)
                        // {
                        op1.OptionGiven = books_etc_options[randomNumber[j]];
                        // j++;
                        context.OptionsT.Add(op1);
                        //}
                        // k++;
                    }
                }
                //context.QuestionsT.AddRange(qL);
                context.SaveChanges();
                Console.WriteLine("quyuqywuqywuqyw");
                return(true);
            }
            return(false);
        }