def __init__(self, name='Meta-DecisionTree', commands=[]): """ Initializes the TransitivityInt model. Parameters ---------- name : str Unique name of the model. Will be used throughout the ORCA framework as a means for identifying the model. """ SentimentAnalyzer.initialize() self.parameter = {} self.componentKeys = Keys.person + Keys.task super().__init__(name, ['misinformation'], ['single-choice'], commands)
def __init__(self, name='Fast-Frugal-Tree', commands = []): """ Initializes the TransitivityInt model. Parameters ---------- name : str Unique name of the model. Will be used throughout the ORCA framework as a means for identifying the model. """ SentimentAnalyzer.initialize() self.parameter = {} #self.parameter['thresh'] = 10 self.componentKeys = ['Exciting_Party_Combined', 'Familiarity_Party_Combined', 'Partisanship_Party_Combined','Worrying_Party_Combined','Importance_Party_Combined', 'Partisanship_All_Combined', 'Partisanship_All_Partisan'] super().__init__(name, ['misinformation'], ['single-choice'], commands)
def __init__(self, name='Fast-Frugal-Tree-ZigZag(Z+)', commands=[]): """ Initializes the model. Parameters ---------- name : str Unique name of the model. Will be used throughout the ORCA framework as a means for identifying the model. """ SentimentAnalyzer.initialize() self.parameter = {} #self.parameter['thresh'] = 1 self.fft = None self.lastnode = None self.componentKeys = Keys.person + Keys.task super().__init__(name, ['misinformation'], ['single-choice'], commands)
def toDFFormat(self, trialList): featList = [] for item in trialList: if item.conservatism < 3.5: componentKeys = [a.replace('Party','Democrats') for a in self.componentKeys] if item.conservatism > 3.5: componentKeys = [a.replace('Party','Republicans') for a in self.componentKeys] newPars = [item.birep, item.conservatism, item.gender, #int(item.truthful), item.crt, item.cons, item.accimp] newPars += [item.itemComponents[a] for a in componentKeys] + [SentimentAnalyzer.analysis(item)[a] for a in SentimentAnalyzer.relevant] newPars += [item.panas[a] for a in item.panas.keys()] + [item.media[a] for a in item.media.keys()] featList.append(newPars) compKeys = [a[:3] + a.split('_')[1][:1] + a.split('_')[2][:1] for a in self.componentKeys] media = ['Media1_Some people t','Media1_In presenting','Media3_1_To what ext','Media3_2_To what ext','Media3_3_To what ext','Media3_11_To what ex','Media3_12_To what ex'] panas = ['PANAS_' + str(i) for i in range(1, 21)] cat_columns = ['ct','Gender'] #'truthful'] nr_columns = ['crt', 'cons','AccImp'] + compKeys + SentimentAnalyzer.relevant + panas + media data_columns = ['response'] + cat_columns + nr_columns data = pd.DataFrame(data=featList, columns=data_columns) for col in cat_columns: data[col] = data[col].astype('category') for col in nr_columns: if data[col].dtype != 'float' and data[col].dtype != 'int': print('type error: ' + data[col]) data.loc[data[col] == '?', col] = np.nan data[col] = data[col].astype('float') data['response'] = data['response'].apply(lambda x: True if x==1 else False).astype(bool) return data
def predictS(self, trial): analysis = SentimentAnalyzer.analysis(trial) p = 0 for a in self.relevant: p += analysis[a] * self.parameter[a] #print(p) return 1 if self.thresh < p else 0
def itemsList(source): itemsList = [] linecount = 0 indcount = 0 line1 = True lines = open('/home/hippo/git/news-reasoning/benchmarks/misinformation/' + source + '.csv') ind = {} for line in lines: listLine = line.replace('\r', '').replace('\n', '').split(',') if line1: line1 = False for key in listLine: ind[key] = indcount indcount += 1 continue panasPos = [ 'PANAS_' + str(i) for i in [1, 3, 5, 9, 10, 14, 16, 17, 19] ] panasNeg = [ 'PANAS_' + str(i) for i in [2, 4, 6, 7, 8, 11, 12, 13, 15, 18, 20] ] personfeatures = { 'crt': float(listLine[ind['crt']]), 'conservatism': listLine[ind['conservatism']], 'ct': int(listLine[ind['ct']]), 'education': int(listLine[ind['education']]), 'gender': listLine[ind['gender']], 'accimp': float(listLine[ind['accimp']]), 'panasPos': float(listLine[ind['panasPos']]), 'panasNeg': float(listLine[ind['panasNeg']]), 'reaction_time': float(listLine[ind['reaction_time']]) } taskfeatures = {} os.chdir( "/home/hippo/git/news-reasoning/benchmarks/misinformation/data/study2" ) for modelfile in glob.glob("with*"): no = False for a in ['ecision', 'Pers', 'inear', 'ecommend', 'Tree']: if a in modelfile: no = True if no: continue taskfeatures[modelfile] = float(listLine[ind[modelfile]]) if Keys.person == None: Keys.person = [a for a in personfeatures.keys()] if Keys.task == None: SentimentAnalyzer.initialize() Keys.task = [ a for a in taskfeatures.keys() if 'ikelihood' not in a ] Keys.task += [a for a in SentimentAnalyzer.relevant] linecount += 1 itemsList.append( Item(listLine[ind['id']], listLine[ind['domain']], listLine[ind['task']], listLine[ind['response_type']], listLine[ind['choices']], listLine[ind['trial']], float(listLine[ind['crt']]), bool('T' in listLine[ind['realnews']]), bool('T' in listLine[ind['acc']]), bool('T' in listLine[ind['birep']]), str(listLine[ind['response']]), persFeat=personfeatures, taskFeat=taskfeatures)) return itemsList
def itemsList(source): itemsList = [] linecount = 0 indcount = 0 line1 = True lines = open( '/home/hippo/git/news-reasoning/benchmarks/misinformation/data/' + source + '.csv') ind = {} for line in lines: listLine = line.replace('\r', '').replace('\n', '').split(',') if line1: line1 = False for key in listLine: ind[key] = indcount indcount += 1 continue linecount += 1 if listLine[ind['_accurate']] == '': continue crtresults = [] itemComponents = {} panas = {} media = {} if 'DemRep_C_current' in ind.keys(): if '' == listLine[ind['DemRep_C_current']]: continue conservatism = float(listLine[ind['DemRep_C_current']]) elif 'Conservatism' in ind.keys(): conservatism = float(listLine[ind['Conservatism']]) * 7 / 5 elif 'Conserv' in ind.keys(): try: conservatism = float(listLine[ind['Conserv']]) * 7 / 5 except: continue if '' == conservatism: continue for item in ind.keys(): if item in [ 'Exciting_Democrats_Combined', 'Exciting_Republicans_Combined', 'Familiarity_Democrats_Combined', 'Familiarity_Republicans_Combined', 'Importance_Democrats_Combined', 'Importance_Republicans_Combined', 'Likelihood_Democrats_Combined', 'Likelihood_Republicans_Combined', 'Partisanship_All_Combined', 'Partisanship_All_Partisan', 'Partisanship_Democrats_Combined', 'Partisanship_Republicans_Combined', 'Worrying_Democrats_Combined', 'Worrying_Republicans_Combined' ]: #'Sharing_Democrats_Combined', 'Sharing_Republicans_Combined', itemComponents[item] = float(listLine[ind[item]]) elif 'CRT1' in item or 'CRT3' in item: crtresults.append( float(listLine[ind[item]] in item.split('_')[1].split(':') [1:])) elif 'PANAS' in item and 'Inst' not in item: if listLine[ind[item]] == '': #logstr('One panas error', listLine[ind['id']], item) panas[item.split('_T')[0]] = None continue panas[item.split('_T')[0]] = float(listLine[ind[item]]) elif 'AccImp_How important' in item: accimp = float(listLine[ind[item]]) elif 'Gender_What' in item: gender = float(listLine[ind[item]]) elif 'Sex' == item: try: gender = float(listLine[ind[item]]) except: gender = 'NoInfo' crt = sum(crtresults) / len(crtresults) panasPos = [ 'PANAS_' + str(i) for i in [1, 3, 5, 9, 10, 14, 16, 17, 19] ] panasNeg = [ 'PANAS_' + str(i) for i in [2, 4, 6, 7, 8, 11, 12, 13, 15, 18, 20] ] for a in ['_RT_2_Timing-Last Click', '_RT_accurate', '_A_RT_accurate']: if a not in ind.keys(): continue try: react_time = float(listLine[ind[a]]) except: react_time = 'NoInfo' if react_time == 'NoInfo': continue for a in ['ClintonTrump', 'POTUS2016_Who did yo']: if a not in ind.keys(): continue try: ct = int(listLine[ind[a]]) except: ct = 'NoInfo' print('ct:', listLine[ind[a]]) for a in ['Education', 'Education_What is th']: if a not in ind.keys(): continue try: edu = int(listLine[ind[a]]) except: edu = 'NoInfo' if 'AccImp_How important' not in ind.keys(): accimp = 'NoInfo' personfeatures = { 'crt': float(crt), 'conservatism': conservatism, 'ct': ct, 'education': edu, 'gender': gender, 'accimp': accimp, 'panasPos': sum(panas[a] for a in panasPos if panas[a] != None) if len(panas.keys()) > 0 else 'NoInfo', 'panasNeg': sum(panas[a] for a in panasNeg if panas[a] != None) if len(panas.keys()) > 0 else 'NoInfo', 'reaction_time': react_time } nokeys = [] # for a in personfeatures.keys(): # if personfeatures[a] == 'NoInfo': # nokeys.append(a) # for a in nokeys: # personfeatures.pop(a) taskfeatures = {} for a in itemComponents.keys(): if conservatism >= 3.5: if 'Democrats' in a: continue else: key = a.replace('Republicans', 'Party') elif conservatism <= 3.5: if 'Republicans' in a: continue else: key = a.replace('Democrats', 'Party') taskfeatures[key] = itemComponents[a] if Keys.person == None: Keys.person = [a for a in personfeatures.keys()] if Keys.task == None: SentimentAnalyzer.initialize() Keys.task = [ a for a in taskfeatures.keys() if 'ikelihood' not in a ] Keys.task += [a for a in SentimentAnalyzer.relevant] newItem = Item(listLine[ind['id']], listLine[ind['domain']], listLine[ind['task']], listLine[ind['response_type']], listLine[ind['choices']], listLine[ind['sequence']], float(crt), bool(int(listLine[ind['truthful']])), bool(int(listLine[ind['_accurate']])), bool(int(listLine[ind['binaryResponse']])), str(listLine[ind['response']]), persFeat=personfeatures, taskFeat=taskfeatures) itemsList.append(newItem) return itemsList