Ejemplo n.º 1
0
def checkReminders(verbose=False):

    from timeParsing import getTimeVec
    from determineFunction import updateContext
    from emotions import getFace

    rotateCircle(index=2, angle=30)

    #print "LOADING"
    REMINDERS = load(DATA_DIR + "reminders.txt", LPC=1)
    REMINDERS = [s[0] for s in REMINDERS]
    #print "LOADING... DONE"

    #nowTime = getTimeVec("now")
    updateReminders = False

    NowTime = datetime.datetime.now()
    NowTotalSecs = (NowTime - datetime.datetime(1970, 1, 1)).total_seconds()

    dueInFuture = 0  # track how many are due in future

    textStr = ""

    for i in range(len(REMINDERS)):
        item = REMINDERS[i]

        if item[1] != [] and item[2] != True:

            # see if the time has passes:

            NoteTime = datetime.datetime(year=item[1][0],
                                         month=item[1][1],
                                         day=item[1][2],
                                         hour=item[1][3],
                                         minute=item[1][4],
                                         second=item[1][5])
            NoteTotalSecs = (NoteTime -
                             datetime.datetime(1970, 1, 1)).total_seconds()

            timePassed = (NowTotalSecs >= NoteTotalSecs)

            if not timePassed:
                dueInFuture += 1
                #say("Future: "+item[0], more=True, speak=setting("SPEAK"), moodUpdate=True)

            if timePassed:

                noteTD = toDict(item[1])

                diffStr = timeDiff(noteTD)

                rStr = "Reminder: " + item[0] + " (due " + diffStr + ")"

                say(rStr,
                    more=(not setting('SEND_TEXT')),
                    speak=setting("SPEAK"),
                    moodUpdate=True)
                #say("Reminder: "+item[0], more=True, speak=setting("SPEAK"), moodUpdate=True)

                REMINDERS[i] = (item[0], item[1], True)
                updateContext(inStr=item[0])
                updateReminders = True

                textStr = textStr + " <" + item[0] + ">"

    if setting('SEND_TEXT') and not textStr == "":
        face = getFace(GLOB['MOOD'])
        moodStr = ""
        if face[0] == "":
            moodStr = "(" + getFace(
                GLOB['MOOD'])[2] + ")"  # use the description
        else:
            moodStr = getFace(GLOB['MOOD'])[0]  # use the emoticon

        textStr = setting(
            "YOUR_NAME") + " " + moodStr + " REMINDER: " + textStr
        say("Sending text...", more=True, speak=False, moodUpdate=True)
        sendText(textStr)

    if verbose and not updateReminders:
        dueStr = "(" + ('%s' % dueInFuture) + " due in future)"
        say("No new reminders. " + dueStr,
            more=False,
            speak=setting("SPEAK"),
            moodUpdate=True)
        updateContext(inStr="reminders")
        return "new prompt"

    # want to overwrite ingestions file
    if updateReminders:
        f = open(DATA_DIR + 'reminders.txt', 'w')
        for item in REMINDERS:
            userStr = k.cleanWord(item[0], cleanType=1)
            f.write("\'%s\', %s, %s\n" % (userStr, item[1], item[2]))
        f.close()

    return "no prompt"
