1

I'm creating a small Virtual Assistant project that uses speech recognition to help me get more advanced with Python. I've currently made it able to get the weather for a given city, or the current location, also simple arithmetic (adding, subtracting, etc) and getting the news using newsapi.org.

I would like to know how to speed up the process of identifying keywords using if statements. For example, right now I have something like this:

if "weather" in voiceRgn and "here" in voiceRgn or "weather" in voiceRgn:
    #current location weather function
elif "weather" in voiceRgn and "in" in voiceRgn and "current" not in voiceRgn and "my" not in voiceRgn:
    # given city/place weather function
elif "articles" in voiceRgn or "news" in voiceRgn or "headlines" in voiceRgn:
    # list news headlines function

As you can see it's very long and probably inefficient. Is there a way to shorten this, so that maybe it's given a list of words and if the clip contains something along the list of words, it runs the function?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
thestp123
  • 149
  • 2
  • 6
  • You may find that language processing is very complex and difficult, and you should instead use tools that are actually [made for that](http://www.nltk.org/) – OneCricketeer Oct 30 '16 at 00:13
  • Create bag of words from your data and use tf-idf weight to identify important terms/keywords. This is a suggestion since use of if/else statement for a large set of keywords is not a good idea. – Wasi Ahmad Oct 30 '16 at 02:41

0 Answers0