Esempio n. 1
0
def process(sentence):
    """ Process the sentence """

    keywords = sentence.keywords(include=["VB", "NS"])
    paul.log("KEYWORDS:", keywords)

    if paul.has_one_of(keywords, ["mute", "silence", "silent, " "unmute"]):
        mute()
        return "Toggling mute."
    elif paul.has_one_of(keywords, ["volume", "louder", "quieter"]):
        return change_volume(keywords)
    elif paul.has_one_of(keywords, ["brightness", "brighter", "dimmer"]):
        return change_brightness(keywords)
    elif paul.has_word(keywords, "screensaver"):
        screensaver()
        return "Done!"
    elif paul.has_word(keywords, "desktop"):
        desktop()
        return "Done!"
    elif paul.has_one_of(keywords, ["lock", "sleep"]):
        sleep()
        return "Done!"
    elif paul.has_one_of(keywords, ["more", "again"]):
        return repeat()
    else:
        return "I couldn't manage that."
Esempio n. 2
0
def get_val(keywords, key, sentence):
    ''' Determine the value to set. '''
    val = ''
    flag = True
    confirm = "Done."
    
    if paul.has_one_of(keywords, ["off", "false", "stop"]):
        val = "False"
    elif paul.has_one_of(keywords, ["on", "true", "start", "begin"]):
        val = "True"
    elif key == "title":
        if paul.has_word(keywords, "sir"):
            val = "sir"
        elif paul.has_word(keywords, "ma'am"):
            val = "ma'am"
        else:
            return ("I don't understand which title " 
                    + "you want to go by, sir or ma'am.", False)
        val = '"{}"'.format(val)
    elif key == "search_engine":
        engines = ["Google", "Bing", "Yahoo", "DuckDuckGo", "Baidu"]
        for engine in engines:
            if paul.has_word(keywords, engine.lower()):
                val = '"{}"'.format(engine)
        if val == '':
            return ("Sorry, I couldn't work out which " 
                    + "search engine you want to use.\n"
                    + "Please choose from Google, Bing, Yahoo, "
                    + "DuckDuckGo and Baidu next time.", False)
    elif key == "name":
        if sentence.has_one_of(["i", "me"]):
            val = paul.join_lists(sentence.get_part("??"), 
                                  sentence.get_part("XO"))
            paul.log("VAL[0]", val[0])
            val = '"{}"'.format(val[0].capitalize())
            confirm = ("Ok, I'll call you " + 
                       "{} from now on.".format(val[1:-1]))
        elif sentence.has_word("you"):
            return ("My name is Paul.", False)
        else:
            return ("Not really sure what you're getting at...", False)
    else:
        paul.log("PARAMETER NOT FOUND")
        return ("I'm not sure how you" 
                + " wanted '{}' set.".format(key), False)
    return (confirm, flag, val)
Esempio n. 3
0
def get_key(keywords):
    ''' Decide on the key to use '''
    key = ''
    flag = True
    if paul.has_one_of(keywords, ["noisy", "noisiness", "talk", "talking"]):
        key = "NOISY"
    elif paul.has_one_of(keywords, ["verbose", "verbosity", 
                                    "debug", "debugging"]):
        key = "VERBOSE"
    elif paul.has_word(keywords, "logging"):
        key  = "LOGGING"
    elif paul.has_one_of(keywords, ["name", "call", "called"]):
        key = "name"
    elif paul.has_word(keywords, "title"):
        key = "title"
    elif paul.has_word(keywords, "prompt"):
        return ("You have to change the prompt in settings"
                + " manually, I'm afraid.", False)
    elif paul.has_one_of(keywords, ["search", "engine", "search engine"]):
        key = "search_engine"
    else:
        paul.log("FOUND NO FLAG")
        return ("I'm not sure what you wanted me to set.", False)
    return (key, flag)
Esempio n. 4
0
def process(sentence):
    ''' Process the sentence, act as necessary '''
    
    paul.loading()
    ignore = [
        "weather",
        "forecast",
        "rainy",
        "rain",
        "raining",
        "sunny",
        "temperature",
        "cold",
        "hot",
        "humid",
    ]
    
    keywords = sentence.keywords()
    paul.log("KEYWORDS: " + str(keywords))
    
    today = datetime.date.today().weekday()
    paul.log("TODAY: " + str(today))
    
    day_index = 0
    
    weekdays = ['monday', 'tuesday', 'wednesday', 
                'thursday', 'friday', 'saturday', 'sunday']
    
    if (len(keywords) == 0 
        or paul.has_one_of(keywords, ['today', 'now', "today's"])):
        day_index = 0
    elif paul.has_one_of(keywords, ['tomorrow', "tomorrow's"]):
        day_index = 2
    elif paul.has_one_of(keywords, weekdays):
        for day in weekdays:
            if paul.has_word(keywords, day):
                paul.log("DAY:", day)
                day_index = (weekdays.index(day) + today) % 7 + 1
            if day_index == 1:
                day_index = 0
    
    paul.log("DAY: " + str(day_index))
    
    return weather(day_index, sentence)
Esempio n. 5
0
def process(sentence):
    ''' Process the input sentence '''
    
    keywords = sentence.keywords(include=["NS", "VB"])
    
    takeback = "I'm still learning!"
    
    if paul.has_one_of(keywords, GREETINGS):
        takeback = greet()
    elif paul.has_one_of(keywords, THANKS):
        takeback = thank()
    elif paul.has_one_of(keywords, FEELING):
        takeback = feeling()
    elif paul.has_word(keywords, "yourself"):
        takeback = about_me()
    elif paul.has_one_of(keywords, RANDOM):
        takeback = random(sentence)
    elif paul.has_one_of(keywords, ["name", "call", "called", "named"]):
        return sentence.forward("settings")
    return takeback
