Example #1
0
    def main(self, question):
        """
        Main method which instantiates the classes necessary for the operation
        of the program, stores the collected data in parameters and returns a
        formatted dictionary.

        Args:
            question(str): input user

        Returns:
            dict : Formatted response returned to AJAX
        """
        initialize_parser = Parser()
        self.parser = initialize_parser.clean(question)

        initialize_google_client = GoogleClient(self.parser)
        self.google_answer = initialize_google_client.get_location()

        initialize_wiki_client = WikiClient()
        self.wiki_answer = initialize_wiki_client.search_page(self.google_answer)
        
        if self.wiki_answer['extract']:
            self.wiki_answer['extract'] = layout(self.wiki_answer['extract'])

        self.papy_answer = self._format_return_datas()
        return self.papy_answer
 def test_parser_can_return_clean_of_all_output(self):
     """ Tests whether the parser is able to run all its methods in order
     to get a clean localisation from a full sentence."""
     parser = Parser(
         "Bonjour Grandpy, peux-tu me dire l'adresse de la tour Eiffèl?",
         STOPWORDS, ACCENTS, QUESTIONS)
     result = parser.clean()
     assert result == "tour eiffel"
Example #3
0
def app_grandpy(question):
    """
    The main implementation of all the application logic
    Create the parser for the questions asked analyzer
    Using the API Google maps
    Using the API Wikipedia
    """
    parser = Parser(question)
    question = parser.clean()
    gmaps = GoogleMaps()
    result_address = gmaps.search(question)
    wikip = Wikipedia()
    pages = wikip.search_for_pages(result_address["lat"],
                                   result_address["lng"])
    result_article, result_url = wikip.search_for_page_content(
        pages[0]["pageid"]
    )
    return {
        "parser": question,
        "grandpy": random.choice(reponseListe),
        "gmaps": result_address,
        "wikip": result_article,
        "wikip_url": result_url}
Example #4
0
def initialize_parser_class(request):
    pars = Parser()
    yield pars.clean(request.param)