Now we can define some functions that take speech as input and outputs the relevant information. The trick here is to remove noise words like “what”, “who”, etc. This can be accomplished with the re package. Here is the wolframLookUp function:

As you can see you need to have an application id from Wolfram. You can easily sign up and get an id here and just load that into your keyring. Also I implemented a try/except block because sometimes (not often) the WolframAlpha API will not return anything and this will catch that.

As you can see there are lot more noise words removed from the wikipedia lookup because it is not as smart as parsing as WolframAlpha. Also there is a second parameter passed, num_sentences, which allows the user to determine whether they want a long or a short response.