Exemple #1
0
 def test_parsing_introduction_segment(self):
     segment = "introduction"
     section = ""
     sub_section = ""
     fetch_content = FetchFromES()
     results = fetch_content.fetch_lesson_content_from_es(
         "What's the Weather like")
     parse_content = ParseESResults(results, segment)
     segment_content = parse_content.parse_segment_content()
     self.assertIsNotNone(segment_content)
Exemple #2
0
 def test_parsing_lesson_segment_and_section(self):
     segment = "lessons"
     lesson = "What's the weather like"
     section = "Introducing the Read Aloud"
     sub_section = ""
     fetch_content = FetchFromES()
     results = fetch_content.fetch_lesson_content_from_es(
         "What's Weather like")
     parse_content = ParseESResults(results, segment, lesson, section)
     section_content = parse_content.parse_section_content("sections")
     self.assertIsNotNone(section_content)
Exemple #3
0
 def test_parsing_introduction_segment_and_section(self):
     segment = "introduction"
     lesson = "What's the weather like"
     section = "Recommended resources"
     sub_section = ""
     fetch_content = FetchFromES()
     results = fetch_content.fetch_lesson_content_from_es(
         "What's Weather like")
     parse_content = ParseESResults(results, segment, lesson, section)
     section_content = parse_content.parse_section_content("sections")
     self.assertIsNotNone(section_content)
Exemple #4
0
 def test_parsing_lesson_segment_and_additional_section(self):
     segment = "lessons"
     lesson = "What's the weather like"
     section = "PRIMARY FOCUS OF LESSON"
     sub_section = ""
     fetch_content = FetchFromES()
     results = fetch_content.fetch_lesson_content_from_es(
         "What's Weather like")
     parse_content = ParseESResults(results, segment, lesson, section)
     section_content = parse_content.parse_section_content(
         "additional_sections")
     self.assertIsNotNone(section_content)
 def take_quiz(self,params):
     lesson = "What's the Weather like"      
     fetch_assessment_qna = FetchFromES()
     quiz_content = fetch_assessment_qna.fetch_assessment_qna_from_es(lesson)
     user_response = params["query"]    
     question = '' 
     validation_result = ''   
     filename=get_user_context_file(params)
     context= get_assesment_context(filename)        
     response=''       
     context["lesson"] = lesson   
     question_number = context["status"]["present_question"]
     context["status"]["total_questions"] = len(quiz_content) 
         
     if params["intent"]=="smartlearning.assessment" and context["status"]["present_question"]>0  and context["status"]["present_question"]!=context["status"]["total_questions"] and context["status"]["staroverprompt"]!=True:              
         response+="Would you like to continue the quiz from where you left last time or start over again?"
         question_number= context["status"]["previous_question"]
         context["status"]["staroverprompt"]=True            
         save_assesment_context(context,filename)  
     elif context["status"]["staroverprompt"]==True:
         if params["query"] =="start over" :
             context["status"]["present_question"]=0
             context["status"]["previous_question"]=0
             question_number = context["status"]["present_question"]
             context = self.update_context(context)                               
         else:
             validation_result+="ok lets continue < break time = '1s' />"
             question_number= context["status"]["previous_question"]
             
                 
         if question_number < context["status"]["total_questions"]:
             question = quiz_content[question_number]["question"]      
         context["status"]["staroverprompt"]=False
         save_assesment_context(context,filename)    
         response = validation_result 
         response = response + (question if question else "quiz completed")           
     else:
         if question_number > 0:
             validation_result += self.validate_response(user_response,context,quiz_content)
         context = self.update_context(context)
     
           
         if question_number < context["status"]["total_questions"]:
             question = quiz_content[question_number]["question"]      
         save_assesment_context(context,filename)    
         response = validation_result 
         response = response + (question if question else "quiz completed")    
     return response
Exemple #6
0
 def __init__(self, params, context):
     self.params = params
     self.context = context
     fetch_content = FetchFromES()
     self.results = fetch_content.fetch_lesson_content_from_es(
         "What's the Weather like")
