-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_topic.py
111 lines (89 loc) · 4.29 KB
/
create_topic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# python script for creating topics from Kialo debates
# %%
import json
import re
import random
kialo_path = '/Users/ggbetz/Documents/Philosophie/vortraege_paper/2019/Artificial Epistemic Agent/kialo_corpus/raw debates/'
topic = {
'id': 'compulsory_voting',
'claims': {
'connector': 'I more or less agree with what my peers are saying here. And therefore, all in all,',
'pro': [' compulsory voting is a pretty good idea, and I am for compulsory voting.'],
'con': [' compulsory voting is a really bad idea, and I am against compulsory voting.']
},
'intro': 'Let\'s discuss compulsory voting! Should citizens be free to abstain from voting? Or should voting be made compulsory?',
'prompt': 'I more or less agree with what my peers are saying here. Regarding the idea of compulsory voting, I\'d just add the following thought:\n',
'initial_posts': [
{
'type':'pro',
'text':'Turnout in British election is distressingly low. Compulsory voting might fix this problem and increase the legitimacy of our government.'
}
]
}
# %%
templates = [
{
'filename': 'a-society-with-no-gender-would-be-better-16617.txt',
'id': 'society-with-no-gender',
'pro': [' a society without gender is a pretty good idea.', ' there is no need to distinguish between men and women.'],
'con': [' a society without gender is a really bad idea.', ' there are important differences between men and women we should pay attention to.'],
'intro': 'Let\'s discuss a society without gender!',
'prompt': 'I more or less agree with what my peers are saying here. Regarding the idea of a society without gender, I\'d just add the following thought:\n',
},
{
'filename': 'all-drugs-should-be-legalized-7100.txt',
'id': 'all-drugs-should-be-legalized',
'pro': [' legalization of drugs is a pretty good idea.', ' all drugs should be legal.'],
'con': [' legalization of drugs is a really bad idea.', ' drugs should remain illegal.'],
'intro': 'Let\'s discuss legalization of drugs!',
'prompt': 'I more or less agree with what my peers are saying here. Regarding the legalization of drugs, I\'d just add the following thought:\n',
}
]
for template in templates:
new_topic = topic.copy()
new_topic['id'] = template.get('id')
new_topic['claims']['pro'] = template.get('pro')
new_topic['claims']['con'] = template.get('con')
new_topic['intro'] = template.get('intro')
new_topic['prompt'] = template.get('prompt')
new_topic['initial_posts'] = []
with open(kialo_path+template.get('filename')) as f:
content = f.readlines()
content = [x.strip() for x in content]
valence_dict = {
'1.': 'pro'
}
parent_depth = 0
for line in content:
line_split = line.split()
if line.startswith("1.") and line_split[1] in ['Pro:','Con:'] and not line_split[2].startswith('->'):
parent_key = '.'.join(line_split[0].split('.')[:-2])+'.'
parent_val = valence_dict[parent_key]
if line_split[1]=='Pro:':
val = parent_val
else:
val = list({'pro','con'}-{parent_val})[0]
valence_dict[line_split[0]] = val
conclusion = ""
if random.choice([True, False]):
conclusion = random.choice([' So', ' I think', ' I believe', " That's why"]) + random.choice(template.get(val))
text = (
" ".join(line_split[2:]) +
conclusion
)
new_topic['initial_posts'].append({'type':val,'text':text})
# reason_pattern = r"1.(?:[\d|.]* (?:Pro: |Con: ))"
# for line in content:
# rm = re.search(reason_pattern, line)
# if rm!=None:
# if rm.start()==0:
# r = line[rm.end():]
# if not r.startswith('->'):
# r = r.replace('\(','(')
# r = r.replace('\)',')')
# new_topic['initial_posts'].append({'text':r})
with open('topics/'+template.get('filename')[:-4]+'.json', 'w') as outfile:
json.dump(new_topic, outfile,indent=4)
# %%
"1.2.3.".split('.')
# %%