'''bcVerbalAnalysis reads in the stimLists from a subjects session and checks the words against subject provided recall list. this code can be used in memory experiments where a subject is presented with a list of words to remember during a study phase which will then be tested in a recognition phase. after the final test phase a final recall is administered.'''
#bc ┌( ಠ_ಠ)┘
#do the imports
import glob
from itertools import chain
#initialize all sessions study list
allSessionsStudy = []
#set the path for folder containing the study files
#change name of behavior folder to be analyzed (i.e. original stimList)
path = "C:\\Users\\Owner\\...*"
for filename in glob.glob(path):
with open(filename, 'r') as f:
for line in f:
allSessionsStudy.append(line)
#initialize cleaned study list
allSessionsStudyClean = []
#clean words and put in list
for word in allSessionsStudy:
newWord = word[6:-5]
allSessionsStudyClean.append(newWord)
#initialize all sessions test list
allSessionsTest = []
#set the path for folder containing the test files
#change name of behavior folder to be analyzed
path = "C:\\Users\\Owner\\...*"
for filename in glob.glob(path):
with open(filename, 'r') as f:
for line in f:
allSessionsTest.append(line)
#initialize cleaned test list
allSessionsTestClean = []
#clean words and put in list
for word in allSessionsTest:
newWord = word[6:-5]
allSessionsTestClean.append(newWord)
#list for old words
computerOld = []
#list for new words
computerNew = []
for i in allSessionsStudyClean:
computerOld.append(i)
for i in allSessionsTestClean:
if i not in computerOld:
computerNew.append(i)
#create subject list dictionary
#read subject text file into dictionary
#reading the dictionary, generate lists of subject oldCorrect, subjectNewCorrect
#subjectoldWrong and subjectNewWrong, and other.
subjectWords = []
#set the path for folder containing the study files
#change name of behavior folder to be analyzed
path = "C:\\Users\\Owner\\Desktop\canna106\subjectList.txt"
for filename in glob.glob(path):
with open(filename, 'r') as f:
for line in f:
subjectWords.append(line)
#split the words at the comma for the subject provided list
splitWords = []
#split the subject words
for word in subjectWords:
x = word.split(',')
splitWords.append(x)
#turn the list of lists into a single list
singleList = list(chain(*splitWords))
#take the newline character off the end of the list
noLine = []
for i in singleList:
x = i.strip()
noLine.append(x)
#split the noLine list into two parts
#put the elements divided by 2 into first list --> keys
#put the elements not divided by 2 into the second list -- > values
# zip the two lists together as a dictionary that can then be checked against study/test lists
keyList = noLine[::2]
valueList = noLine[1::2]
subjectWords = dict(zip(keyList, valueList))
subjectOldWrong = []
subjectNewWrong = []
subjectOldCorrect = []
subjectNewCorrect = []
other = []
#iterate through the dictionary checking each value against original study/test lists
for key, value in subjectWords.items():
if key in computerOld and value == 'old':
subjectOldCorrect.append(key)
elif key in computerNew and value == 'old':
subjectOldWrong.append(key)
elif key in computerOld and value == 'new':
subjectNewWrong.append(key)
elif key in computerNew and value == 'new':
subjectNewCorrect.append(key)
else:
other.append(key)
#get subject accuracy --> TODO put in other stats
#total words
totalWords = ((len(subjectOldWrong) + (len(subjectNewWrong)) + (len(subjectOldCorrect)) + (len(subjectNewCorrect)) + (len(other))))
#percent wrong
percentWrong = (((len(subjectOldWrong) + (len(subjectNewWrong))) + (len(other))) / totalWords * 100)
#percent correct
percentCorrect = (((len(subjectOldCorrect)) + (len(subjectNewCorrect))) / totalWords * 100)
print("Subject Word Categorization: ")
print("Subject said old but new: ")
print(subjectOldWrong)
print("Subject said new but old: ")
print(subjectNewWrong)
print("Subject correct old recall: ")
print(subjectOldCorrect)
print("Subject correct new recall: ")
print(subjectNewCorrect)
print("Words not included in session list: ")
print(other)
print("Word Stats: ")
print("Total Subject Recalled Words: ")
print(totalWords)
print("Total Percentage of Wrong Words: ")
print(percentWrong)
print("Total Percentage of Correct Words: ")
print(percentCorrect)