Esempio n. 1
0
def variabilityFactor():
    from common import wordSim

    #global CMDHIST
    CMDHIST = GLOB['CMDHIST']
    ''' CALCULATE COMMAND VARIABILITY '''
    varSum = 0
    mSize = 0
    vWeightSum = 0
    for i in range(min(5, len(CMDHIST)) - 0):
        str1, str2 = CMDHIST[len(CMDHIST) - i - 1][1], CMDHIST[len(CMDHIST) -
                                                               i - 2][1]
        vWeight = pow(2.0, -1.0 * i)
        vWeightSum += vWeight
        mSize += 1
        varSum += wordSim(str1, str2) * vWeight

    # 0: no variability, 1: lots of variability
    var = 0.5 if mSize <= 1 else 1.0 - varSum / (vWeightSum
                                                 )  # when m = 1, str2=str1

    # variability factor: when commands are repetative, you get bored
    #	- when the user is away however, it becomes less important
    variability = 2.0 * (var - 0.5)  # rescale it to [-1, 1]
    return variability
Esempio n. 2
0
def variabilityFactor():
	from common import wordSim

	#global CMDHIST
	CMDHIST = GLOB['CMDHIST']
	''' CALCULATE COMMAND VARIABILITY '''
	varSum=0
	mSize=0
	vWeightSum=0
	for i in range(min(5, len(CMDHIST))-0):
		str1, str2=CMDHIST[len(CMDHIST)-i-1][1], CMDHIST[len(CMDHIST)-i-2][1]
		vWeight= pow(2.0, -1.0*i)
		vWeightSum += vWeight
		mSize += 1
		varSum += wordSim(str1, str2) * vWeight

	# 0: no variability, 1: lots of variability
	var = 0.5 if mSize<=1 else 1.0-varSum/(vWeightSum) # when m = 1, str2=str1

	# variability factor: when commands are repetative, you get bored
	#	- when the user is away however, it becomes less important
	variability = 2.0*(var - 0.5) # rescale it to [-1, 1]
	return variability
Esempio n. 3
0
def ingest(inCmd,
           inStr,
           mood=[],
           weight=[],
           isCmd=False,
           isMem=False,
           matches=[[], []]):
    from common import wordSim, processResponse, getResponse, say
    #from loadFile import load
    from determineFunction import findCMD, refineMatches
    from Fermi import substituteBiographicMemory

    if not (isCmd or isMem):
        matches = refineMatches(inCmd, inStr)
        matches = substituteBiographicMemory(matches, queryType='what is')

    if len(matches[0]) == 0 and not (isCmd or isMem):
        say(getResponse(findCMD("rephrase")),
            more=False,
            speak=setting("SPEAK"),
            moodUpdate=True)
        return False
    '''
	Algorithm:
		- load substance from list
		- record ingestion time
		- append to INGESTED list

	'''

    if isCmd:
        ingestionTime = time.time()

        taskProfile = "pow(2.0, -1.0*T*T/(900.0*900.0))"  # ~15 minute half life

        taskDetails = [[inCmd[0]], mood, weight, taskProfile]
        #print "appending: ", taskDetails

        GLOB['INGESTED'].append([taskDetails, ingestionTime, "COMMAND"])
        GLOB['MOOD'] = updateMood(GLOB['MOOD'], weight=[0] * GLOB['MOODDIM'])

        #print "AFTER CMD ADD"
        #print GLOB['MOOD']

        return  # no return value if adding a cmd mood modifier

    if isMem:
        #print "ADDING MEMORY MOOD"

        ingestionTime = time.time()

        memProfile = "pow(2.0, -1.0*T*T/(900.0*900.0))"  # ~15 minute half life

        memDetails = [[inStr], mood, weight, memProfile]
        #print "appending: ", taskDetails

        GLOB['INGESTED'].append([memDetails, ingestionTime, "MEMORY"])
        GLOB['MOOD'] = updateMood(GLOB['MOOD'], weight=[0] * GLOB['MOODDIM'])

        #print "AFTER CMD ADD"
        #print GLOB['MOOD']

        return  # no return value if adding a cmd mood modifier

    substances = load(SETS_DIR + "substances.txt", LPC=5)
    # line 0: name(s)
    # line 1: effect
    # line 2: weight
    # line 3: profile equations
    # line 4: response formats
    '''
	for matchStr in inCmd[1]:
		matchStr= matchStr.replace('juice','')
		inStr = inStr.replace(matchStr, '')
	'''

    # find top match

    maxMatch = 0
    topSubstance = []
    for substance in substances:
        for matchPhrase in substance[0]:
            matchScore = wordSim(matches[0][0], matchPhrase, useInScore=True)
            #print matchPhrase, inStr, matchScore
            if matchScore >= maxMatch:
                maxMatch = matchScore
                topSubstance = substance

    if setting('DEBUG'):
        print "INGESTION SCORE:", topSubstance[0], " - ", maxMatch

    # topSubstance[4]:

    #replacements = [topSubstance[0][randint(0,len(topSubstance[0])-1)]]
    replacements = topSubstance[0][randint(0,
                                           len(topSubstance[0]) -
                                           1)]  #matches[0][0] #
    #rStr = processResponse(getResponse(inCmd), replacements)
    responseForm = topSubstance[4][randint(0, len(topSubstance[4]) - 1)]
    rStr = processResponse(responseForm, [replacements])

    say(rStr, more=False, speak=setting("SPEAK"))

    # now modify mood accordingly
    ingestionTime = time.time()

    #print "appending: ", topSubstance

    GLOB['INGESTED'].append([topSubstance, ingestionTime, "SUBSTANCE"])

    #print "BEFORE UPDATE"
    #print GLOB['MOOD']

    GLOB['MOOD'] = updateMood(GLOB['MOOD'], weight=[0] * GLOB['MOODDIM'])

    #print "AFTER SUBSTANCE ADD"
    #print GLOB['MOOD']

    return [topSubstance[0][0], True]
