-
Notifications
You must be signed in to change notification settings - Fork 1
/
logical_equivalence_synthetic_testset.py
219 lines (193 loc) · 8.79 KB
/
logical_equivalence_synthetic_testset.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import pandas as pd
import random
from nltk.corpus import wordnet
from itertools import combinations, permutations
data = []
df_output = pd.DataFrame(data,columns=['ID','Sentence1','Sentence2', 'Label', 'Tag'])
subject_list = ['the bald eagle', 'the tiger', 'the bear', 'the lion', 'the wolf', 'the crocodile', 'the dinosaur', 'the snake', 'the leopard',
'the cat', 'the dog', 'the mouse', 'the rabbit', 'the squirrel',
'Anne', 'Alan', 'Bob', 'Charlie', 'Dave', 'Erin', 'Harry', 'Gary', 'Fiona']
verb_list = ['is']
adjective_list = ['kind', 'quiet', 'round', 'nice', 'smart', 'clever',
'dull', 'rough', 'lazy', 'slow', 'sleepy', 'boring', 'tired', 'reckless',
'furry', 'small', 'cute', 'lovely', 'beautiful', 'funny',
'big', 'strong', 'awful', 'fierce', 'heavy', 'horrible', 'powerful', 'angry',
'high', 'huge',
'short', 'thin', 'little', 'tiny',
'wealthy', 'poor', 'dull', 'rough', 'bad', 'sad']
def double_negation(df_output, id, sub, verb, adj):
##Logical equivalence example
s1 = sub + " " + verb + " " + adj + "."
syn = wordnet.synsets(adj)[0]
good = wordnet.synset(syn.name())
antonym = good.lemmas()[0].antonyms()
if len(antonym) > 0:
s2 = sub + " " + verb + " not " + antonym[0].name() + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s2,
'Label': 1,
'Tag': "Double Negation"}, ignore_index=True)
s3 = sub + " " + verb + " not " + adj + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s3,
'Label': 0,
'Tag': "Double Negation"}, ignore_index=True)
return df_output
def commutative(df_output, id, sub1, verb1, adj1, sub2, verb2, adj2):
##Logical equivalence example
s1 = sub1 + " " + verb1 + " " + adj1
s2 = sub2 + " " + verb2 + " " + adj2
s3 = sub1 + " " + verb1 + " not " + adj1
concat_sen = s1 + " and " + s2 + "."
concat_sen2 = s2 + " and " + s1 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': concat_sen,
'Sentence2': concat_sen2,
'Label': 1,
'Tag': "Commutative"}, ignore_index=True)
concat_sen3 = s1 + " and " + s3 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': concat_sen,
'Sentence2': concat_sen3,
'Label': 0,
'Tag': "Commutative"}, ignore_index=True)
return df_output
def contraposition(df_output, id, sub1, sub2, verb, adj1, adj2):
##Logical equivalence example
s1 = "If " + sub1 + " " + verb + " " + adj1 + ", then " + sub2 + " " + verb + " " + adj2 + "."
s2 = "If " + sub2 + " " + verb + " not " + adj2 + ", then " + sub1 + " " + verb + " not " + adj1 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s2,
'Label': 1,
'Tag': "Contraposition"}, ignore_index=True)
s3 = "If " + sub1 + " " + verb + " " + adj1 + ", then " + sub2 + " " + verb + " not " + adj2 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s3,
'Label': 0,
'Tag': "Contraposition"}, ignore_index=True)
s1 = "If " + sub1 + " " + verb + " " + adj1 + ", then " + sub2 + " " + verb + " not " + adj2 + "."
s2 = "If " + sub2 + " " + verb + " " + adj2 + ", then " + sub1 + " " + verb + " not " + adj1 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s2,
'Label': 1,
'Tag': "Contraposition"}, ignore_index=True)
s3 = "If " + sub1 + " " + verb + " " + adj1 + ", then " + sub2 + " " + verb + " " + adj2 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s3,
'Label': 0,
'Tag': "Contraposition"}, ignore_index=True)
s1 = "If " + sub1 + " " + verb + " not " + adj1 + ", then " + sub2 + " " + verb + " " + adj2 + "."
s2 = "If " + sub2 + " " + verb + " not " + adj2 + ", then " + sub1 + " " + verb + " " + adj1 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s2,
'Label': 1,
'Tag': "Contraposition"}, ignore_index=True)
s3 = "If " + sub1 + " " + verb + " not " + adj1 + ", then " + sub2 + " " + verb + " not " + adj2 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s3,
'Label': 0,
'Tag': "Contraposition"}, ignore_index=True)
s1 = "If " + sub1 + " " + verb + " not " + adj1 + ", then " + sub2 + " " + verb + " not " + adj2 + "."
s2 = "If " + sub2 + " " + verb + " not " + adj2 + ", then " + sub1 + " " + verb + " not " + adj1 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s2,
'Label': 1,
'Tag': "Contraposition"}, ignore_index=True)
s3 = "If " + sub1 + " " + verb + " not " + adj1 + ", then " + sub2 + " " + verb + " " + adj2 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s3,
'Label': 0,
'Tag': "Contraposition"}, ignore_index=True)
return df_output
def implication(df_output, id, sub1, sub2, verb, adj1, adj2):
##Logical equivalence example
s1 = "If " + sub1 + " " + verb + " " + adj1 + ", then " + sub2 + " " + verb + " " + adj2 + "."
s2 = sub1 + " " + verb + " not " + adj1 + " or " + sub2 + " " + verb + " " + adj2 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s2,
'Label': 1,
'Tag': "Contraposition"}, ignore_index=True)
s3 = sub1 + " " + verb + " not " + adj1 + " or " + sub2 + " " + verb + " not " + adj2 + "."
df_output = df_output.append(
{'ID': id,
'Sentence1': s1,
'Sentence2': s3,
'Label': 0,
'Tag': "Contraposition"}, ignore_index=True)
return df_output
id = 0
for i in range(100):
random_number_1 = random.randint(0, len(subject_list) - 1)
random_number_2 = random.randint(0, len(adjective_list) - 1)
subject_1 = subject_list[random_number_1]
adjective_1 = adjective_list[random_number_1]
df_output = double_negation(df_output, id, subject_1, verb_list[0], adjective_1)
id = id + 1
for i in range(100):
random_number_1 = random.randint(0, len(subject_list) - 1)
random_number_2 = random.randint(0, len(adjective_list) - 1)
subject_1 = subject_list[random_number_1]
adjective_1 = adjective_list[random_number_1]
random_number_3 = random.randint(0, len(subject_list) - 1)
random_number_4 = random.randint(0, len(adjective_list) - 1)
while random_number_3 == random_number_1:
random_number_3 = random.randint(0, len(subject_list) - 1)
while random_number_4 == random_number_2:
random_number_4 = random.randint(0, len(adjective_list) - 1)
subject_3 = subject_list[random_number_3]
adjective_4 = adjective_list[random_number_4]
df_output = commutative(df_output, id, subject_1, verb_list[0], adjective_1, subject_3, verb_list[0], adjective_4)
id = id + 1
for i in range(100):
random_number_1 = random.randint(0, len(subject_list) - 1)
random_number_2 = random.randint(0, len(subject_list) - 1)
while random_number_1 == random_number_2:
random_number_2 = random.randint(0, len(subject_list) - 1)
subject_1 = subject_list[random_number_1]
subject_2 = subject_list[random_number_2]
random_number_1 = random.randint(0, len(adjective_list) - 1)
random_number_2 = random.randint(0, len(adjective_list) - 1)
adjective_1 = adjective_list[random_number_1]
adjective_2 = adjective_list[random_number_2]
## comtraposition logical equivalence/inequivalence
df_output = contraposition(df_output, id, subject_1, subject_2, verb_list[0], adjective_1, adjective_2)
id = id + 1
for i in range(100):
random_number_1 = random.randint(0, len(subject_list) - 1)
random_number_2 = random.randint(0, len(subject_list) - 1)
while random_number_1 == random_number_2:
random_number_2 = random.randint(0, len(subject_list) - 1)
subject_1 = subject_list[random_number_1]
subject_2 = subject_list[random_number_2]
random_number_1 = random.randint(0, len(adjective_list) - 1)
random_number_2 = random.randint(0, len(adjective_list) - 1)
adjective_1 = adjective_list[random_number_1]
adjective_2 = adjective_list[random_number_2]
## comtraposition logical equivalence/inequivalence
df_output = implication(df_output, id, subject_1, subject_2, verb_list[0], adjective_1, adjective_2)
id = id + 1
df_output.to_csv("./synthetic_logical_equivalence_sentence_pair_testset.csv",index = None,encoding = 'utf8')