Exemple #7
0
def get_answer(query):
    """
    Question Ananlyzer 
        1. question classification
        2. rephrasing question with synonyms
    """
    answer_type = classify_question(query)

    nlp_lib_answer_type = get_ner_type_for_answer_type[answer_type]

    query = rephrase_query_with_synonyms(query)
    """ 
    Loading the PreProcess class to pre-process queries and passages
    Pre Processing query to remove punctuations, stopwords and replace words(verbs) with their lemmatized forms
    """
    pre_process = PreProcess()
    query_object = pre_process.pre_process(query)
    #     entity_tagger = AnnotatorPipeline([EntityTagger()])
    #     entity_tagger.process(query_object)
    '''
    DOC (PASSAGES)-RETRIEVAL FROM ELASTICSEARCH
    '''
    document_fetcher = FetchFromES()
    documents = document_fetcher.fetch_document_from_es(query)
    """
    joining all documents to convert into single document seperated by "\n\n" (denotes the start of a new passage) 
     
    """
    merged_document = "\n\n".join(documents)
    passages = merged_document.split("\n\n")
    """
    Pre Processing documents to remove punctuations, stopwords and replace words(verbs) with their lemmatized forms
    
    """

    passage_objects = []
    for passage in passages:
        passage_object = pre_process.pre_process(passage)
        passage_objects.append(passage_object)
    """
    CANDIDATE PASSAGES EXTRACTOR
     
    """
    passage_extractor = PassageExtraction(query_object, nlp_lib_answer_type,
                                          passage_objects)
    candidate_passages = passage_extractor.process()
    """
    Checking for presence of at least one candidate passage
    """

    if candidate_passages and candidate_passages[0]:
        """
        SENTENCE EXTRACTION 
        
        Considering 1st passage(among candidate passages) as the required passage; using this passage to extract sentence 
        
        Sentence retrieval is on the basis of keyword percent match, similarity score and longest sub-sequence match
        
        Final sentence selected after sorting above features 
        
        """
        sentence_extractor = SentenceExtraction(
            query_object.text, nlp_lib_answer_type,
            candidate_passages[0][0].text, candidate_passages[0][0].raw_text)
        final_sentence = sentence_extractor.process()
        return final_sentence.raw_text

    else:
        """
        candidate passages have no elements when at least 2 keywords from query are not present in either of the passages 
        """
        return "REPHRASE THE QUESTION"


#
#     """
#     ANSWER EXTRACTION
#     """
#
#     answer_extractor = AnswerExtraction(query_object,nlp_lib_answer_type,final_sentence)
#     print(answer_extractor.extract_answer())

# if __name__== "__main__":
#
#     data = ['LOC:other-When are the plants full of leaves, flowers and fruits?']
#     for question in data:
#         if question:
#             query = question.split("-")[1].replace('\n','')
#             print(get_answer(query))
Exemple #8
0
 def test_fetch_documents_for_qna_processor(self):
     fetch_qna = FetchFromES()
     query = "seasons year"
     results = fetch_qna.fetch_document_from_es(query)
     print (results)
Exemple #9
0
 def test_fetch_assessment_qna(self):
     fetch_qna = FetchFromES()
     lesson_name = "What's the weather like"
     results = fetch_qna.fetch_assessment_qna_from_es(lesson_name)
     print (results)
Exemple #10
0
 def test_es_fetch_content(self):
     es_db = FetchFromES()
     results = es_db.fetch_lesson_content_from_es("What's the Weather Like")
     self.assertIsNotNone(results)
Exemple #11
0
 def test_es_index_exists(self):
     es_db = FetchFromES()
     es_db.check_index_exists()
Exemple #12
0
 def test_es_connection(self):
     es_db = FetchFromES()
     es_db.check_es_connection()
Exemple #13
0
 def __init__(self):
     fetch_content = FetchFromES()
     self.results = fetch_content.fetch_lesson_content_from_es(
         "What's Weather like")