Ejemplo n.º 2
0
def checkReminders(verbose=False):

	from timeParsing import getTimeVec
	from determineFunction import updateContext
	from emotions import getFace

	rotateCircle(index=2, angle=30)

	#print "LOADING"
	REMINDERS=load(DATA_DIR+"reminders.txt", LPC=1)
	REMINDERS=[s[0] for s in REMINDERS]
	#print "LOADING... DONE"


	#nowTime = getTimeVec("now")
	updateReminders=False

	
	NowTime = datetime.datetime.now()
	NowTotalSecs = (NowTime-datetime.datetime(1970,1,1)).total_seconds()

	dueInFuture=0 # track how many are due in future

	textStr=""

	for i in range(len(REMINDERS)):
		item = REMINDERS[i]

		if item[1] != [] and item[2] != True:

			# see if the time has passes:
			
			NoteTime = datetime.datetime(year = item[1][0], month=item[1][1], day=item[1][2], hour=item[1][3], minute=item[1][4], second=item[1][5])
			NoteTotalSecs = (NoteTime-datetime.datetime(1970,1,1)).total_seconds()

			timePassed = (NowTotalSecs >= NoteTotalSecs)
		
			if not timePassed:
				dueInFuture += 1
				#say("Future: "+item[0], more=True, speak=setting("SPEAK"), moodUpdate=True)

			if timePassed:
		
				noteTD = toDict(item[1])
				
				diffStr = timeDiff(noteTD)
		
				rStr = "Reminder: "+item[0]+" (due "+diffStr+")"
		
				say(rStr, more=(not setting('SEND_TEXT')), speak=setting("SPEAK"), moodUpdate=True)
				#say("Reminder: "+item[0], more=True, speak=setting("SPEAK"), moodUpdate=True)

				REMINDERS[i] = (item[0], item[1], True)
				updateContext(inStr=item[0])
				updateReminders=True

				textStr=textStr+" <"+item[0]+">"



				
				
	

	if setting('SEND_TEXT') and not textStr == "":
		face=getFace(GLOB['MOOD'])
		moodStr=""
		if face[0]=="":
			moodStr="("+getFace(GLOB['MOOD'])[2]+")" # use the description
		else:
			moodStr=getFace(GLOB['MOOD'])[0] # use the emoticon
		
		textStr=setting("YOUR_NAME")+" "+moodStr+" REMINDER: "+textStr
		say("Sending text...", more=True, speak=False, moodUpdate=True)
		sendText(textStr)

	if verbose and not updateReminders:
		dueStr = "("+('%s'%dueInFuture)+" due in future)"
		say("No new reminders. "+dueStr, more=False, speak=setting("SPEAK"), moodUpdate=True)
		updateContext(inStr="reminders")
		return "new prompt"

	# want to overwrite ingestions file
	if updateReminders:
		f = open(DATA_DIR+'reminders.txt', 'w')
		for item in REMINDERS:
			userStr =  k.cleanWord(item[0], cleanType=1)
			f.write("\'%s\', %s, %s\n" % (userStr, item[1], item[2]))
		f.close()

	return "no prompt"
