Update process.py
Browse files- process.py +3 -4
process.py
CHANGED
@@ -74,15 +74,14 @@ def filtering(entry):
|
|
74 |
|
75 |
with open(f"data/t_rex.raw.jsonl") as f:
|
76 |
data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
|
77 |
-
print(f"[raw dataset]: {len(data)}")
|
78 |
data = [i for i in data if filtering(i)]
|
79 |
df = pd.DataFrame(data)
|
80 |
df = df.drop_duplicates()
|
81 |
-
print(f"[entity only] : {len(df)}")
|
82 |
count = df.groupby("predicate")['title'].count()
|
83 |
df = df[[count[p] >= 3 for p in df['predicate']]]
|
84 |
-
print(f"[remove rare predicate] : {len(df)}")
|
85 |
-
# print(f"[entity]: {len(set(df['object'].unique().tolist() + df['subject'].unique().tolist()))}")
|
86 |
|
87 |
with open(f"data/t_rex.filter.jsonl", 'w') as f:
|
88 |
f.write('\n'.join([json.dumps(i.to_dict()) for _, i in df.iterrows()]))
|
|
|
74 |
|
75 |
with open(f"data/t_rex.raw.jsonl") as f:
|
76 |
data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
|
77 |
+
print(f"[raw dataset]: {len(data)} triples, {len(set([i['predicate'] for i in data]))} predicates")
|
78 |
data = [i for i in data if filtering(i)]
|
79 |
df = pd.DataFrame(data)
|
80 |
df = df.drop_duplicates()
|
81 |
+
print(f"[entity only] : {len(df)} triples, {len(df['predicate'].unique())} predicates")
|
82 |
count = df.groupby("predicate")['title'].count()
|
83 |
df = df[[count[p] >= 3 for p in df['predicate']]]
|
84 |
+
print(f"[remove rare predicate] : {len(df)} triples, {len(df['predicate'].unique())} predicates")
|
|
|
85 |
|
86 |
with open(f"data/t_rex.filter.jsonl", 'w') as f:
|
87 |
f.write('\n'.join([json.dumps(i.to_dict()) for _, i in df.iterrows()]))
|