Esempio n. 6
0
def process(sentence):
    ''' Process the sentence. '''
    
    sentence.replace_it()
    eqns = make_equations(sentence)
    if len(eqns) == 0:
        return "I'm not sure what you want me try try and solve. Sorry!"
    subs = sentence.has_one_of(["sub", "substitute", "solve"])
    rearrange = sentence.has_one_of(["rearrange", "solve"])
    if subs: rearrange = False
    if (paul.get_it() and
        paul.Sentence(paul.get_it()).has_one_of("+/^*-=1234567890")):
        eqns.append(paul.get_it()) if len(eqns) < 2 else 0
    paul.log(eqns)
    eqn_string = eqns[0]
    if subs:
        try:
            eqn_string = eqns[1]
        except IndexError:
            eqn_string = eqns[0]
    if rearrange:
        for e in eqns:
            if len(e) > 1:
                eqn_string = e
                break
    
    paul.log("SUBS:", subs, "REARRANGE:", rearrange)
    paul.log("EQUATION:", eqn_string)
    had_equals = True
    if not paul.has_word(eqn_string, "="):
        eqn_string = "y=" + eqn_string
        had_equals = False
    elif eqn_string.strip()[0] == "=":
        eqn_string = "y" + eqn_string
    paul.log("EQUATION:", eqn_string)
    
    # try:
    eqn = Equation(eqn_string)
    # except:
    #     return "Something went horribly wrong when I tried to math. Oops."
    # 
    if subs and len(eqns) > 1:
        eq2 = Equation(eqns[0])
        if type(eq2.head.right.value) == float:
            eqn.substitute((eq2.head.left.value, eq2.head.right.value))
        elif type(eqn.head.right.value) == float:
            eq2.substitute((eqn.head.left.value, eqn.head.right.value))
            eqn, eq2 = eq2, eqn
        else:
            url = "http://www.wolframalpha.com/input/?i="
            query = "sub {} into {}".format(eq2, eqn)
            query.replace("+", "%2D").replace("=", "%3D").replace("/", "%2F")
            paul.open_URL(url+query)
            return '''I was unsuccessful in finding the solution:\n{}\n{}'''.format(eq2, eqn)
    
    if rearrange:
        targ = "x"
        targets = sentence.keywords()
        for word, _ in targets:
            if len(word) == 1:
                targ = word
        try:
            eqn.rearrange_linear_for(targ)
        except RuntimeError:
            url = "http://www.wolframalpha.com/input/?i="
            query = "rearrange {} for {}".format(eqn, targ)
            query.replace("+", "%2D").replace("=", "%3D").replace("/", "%2F")
            paul.open_URL(url+query)
            return "Oh dear, not a clue. Try this instead."
    
    result = str(eqn)
    if not had_equals:
        result = result[4:]
    
    paul.set_it(result)
    try:
        if result[0] == "(" and result[-1] == ")": result = result[1:-1]
    except IndexError:
        pass
    return result
Esempio n. 7
0
def process(sentence):
    ''' Process the sentence '''
    
    commands = {
        'open': lambda location: get(location),
        'get': lambda location: get(location),
        'launch': lambda location: get(location),
        'show': lambda location: reveal(location),
        'find': lambda location: reveal(location),
        'search': lambda location: reveal(location),
        'reveal': lambda location: reveal(location),
        'locate': lambda location: reveal(location),
        'be': lambda location: reveal(location), # Catch in case, use safer reveal than get
    }
    
    types = {
        'folder': "folder ",
        'powerpoint': "presentation ",
        'keynote': "presentation ",
        'document': "word ",
        'word': "word ",
        'spreadsheet': "spreadsheet ",
        'excel': "spreadsheet ",
        'picture': "image ",
        'image': "image ",
        'movie': "movie ",
        'film': "movie",
        'video': "movie ",
        'audio': "audio ",
        'music': "music ",
        'email': "email ",
        'event': "event ",
        'pdf': "pdf",
        'preference': "preferences ",
        'bookmark': "bookmark ",
        'favourite': "bookmark ",
        'font': "font ",
        'widget': "widget ",
        "app": "application ", 
        "application": "application ", 
        "program": "application ", 
        "executable": "application ",
    }
    
    apps = ["app", "application", "program", "executable"]
    
    replaced = sentence.replace_it()
    preps = sentence.get_part("PP", indexes=True)
    paul.log(preps)
    preps = paul.filter_out(preps, "for")
    paul.log(preps)
    
    try:
        object = sentence.get_part("NO")[0]
    except:
        object = None
    verb = sentence.get_part("VB")[0]
    
    if replaced:
        return commands[verb](replaced)
    
    ignore = list(types.keys()) + list(commands.keys())
    
    keywords = sentence.keywords(ignore=["file"])
    paul.log("KEYWORDS: " + str(keywords))
    if keywords == []:
        return "I don't understand. Sorry."
    
    filters = generate_filters(keywords, preps)
    if object in types.keys():
        filters.append("kind:{}".format(types[object]))
    
    if object in apps:
        where = "/Applications"
        params = keywords[0][0] + " kind:application"
        paul.log("FINDING APP")
    else:
        where = False
        params = " ".join(filters)
        paul.log("PARAMETERS: " + str(params))
    
    search = filters[0]
    paul.log(search)
    
    if search.startswith("http") or search.startswith("www."):
        s = search
        paul.open_URL(s if s.startswith("http") else "http://"+s)
        return "Opening the website..."
    elif paul.has_word(keywords, "all"):
        return show_all(params)
    else:
        return commands[verb](find(params, where))