def answer_question(input_question): en_doc = nlp(u'' + input_question) question_class = classify_question(en_doc) print("Class:", question_class) question_keywords = extract_features(question_class, en_doc) print("Question Features:", question_keywords) question_query = construct_query(question_keywords, en_doc) print("Question Query:", question_query) print("Fetching Knowledge source...") wiki_pages = fetch_wiki(question_keywords, number_of_search=3) print("Pages Fetched:", len(wiki_pages)) # Anaphora Resolution ranked_wiki_docs = rank_docs(question_keywords) print("Ranked Pages:", ranked_wiki_docs) candidate_answers, split_keywords = get_candidate_answers( question_query, ranked_wiki_docs, nlp) print("Candidate Answer:", "(" + str(len(candidate_answers)) + ")", candidate_answers) print("Answer:", " ".join(candidate_answers)) answer = " ".join(candidate_answers) return answer
def answer_question(input_question): warnings.warn("This method is now deprecated.", DeprecationWarning) en_nlp = spacy.load('en_core_web_md') en_doc = en_nlp(u'' + input_question) question_class = classify_question(en_doc) print("Class:", question_class) question_keywords = extract_features(question_class, en_doc) print("Question Features:", question_keywords) question_query = construct_query(question_keywords, en_doc) print("Question Query:", question_query) print("Fetching Knowledge source...") wiki_pages = fetch_wiki(question_keywords, number_of_search=3) print("Pages Fetched:", len(wiki_pages)) # Anaphora Resolution ranked_wiki_docs = rank_docs(question_keywords) print("Ranked Pages:", ranked_wiki_docs) candidate_answers, split_keywords = get_candidate_answers( question_query, ranked_wiki_docs, en_nlp) print("Candidate Answer:", "(" + str(len(candidate_answers)) + ")", candidate_answers) print("Answer:", " ".join(candidate_answers)) answer = " ".join(candidate_answers) return answer
def answer_question(q, num_sentences): q = nlp(u'' + q) question_class = classify_question(q) _logger.info("Question Class: {}".format(question_class)) question_keywords = extract_features(question_class, q) _logger.debug("Question Features: {}".format(question_keywords)) query = construct_query(question_keywords, q) _logger.debug("Query: {}".format(query)) _logger.info("Retrieving {} wikipedia pages...".format(num_sentences)) wiki_pages = fetch_wiki(question_keywords, number_of_search=num_sentences) _logger.debug("Pages retrieved: {}".format(len(wiki_pages))) # Anaphora Resolution ranked_wiki_docs = rank_docs(question_keywords) _logger.debug("Ranked pages: {}".format(ranked_wiki_docs)) candidate_answers, keywords = get_candidate_answers(query, ranked_wiki_docs, nlp) _logger.info("Candidate answers ({}):\n{}".format(len(candidate_answers), '\n'.join(candidate_answers))) return " ".join(candidate_answers)
def process_answer(self): _logger.info("Retrieving {} Wikipedia pages...".format( self.search_depth)) search_wikipedia(self.question_keywords, self.search_depth) # Anaphora Resolution wiki_pages = search_rank(self.query) _logger.info("Pages retrieved: {}".format(len(wiki_pages))) self.candidate_answers, keywords = get_candidate_answers( self.query, wiki_pages, self.nlp) _logger.info("Candidate answers ({}):\n{}".format( len(self.candidate_answers), '\n'.join(self.candidate_answers))) return " ".join(self.candidate_answers)
def process_answer(self): _logger.info("Retrieving {} wikipedia pages...".format( self.search_depth)) wiki_pages = fetch_wiki(self.question_keywords, number_of_search=self.search_depth) _logger.debug("Pages retrieved: {}".format(len(wiki_pages))) # Anaphora Resolution ranked_wiki_docs = rank_docs(self.question_keywords) _logger.debug("Ranked pages: {}".format(ranked_wiki_docs)) self.candidate_answers, keywords = get_candidate_answers( self.query, ranked_wiki_docs, self.nlp) _logger.info("Candidate answers ({}):\n{}".format( len(self.candidate_answers), '\n'.join(self.candidate_answers))) return " ".join(self.candidate_answers)