Ejemplo n.º 3
0
def KTInterface(inCmd, inStr, matches=[[], []]):
    #print "KTI"
    from determineFunction import refineMatches, updateContext

    inStr = inStr.replace('\"', '').replace('\'', '')

    #matches = refineMatches(inCmd, inStr)

    matches = substituteBiographicMemory(matches, queryType='what is')

    inStr = inStr.lower()

    setFace(face="thinking_animation")

    # check if summarizing clipboard
    if "clipboard" in inStr and len(matches[0]) == 0:
        say("Summarizing data in clipboard.",
            more=False,
            speak=setting("SPEAK"),
            moodUpdate=False,
            PAUSE_SEND=True)

        CLIPBOARD = k.loadClipboard()

        #k.summary(CLIPBOARD, SEN_NUM=3, TYPE="short", CHRON=True)
        top5 = k.importantSentences(CLIPBOARD, SEN_NUM=5, CHRON=True)
        top5 = [sen[0] for sen in top5]
        topTrimmed = []

        lenSum = 0
        for sen in top5:
            if lenSum < 75:  # max words
                topTrimmed.append(sen)
                lenSum += len(sen.split())
            else:
                break

        topStr = ' '.join(topTrimmed)

        #print top3Str
        tkHistCat(topStr + '\n')

        #k.summary(k.loadClipboard())

        # now update the context
        if len(CLIPBOARD[0]) != 0:
            Freqs = k.getWordFreqs(k.filter(CLIPBOARD, lemmatize=True))
            if len(Freqs) != 0:
                #print "new context: ", Freqs[0][0]
                updateContext(inStr=Freqs[0][0])

        return True

    if len(matches[0]) == 0:
        say(getResponse(findCMD("rephrase")),
            more=False,
            speak=setting("SPEAK"),
            moodUpdate=False)
        return False

    # now figure out query type
    if ("in common" in inStr or "similar" in inStr):
        if len(matches[0]) != 2:
            say("I was expecting two terms to compare.",
                more=False,
                speak=setting("SPEAK"))
            return False
        # get the word frequency intersection and return top few words

        timedOut = False
        try:
            A1, A2 = k.learn(matches[0][0]), k.learn(matches[0][1])
        except TimedOutExc:
            say("Unable to get data from Wikipedia.",
                more=False,
                speak=setting("SPEAK"))
            timedOut = True
            return True
            pass

        if len(A1) <= 2 and not timedOut:
            #say("Wikipedia article "+matches[0][0]+" not found.", more=True, speak=setting("SPEAK"))
            #sys.stdout.flush()
            return False
        if len(A2) <= 2 and not timedOut:
            #say("Wikipedia article "+matches[0][1]+" not found.", more=True, speak=setting("SPEAK"))
            #sys.stdout.flush()
            return False

        # say something like "let me think about this"
        say(getResponse(inCmd),
            more=False,
            speak=setting("SPEAK"),
            PAUSE_SEND=True)

        # get the top 3
        top3Str = ', '.join([c[0] for c in k.wordIntersection(A1, A2)[0:3]])
        strProcessed = processResponse(
            "Things #0# and #1# have in common: #2#.",
            replacements=[matches[0][0], matches[0][1], top3Str])
        say(strProcessed, more=False, speak=setting("SPEAK"))
        return True

    if ("tell me about" in inStr) or ("know about" in inStr) or (
            "teach me" in inStr) or ("learn about" in inStr):

        #print "inSTR = ", inStr
        retVal = False
        for topic in matches[0]:  # already checked to be non-zero

            timedOut = False
            try:
                A = k.learn(topic)
                #if setting('DEBUG'):
                #print A
            except:  # TimedOutExc:
                say("Unable to get data from Wikipedia.",
                    more=False,
                    speak=setting("SPEAK"))
                timedOut = True
                pass
                return True

            if len(A) <= 2 and not timedOut:
                #say("Wikipedia article "+topic+" not found.", more=False, speak=setting("SPEAK"))
                retVal = False
            else:
                say(getResponse(inCmd),
                    more=False,
                    speak=setting("SPEAK"),
                    PAUSE_SEND=True)
                # get top 3 sentences on topic
                top2 = k.importantSentences(A, SEN_NUM=2, CHRON=True)
                topStrs = [sen[0] for sen in top2]
                strProcessed = processResponse(
                    "Let me tell you about \"#0#\": \n\t- #1# #2#",
                    replacements=[topic, topStrs[0], topStrs[1]])
                say(strProcessed, more=False, speak=setting("SPEAK"))
                retVal = True
        return retVal

    if "word web" in inStr:
        if len(matches[0]) != 1:
            say("I was expecting only one term in \"\"'s.",
                more=False,
                speak=setting("SPEAK"))
            return False

        say(getResponse(inCmd),
            more=False,
            speak=setting("SPEAK"),
            PAUSE_SEND=True)

        try:
            A = k.learn(matches[0][0])
        except TimedOutExc:
            say("Unable to get data from Wikipedia.",
                more=False,
                speak=setting("SPEAK"))
            pass
            return True

        except:
            pass
            return True

        if len(A) <= 2:
            say("Wikipedia article " + matches[0][0] + " not found.",
                more=False,
                speak=setting("SPEAK"))
            return False
        else:
            k.wordWeb(A)
            return True

    if ("draw" in inStr) or ("paint" in inStr) or ("painting" in inStr):
        if len(matches[0]) != 1:
            say("I was expecting only one term.",
                more=False,
                speak=setting("SPEAK"))
            return False
        say(getResponse(inCmd),
            more=False,
            speak=setting("SPEAK"),
            PAUSE_SEND=True)
        #print "word:"+qWords[0]
        try:
            k.paintImage(k.learn(matches[0][0]))
            return True
        except TimedOutExc:
            say("Unable to get data from Wikipedia.",
                more=False,
                speak=setting("SPEAK"))
            pass

        return False

    return False
