Example #1
0
def addAutobiographicMemory(threshold = 1.5):
	# memory:
	#	- time tag
	#	- delta mood vector
	#	- context
	#	- recent cmd hist

	new_mem = {}

	memLen = 3

	# check that memory is of sufficient emotional magnitude
	# deltaM12 = delta mood

	cNum = len(GLOB['CMDHIST'])
	
	if cNum < memLen:
		return False
	
	oldMood = GLOB['CMDHIST'][cNum-2][3]
	newMood = GLOB['CMDHIST'][cNum-1][3]

	deltaMood = [round(newMood[i] - oldMood[i], 2) for i in range(GLOB['MOODDIM'])]
	maxDelta = max([abs(item) for item in deltaMood])
	memoryWeight = sum([abs(item) for item in deltaMood])

		


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

	new_mem['deltaMood'] = deltaMood
	#new_mem['mood'] = GLOB['CMDHIST'][cNum-1][3]
	new_mem['weight'] =round(memoryWeight, 3)
	new_mem['time'] = NowTotalSecs
	new_mem['context'] = GLOB['CONTEXT']
	# get the last memLen commands: [old, .. , new]
	new_mem['recentHist'] = [GLOB['CMDHIST'][cNum-1-i][1] for i in range(memLen-1, -1, -1)]
	new_mem['novelty'] = round(getMemoryNovelty(new_mem), 3)

	new_mem['title'] = getMemoryTitle(new_mem)

	new_mem['count_recalled'] = 0
	new_mem['count_happened'] = 0

	#print "weight, maxDelta, novelty = ", memoryWeight, maxDelta, new_mem['novelty']

	if new_mem['novelty'] >= threshold and (new_mem['weight'] >= 1.5 or maxDelta >= 0.5):

		GLOB['AUTOBIOGRAPHIC_MEMORY'].append(new_mem)

		jsonSave(GLOB['AUTOBIOGRAPHIC_MEMORY'], DATA_DIR+'autobiographic_memory.txt')

		playMemSound(new_mem)

		return True
	else:
		return False
Example #2
0
	def saveData(self, event=[]):
		#print "saving..."
		pixelX=self.root.winfo_width()
		pixelY=self.root.winfo_height()

		oX = self.root.winfo_rootx()
		oY = self.root.winfo_rooty()
		data = {}
		data['root_geometry'] = self.root.winfo_geometry() #[pixelX, pixelY, oX, oY]

		#"1097x499+94+212"


		data['thoughts'] = []

		data['zoom'] = self.curZoom

		for t in self.thoughts:
	
			tData={}
			#tData['index'] = t.index
			tData['pixLoc'] = t.pixLoc
			tData['radius'] = t.r
			tData['text'] = t.getText()
			tData['fontSize'] = t.fontSize

			data['thoughts'].append(tData)


		data['links'] = []
		for l in self.links:
	
			lData={}
			#need to add 1 since index assignments for thoughts starts at 1
			#   instead of 0
			lData['tA'] = self.thoughts.index(l.tA)+1
			lData['tB'] = self.thoughts.index(l.tB)+1
			lData['importance'] = l.importance


			data['links'].append(lData)

			#l.grow()

	
		fileIO.jsonSave(data=data, fileName=self.fileName, indent=True, sort=False, oneLine=False)
		

		self.pulse()

		return
