コード例 #1
0
ファイル: QuizRTRepo.cs プロジェクト: HelloKuldeep/QuizRTapi
        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");
        }
コード例 #2
0
        public async Task <bool> InsertQuestionsAndOptions(QuestionGeneration q, ObjectId currentTemplateId)
        {
            var otherOptionsList = GenerateOtherOptions(q.CategoryName);

            string sparQL = "SELECT ?cidLabel ?authortitleLabel WHERE {?cid wdt:P31 wd:" + q.TopicId + ".?cid wdt:" + q.CategoryId + " ?authortitle .SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . }}LIMIT " + NumberOfQuestions + "";
            // string sparQL2 = $@"SELECT ?personLabel WHERE {{ ?person wdt:{q.Topic} wd:{q.Categ} . SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' . } }LIMIT "+NumberOfQuestions+""; // Nishant
            Task <List <universal_object> > subjectForQuestion = System.Threading.Tasks.Task <string> .Run(() => GetSubjectsForQuestion(sparQL).Result);

            List <universal_object> listOfSubjectForQuestion = subjectForQuestion.Result;

            List <Questions> questionsList         = new List <Questions>();
            string           replacementStrSubject = '[' + GetBetween(q.Text, "[", "]") + ']';
            string           replacementStrObject  = '(' + GetBetween(q.Text, "(", ")") + ')';

            for (int i = 0; i < listOfSubjectForQuestion.Count; i++)
            {
                if (!(listOfSubjectForQuestion[i].mainobject[0] == 'Q' && IsDigitsOnly(listOfSubjectForQuestion[i].mainobject.Substring(1))))
                {
                    string questionText = q.Text;
                    questionText = questionText.Replace(replacementStrObject, q.CategoryName);
                    questionText = questionText.Replace(replacementStrSubject, listOfSubjectForQuestion[i].mainobject);

                    List <OtherOptions> listOfOtherOptions = new List <OtherOptions>();
                    // int iteratorForListOfOptions = 0;
                    int increaser = 0;
                    // otherOptionsList = otherOptionsList.GetRange(1, otherOptionsList.Count).Append(otherOptionsList.First()).ToList();

                    for (int j = 0; j < 3 + increaser; j++)
                    {
                        if (otherOptionsList[j] != "" && !(otherOptionsList[j][0] == 'Q' && IsDigitsOnly(otherOptionsList[j].Substring(1))))
                        {
                            OtherOptions otherOptionObject = new OtherOptions();
                            otherOptionObject.Option = otherOptionsList[j];
                            listOfOtherOptions.Add(otherOptionObject);
                            // if(iteratorForListOfOptions+3 < otherOptionsList.Count)
                            //     iteratorForListOfOptions++;
                            // else
                            //     iteratorForListOfOptions = 0;
                        }
                        else
                        {
                            increaser++;
                        }
                    }
                    otherOptionsList = Shift(otherOptionsList);

                    Questions questionObject = new Questions();
                    questionObject.Question         = questionText;
                    questionObject.CorrectOption    = listOfSubjectForQuestion[i].predicate;
                    questionObject.OtherOptionsList = listOfOtherOptions;

                    questionsList.Add(questionObject);
                }
            }
            QuestionGeneration questionGeneratedObject = new QuestionGeneration();

            questionGeneratedObject.Id            = currentTemplateId;
            questionGeneratedObject.Text          = q.Text;
            questionGeneratedObject.CategoryId    = q.CategoryId;
            questionGeneratedObject.CategoryName  = q.CategoryName;
            questionGeneratedObject.TopicId       = q.TopicId;
            questionGeneratedObject.TopicName     = q.TopicName;
            questionGeneratedObject.QuestionsList = questionsList;
            ReplaceOneResult updateResult = await context.QuestionGenerationCollection.
                                            ReplaceOneAsync(filter : g => g.Id == questionGeneratedObject.Id, replacement : questionGeneratedObject);

            return(updateResult.IsAcknowledged && updateResult.ModifiedCount > 0);
        }
コード例 #3
0
ファイル: QuizRTRepo.cs プロジェクト: HelloKuldeep/QuizRTapi
        // ------------------------

        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);
        }