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)
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)
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)
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 read_sub_section(self, lesson, section, sub_section, query=""): segment = "lessons" attr = "sections" # "additional_sections" if section == None: if query == '': query = "this" return "Oops! There is no sub-section with this title " + query + ". Please repeat the sub-section title again." #return "There is no sub-section like "+query+".Please say the sub-section name correctly." parse_content = ParseESResults(self.results, segment, lesson, section, sub_section) sub_section_content = parse_content.parse_sub_section_content(attr) if sub_section_content == None: if query == '': query = "this" return "Oops! There is no sub-section with this title " + query + ". Please repeat the sub-section title again." return self.change_dict_section_content_to_string_content( sub_section_content, "sub_section")
def read_lesson(self, lesson): parse_content = ParseESResults(self.results, "lessons", lesson) lesson_content = parse_content.parse_lesson_content() if not lesson_content: return "I cannot read this lesson yet. Is there another lesson I can read for you? " sections = [] for section in lesson_content["sections"]: sections.append(section["section_name"]) additional_sections = [] for additional_section in lesson_content["additional_sections"]: additional_sections.append(additional_section["section_name"]) response = "Lesson 1, \"What's the weather like?\", contains " + str(len(sections)) + " sections, They are " + ", ".join(sections[:-1])+ ' and ' + sections[-1] + \ ". The lesson also contains some precursor content like <break time='1s' />" +", ".join(additional_sections[:-1])+ ' and '+ additional_sections[-1] + \ "<break time = '0.5s' />. You can ask me to repeat, skip or jump to the previous or next section anytime" return response
def read_segment(self, segment): """ Any segment contains sections.App can respond back with 1. reading list of sections or 2. start reading with first section content """ parse_content = ParseESResults(self.results, segment) segment_content = parse_content.parse_segment_content() sections = [] for section in segment_content["sections"]: sections.append(section["section_name"]) response = segment + " segment contains " + str(len(sections)) + " sections, They are " + ", ".join(sections[:-1])+ ' and ' + sections[-1]+ \ "<break time='0.5s' />. Which section would you like to hear? You can ask me to repeat, skip or jump to the previous or next section anytime" return response
def read_section(self, segment, lesson, attr, section, query=""): """ attr :: sections/additional_sections (only for lessons segment) """ parse_content = ParseESResults(self.results, segment, lesson, section) section_content = parse_content.parse_section_content(attr) if section_content == None: if query == '': query = "this" return "Oops! There is no section with this title " + query + ". Please repeat the section title again." # response = fetch_ordinal_of_section(segment,section,attr) if segment == "lessons" and attr == "sections": sub_sections = [] for sub_section in section_content["sub_sections"]: sub_sections.append(sub_section["sub_section_name"]) response = section + " section contains " + str(len(sub_sections)) + " sub-sections.They are -" + ", ".join(sub_sections[:-1])+ ' and '+ sub_sections[-1]+ \ "<break time = '0.5s' />. You can ask me to repeat, skip or jump to the previous or next sub-section anytime" return response else: return self.change_dict_section_content_to_string_content( section_content, "section")