Example #3
0
def rememberMemory(mem, confidence, memType):
    from emotions import ingest

    if mem == {} or memType == "":
        return

    if (confidence < 0.4 and memType == "remember"):
        return False
    elif (confidence < 0.6 and memType == "predict"):
        return False

    playMemSound(mem)

    importance = memoryImportance(mem, confidence)

    # UPDATE MEMORY DETAILS
    memIndex = GLOB['AUTOBIOGRAPHIC_MEMORY'].index(mem)
    GLOB['AUTOBIOGRAPHIC_MEMORY'][memIndex]['count_recalled'] += 1

    if confidence >= 0.95 and memType == "remember":
        GLOB['AUTOBIOGRAPHIC_MEMORY'][memIndex]['count_happened'] += 1

    jsonSave(GLOB['AUTOBIOGRAPHIC_MEMORY'],
             DATA_DIR + 'autobiographic_memory.txt')

    # decide if we're going to act on the memory
    # count_recalled
    # count_happened
    # -> if the memory is often recalled but never happens and weight is low
    #    then we don't act on it

    if memoryImportance(mem, confidence) < 0.5:
        #	print "IMPORTANCE = ", importance
        return False

    #sayStr = "*I "+getMemoryStr(mem, confidence, memType)+' %s'%round(importance, 2)+'.*'
    #sayStr += ' '+mem['title']

    sayStr = "*I " + getMemoryStr(mem, confidence, memType) + '.*'
    say(sayStr, more=False, speak=setting("SPEAK"), location="top")

    if sum(mem['deltaMood']) >= 0:
        memoryAnimation(mood="positive")
    else:
        memoryAnimation(mood="negative")

    memMood = [m[0] + m[1] for m in zip(GLOB['MOOD'], mem['deltaMood'])]
    memMood = [max(min(memMood[i], 1), -1) for i in range(GLOB['MOODDIM'])]

    # weight of each facet of memory is equal to the magnitude of the
    #   emotion change in that memory
    memWeight = [abs(m) * confidence for m in mem['deltaMood']]

    if memType == "predict":
        memWeight = [m * 0.25 for m in memWeight]

    # add memory effects to mood
    ingest(inCmd=[],
           inStr=mem['title'],
           mood=memMood,
           weight=memWeight,
           isMem=True)

    return True
Example #4
0
def addAutobiographicMemory(threshold=1.5):
    # memory:
    #	- time tag
    #	- delta mood vector
    #	- context
    #	- recent cmd hist

    new_mem = {}

    memLen = 3

    # check that memory is of sufficient emotional magnitude
    # deltaM12 = delta mood

    cNum = len(GLOB['CMDHIST'])

    if cNum < memLen:
        return False

    oldMood = GLOB['CMDHIST'][cNum - 2][3]
    newMood = GLOB['CMDHIST'][cNum - 1][3]

    deltaMood = [
        round(newMood[i] - oldMood[i], 2) for i in range(GLOB['MOODDIM'])
    ]
    maxDelta = max([abs(item) for item in deltaMood])
    memoryWeight = sum([abs(item) for item in deltaMood])

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

    new_mem['deltaMood'] = deltaMood
    #new_mem['mood'] = GLOB['CMDHIST'][cNum-1][3]
    new_mem['weight'] = round(memoryWeight, 3)
    new_mem['time'] = NowTotalSecs
    new_mem['context'] = GLOB['CONTEXT']
    # get the last memLen commands: [old, .. , new]
    new_mem['recentHist'] = [
        GLOB['CMDHIST'][cNum - 1 - i][1] for i in range(memLen - 1, -1, -1)
    ]
    new_mem['novelty'] = round(getMemoryNovelty(new_mem), 3)

    new_mem['title'] = getMemoryTitle(new_mem)

    new_mem['count_recalled'] = 0
    new_mem['count_happened'] = 0

    #print "weight, maxDelta, novelty = ", memoryWeight, maxDelta, new_mem['novelty']

    if new_mem['novelty'] >= threshold and (new_mem['weight'] >= 1.5
                                            or maxDelta >= 0.5):

        GLOB['AUTOBIOGRAPHIC_MEMORY'].append(new_mem)

        jsonSave(GLOB['AUTOBIOGRAPHIC_MEMORY'],
                 DATA_DIR + 'autobiographic_memory.txt')

        playMemSound(new_mem)

        return True
    else:
        return False