Esempio n. 4
0
def ingest(inCmd, inStr, mood=[], weight=[], isCmd=False, isMem=False, matches=[[],[]]):
	from common import wordSim, processResponse, getResponse, say
	#from loadFile import load
	from determineFunction import findCMD, refineMatches
	from Fermi import substituteBiographicMemory

	if not (isCmd or isMem):
		matches = refineMatches(inCmd, inStr)
		matches = substituteBiographicMemory(matches, queryType='what is')

	if len(matches[0]) ==0 and not (isCmd or isMem):
		say(getResponse(findCMD("rephrase")), more=False, speak=setting("SPEAK"), moodUpdate=True)
		return False

	'''
	Algorithm:
		- load substance from list
		- record ingestion time
		- append to INGESTED list

	'''

	if isCmd:
		ingestionTime = time.time()
		
		taskProfile="pow(2.0, -1.0*T*T/(900.0*900.0))" # ~15 minute half life
		
		taskDetails = [[inCmd[0]], mood, weight, taskProfile]
		#print "appending: ", taskDetails

		GLOB['INGESTED'].append([taskDetails, ingestionTime, "COMMAND"])
		GLOB['MOOD']=updateMood(GLOB['MOOD'], weight=[0]*GLOB['MOODDIM'])
		
		#print "AFTER CMD ADD"
		#print GLOB['MOOD']

		return # no return value if adding a cmd mood modifier

	if isMem:
		#print "ADDING MEMORY MOOD"

		ingestionTime = time.time()
		
		memProfile="pow(2.0, -1.0*T*T/(900.0*900.0))" # ~15 minute half life
		


		memDetails = [[inStr], mood, weight, memProfile]
		#print "appending: ", taskDetails

		GLOB['INGESTED'].append([memDetails, ingestionTime, "MEMORY"])
		GLOB['MOOD']=updateMood(GLOB['MOOD'], weight=[0]*GLOB['MOODDIM'])
		
		#print "AFTER CMD ADD"
		#print GLOB['MOOD']

		return # no return value if adding a cmd mood modifier




	substances = load(SETS_DIR+"substances.txt", LPC=5)
	# line 0: name(s)
	# line 1: effect
	# line 2: weight
	# line 3: profile equations
	# line 4: response formats

	'''
	for matchStr in inCmd[1]:
		matchStr= matchStr.replace('juice','')
		inStr = inStr.replace(matchStr, '')
	'''

	# find top match

	maxMatch=0
	topSubstance=[]
	for substance in substances:
		for matchPhrase in substance[0]:
			matchScore = wordSim(matches[0][0], matchPhrase, useInScore=True)
			#print matchPhrase, inStr, matchScore
			if matchScore >= maxMatch:
				maxMatch = matchScore
				topSubstance = substance

	if setting('DEBUG'):
		print "INGESTION SCORE:", topSubstance[0], " - ", maxMatch

	# topSubstance[4]: 

	#replacements = [topSubstance[0][randint(0,len(topSubstance[0])-1)]]
	replacements = topSubstance[0][randint(0,len(topSubstance[0])-1)] #matches[0][0] #
	#rStr = processResponse(getResponse(inCmd), replacements)
	responseForm = topSubstance[4][randint(0,len(topSubstance[4])-1)]
	rStr = processResponse(responseForm, [replacements])
	
	say(rStr, more=False, speak=setting("SPEAK"))



	# now modify mood accordingly
	ingestionTime = time.time()

	#print "appending: ", topSubstance



	GLOB['INGESTED'].append([topSubstance, ingestionTime, "SUBSTANCE"])


	#print "BEFORE UPDATE"
	#print GLOB['MOOD']

	GLOB['MOOD']=updateMood(GLOB['MOOD'], weight=[0]*GLOB['MOODDIM'])

	#print "AFTER SUBSTANCE ADD"
	#print GLOB['MOOD']

	return [topSubstance[0][0], True]