Ejemplo n.º 4
0
def KTInterface(inCmd, inStr, matches=[[],[]]):
	#print "KTI"
	from determineFunction import refineMatches, updateContext

	inStr = inStr.replace('\"', '').replace('\'','')

	#matches = refineMatches(inCmd, inStr)

	matches = substituteBiographicMemory(matches, queryType='what is')

	inStr = inStr.lower()

	setFace(face="thinking_animation")

	# check if summarizing clipboard
	if "clipboard" in inStr and len(matches[0]) == 0:
		say("Summarizing data in clipboard.", more=False, speak=setting("SPEAK"), moodUpdate=False, PAUSE_SEND=True)

		CLIPBOARD = k.loadClipboard()

		#k.summary(CLIPBOARD, SEN_NUM=3, TYPE="short", CHRON=True)
		top5=k.importantSentences(CLIPBOARD, SEN_NUM=5, CHRON=True)
		top5 = [sen[0] for sen in top5]
		topTrimmed = []

		lenSum = 0
		for sen in top5:
			if lenSum < 75: # max words
				topTrimmed.append(sen)
				lenSum += len(sen.split())
			else:
				break

		topStr = ' '.join(topTrimmed)

		#print top3Str
		tkHistCat(topStr+'\n')

		#k.summary(k.loadClipboard())

		# now update the context
		if len(CLIPBOARD[0]) != 0:
			Freqs = k.getWordFreqs(k.filter(CLIPBOARD, lemmatize=True))
			if len(Freqs) != 0: 
				#print "new context: ", Freqs[0][0]
				updateContext(inStr=Freqs[0][0])

		return True

	
	if len(matches[0]) == 0:
		say(getResponse(findCMD("rephrase")), more=False, speak=setting("SPEAK"), moodUpdate=False)
		return False

	# now figure out query type
	if ("in common" in inStr or "similar" in inStr):
		if len(matches[0]) != 2:
			say("I was expecting two terms to compare.", more=False, speak=setting("SPEAK"))
			return False
		# get the word frequency intersection and return top few words

		timedOut=False
		try:
			A1, A2 = k.learn(matches[0][0]), k.learn(matches[0][1])
		except TimedOutExc:
			say("Unable to get data from Wikipedia.", more=False, speak=setting("SPEAK"))
			timedOut = True
			return True
			pass
		

		if len(A1) <= 2 and not timedOut:
			#say("Wikipedia article "+matches[0][0]+" not found.", more=True, speak=setting("SPEAK"))
			#sys.stdout.flush()
			return False
		if len(A2) <= 2 and not timedOut:
			#say("Wikipedia article "+matches[0][1]+" not found.", more=True, speak=setting("SPEAK"))
			#sys.stdout.flush()
			return False

		# say something like "let me think about this"
		say(getResponse(inCmd), more=False, speak=setting("SPEAK"), PAUSE_SEND=True)


		# get the top 3
		top3Str=', '.join([c[0] for c in k.wordIntersection(A1, A2)[0:3]])
		strProcessed=processResponse("Things #0# and #1# have in common: #2#.", replacements=[matches[0][0], matches[0][1], top3Str])
		say(strProcessed, more=False, speak=setting("SPEAK"))
		return True

	if ("tell me about" in inStr) or ("know about" in inStr) or ("teach me" in inStr) or ("learn about" in inStr):

		#print "inSTR = ", inStr
		retVal = False
		for topic in matches[0]: # already checked to be non-zero

			timedOut = False
			try:
				A = k.learn(topic)
				#if setting('DEBUG'):
					#print A
			except:# TimedOutExc:
				say("Unable to get data from Wikipedia.", more=False, speak=setting("SPEAK"))
				timedOut = True
				pass
				return True

			if len(A)<=2 and not timedOut:
				#say("Wikipedia article "+topic+" not found.", more=False, speak=setting("SPEAK"))
				retVal = False
			else:	
				say(getResponse(inCmd), more=False, speak=setting("SPEAK"), PAUSE_SEND=True)
				# get top 3 sentences on topic
				top2=k.importantSentences(A, SEN_NUM=2, CHRON=True)
				topStrs=[sen[0] for sen in top2]
				strProcessed=processResponse("Let me tell you about \"#0#\": \n\t- #1# #2#", replacements=[topic, topStrs[0], topStrs[1]])
				say(strProcessed, more=False, speak=setting("SPEAK"))
				retVal = True
		return retVal

	if "word web" in inStr:
		if len(matches[0]) != 1:
			say("I was expecting only one term in \"\"'s.", more=False, speak=setting("SPEAK"))
			return False

		say(getResponse(inCmd), more=False, speak=setting("SPEAK"), PAUSE_SEND=True)
		
		try:
			A = k.learn(matches[0][0])
		except TimedOutExc:
			say("Unable to get data from Wikipedia.", more=False, speak=setting("SPEAK"))
			pass
			return True
			
		except:
			pass
			return True
			
		if len(A) <= 2:
			say("Wikipedia article "+matches[0][0]+" not found.", more=False, speak=setting("SPEAK"))
			return False
		else:	
			k.wordWeb(A)
			return True
		
	if ("draw" in inStr) or ("paint" in inStr) or ("painting" in inStr):
		if len(matches[0]) != 1:
			say("I was expecting only one term.", more=False, speak=setting("SPEAK"))
			return False
		say(getResponse(inCmd), more=False, speak=setting("SPEAK"), PAUSE_SEND=True)
		#print "word:"+qWords[0]
		try:
			k.paintImage(k.learn(matches[0][0]))
			return True
		except TimedOutExc:
			say("Unable to get data from Wikipedia.", more=False, speak=setting("SPEAK"))
			pass

		return False

	return False