Example #5
0
def rememberMemory(mem, confidence, memType):
	from emotions import ingest

	if mem=={} or memType=="":
		return

	if (confidence < 0.4 and memType == "remember"):
		return False
	elif (confidence < 0.6 and memType == "predict"):
		return False


	playMemSound(mem)

	importance = memoryImportance(mem, confidence)

	# UPDATE MEMORY DETAILS
	memIndex = GLOB['AUTOBIOGRAPHIC_MEMORY'].index(mem)
	GLOB['AUTOBIOGRAPHIC_MEMORY'][memIndex]['count_recalled'] += 1

	if confidence >= 0.95 and memType == "remember":
		GLOB['AUTOBIOGRAPHIC_MEMORY'][memIndex]['count_happened'] += 1

	jsonSave(GLOB['AUTOBIOGRAPHIC_MEMORY'], DATA_DIR+'autobiographic_memory.txt')


	# decide if we're going to act on the memory
	# count_recalled
	# count_happened
	# -> if the memory is often recalled but never happens and weight is low
	#    then we don't act on it
	
	if memoryImportance(mem, confidence) < 0.5:
	#	print "IMPORTANCE = ", importance
		return False

	#sayStr = "*I "+getMemoryStr(mem, confidence, memType)+' %s'%round(importance, 2)+'.*'
	#sayStr += ' '+mem['title']
	
	sayStr = "*I "+getMemoryStr(mem, confidence, memType)+'.*'
	say(sayStr, more=False, speak=setting("SPEAK"), location="top")

	if sum(mem['deltaMood']) >= 0:
		memoryAnimation(mood="positive")
	else:
		memoryAnimation(mood="negative")

	memMood=[m[0]+m[1] for m in zip(GLOB['MOOD'], mem['deltaMood'])]
	memMood = [max(min(memMood[i], 1), -1) for i in range(GLOB['MOODDIM'])]



	# weight of each facet of memory is equal to the magnitude of the
	#   emotion change in that memory
	memWeight = [abs(m)*confidence for m in mem['deltaMood']]

	if memType == "predict":
		memWeight = [m*0.25 for m in memWeight]

	# add memory effects to mood
	ingest(inCmd=[], inStr=mem['title'], mood=memMood, weight=memWeight, isMem=True)

	return True
Example #6
0
def handleInput(inStr, factList, factFileName, getContext=False, queries=True, save=False):
	global W5


	inStr = removeStrange(inStr).strip()
	#print "HANDLING:", inStr

	if "tag:" == inStr.split()[0]:
		tagStr = inStr.lower().replace('tag: ', '')
		retStr = formAnswerString(tagQuery(tag=tagStr, factList=factList))
		return retStr, tagStr, "add"


	topMatches = []
	topWType = []

	topConfidence = 0
	inputType = "add"

	for wK in W5:
		matches_add, confidence_add =     matchFromList(W5[wK]['add'], inStr, trials=10, subTrials=150, includeLenScore=True)
		matches_query, confidence_query = matchFromList(W5[wK]['query'], inStr, trials=10, subTrials=150, includeLenScore=True)

		if DEBUG:
			print "clearlyQuestion:", clearlyQuestion(inStr)
			print matches_add, confidence_add
			print matches_query, confidence_query

		if confidence_add >= topConfidence and not clearlyQuestion(inStr):
			topConfidence = confidence_add

			topMatches = matches_add
			topWType = wK
			inputType = "add"

			#print matches_add, confidence_add

		elif confidence_query > topConfidence:
			topConfidence = confidence_query

			topMatches = matches_query
			topWType = wK
			inputType = "query"

			#print matches_query, confidence_query


	if topMatches == [] or (inputType=="add" and len(topMatches[0]) < 2) or topConfidence < 0.95:
		# no good match found, so return default
		#print "here"
		#print topConfidence
		return "", "", ""


	retStr = ""	
	context=""

	dataChanged = False

	if inputType == "add":
		# ex. what(sub) = prob
		sub = topMatches[0][0]
		prop = topMatches[0][1]

		replaceInfo = "just" in topMatches[1] or "only" in topMatches[1]

		retStr="Adding to factual memory:\n"+'['+topWType+']'+'('+sub+') = '+prop
		
		fact = [sub, topWType, prop] # ex. ["apples", "what who", "red"]
		addToFacts(factList, fact, replaceInfo=replaceInfo)

		dataChanged = True
		context = prop

	elif inputType == "query" and queries:

		answers=queryFacts(factList=factList, query=inStr, qType=topWType, matches=topMatches, minScore=0.3)

		#print "ANSWERS:", answers
		retStr = formAnswerString(answers)#, qType=topWType)

		if len(answers[0]) != 0:
			context = answers[0][2]


	if save and dataChanged:
		jsonSave(factList, factFileName)


	return retStr, context, inputType
Example #7
0
	W5 = jsonLoad('w5_4.txt')

	factList = jsonLoad(factFileName)

	DEBUG =True

	inStr = ""

	while inStr != "exit":

		sys.stdout.write('>> ')
		inStr = raw_input("")

		print handleInput(inStr=inStr, factList=factList, factFileName=factFileName, save=True)

	jsonSave(factList, factFileName)


	'''
	file = open('raw_text.txt')
	t=file.read()
	TB = TextBlob(t)
	TS = [item.raw for item in TB.sentences]

	for i in range(len(TS)):
		s = TS[i]
		print i+1, "/", len(TS)
		handleInput(inStr=s, factList=factList, factFileName=factFileName)

		if i >= 50: break