Update process.py
Browse files- process.py +8 -6
process.py
CHANGED
@@ -8,9 +8,10 @@ import pandas as pd
|
|
8 |
urls = {
|
9 |
'dev1': 'https://home.ttic.edu/~kgimpel/comsense_resources/dev1.txt.gz',
|
10 |
'dev2': 'https://home.ttic.edu/~kgimpel/comsense_resources/dev2.txt.gz',
|
11 |
-
'test': 'https://home.ttic.edu/~kgimpel/comsense_resources/test.txt.gz'
|
|
|
12 |
}
|
13 |
-
|
14 |
|
15 |
|
16 |
def wget(url, cache_dir: str = './cache'):
|
@@ -32,10 +33,10 @@ def wget(url, cache_dir: str = './cache'):
|
|
32 |
|
33 |
def read_file(file_name):
|
34 |
with open(file_name) as f_reader:
|
35 |
-
df = pd.DataFrame([i.split('\t') for i in f_reader.read().split('\n') if len(i) > 0],
|
36 |
-
|
37 |
-
df_positive = df[df['flag']
|
38 |
-
df_negative = df[df['flag'] == '0']
|
39 |
df_positive.pop('flag')
|
40 |
df_negative.pop('flag')
|
41 |
return df_positive, df_negative
|
@@ -45,6 +46,7 @@ if __name__ == '__main__':
|
|
45 |
test_p, test_n = read_file(wget(urls['test']))
|
46 |
dev1_p, dev1_n = read_file(wget(urls['dev1']))
|
47 |
dev2_p, dev2_n = read_file(wget(urls['dev2']))
|
|
|
48 |
|
49 |
with open(f'dataset/test.jsonl', 'w') as f:
|
50 |
for relation, df_p in test_p.groupby('relation'):
|
|
|
8 |
urls = {
|
9 |
'dev1': 'https://home.ttic.edu/~kgimpel/comsense_resources/dev1.txt.gz',
|
10 |
'dev2': 'https://home.ttic.edu/~kgimpel/comsense_resources/dev2.txt.gz',
|
11 |
+
'test': 'https://home.ttic.edu/~kgimpel/comsense_resources/test.txt.gz',
|
12 |
+
'train': "https://home.ttic.edu/~kgimpel/comsense_resources/train600k.txt.gz"
|
13 |
}
|
14 |
+
os.makedirs("dataset", exist_ok=True)
|
15 |
|
16 |
|
17 |
def wget(url, cache_dir: str = './cache'):
|
|
|
33 |
|
34 |
def read_file(file_name):
|
35 |
with open(file_name) as f_reader:
|
36 |
+
df = pd.DataFrame([i.split('\t') for i in f_reader.read().split('\n') if len(i) > 0], columns=['relation', 'head', 'tail', 'flag'])
|
37 |
+
df = df[[not i.startswith("Not") for i in df.relation]]
|
38 |
+
df_positive = df[df['flag'] != '0']
|
39 |
+
df_negative = df[df['flag'] == '0']
|
40 |
df_positive.pop('flag')
|
41 |
df_negative.pop('flag')
|
42 |
return df_positive, df_negative
|
|
|
46 |
test_p, test_n = read_file(wget(urls['test']))
|
47 |
dev1_p, dev1_n = read_file(wget(urls['dev1']))
|
48 |
dev2_p, dev2_n = read_file(wget(urls['dev2']))
|
49 |
+
train_p, _ = read_file(wget(urls['train']))
|
50 |
|
51 |
with open(f'dataset/test.jsonl', 'w') as f:
|
52 |
for relation, df_p in test_p.groupby('relation'):
|