-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreatePredicate.py
82 lines (67 loc) · 2.64 KB
/
CreatePredicate.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
import pandas as pd
import requests
import json
from tqdm import tqdm # Import tqdm for the progress bar
def main():
#read csv file
df = pd.read_csv('Data/EnrichedGameEntities_checkpoint_39000.csv')
df = df.drop(columns=["Entities"])
cols = ["video_gameLabel","genre","platform","gameModes","inputDevice"]
genreSet = set()
platformSet = set()
gameModesSet = set()
inputDeviceSet = set()
#print(df.head())
#processing
for index, values in tqdm(df.iterrows(), total=df.shape[0], desc="Fetching Wikidata Details"):
for col in cols:
if col == "video_gameLabel":
continue
#check for empty and None values
if values[col] is not None and values[col] != "[]" and not isinstance(values[col], float):
value = values[col].split("; ")
if col == "genre":
genreSet.update(value)
elif col == "platform":
platformSet.update(value)
elif col == "gameModes":
gameModesSet.update(value)
elif col == "inputDevice":
inputDeviceSet.update(value)
predicatebase = """
(isa <Name> Predicate)
(arity <Name> 1)
(arg1Isa <Name> Place)
"""
predicateMap = {}
givenSet = set()
'''
Civilization V,Q2385,4X; turn-based strategy video game,Microsoft Windows; Linux; macOS,co-op mode; single-player video game; multiplayer video game,mouse; computer keyboard
'''
for col in cols:
with open('Data/Predicates.txt', 'a', encoding='utf-8') as f:
f.write(";;; Predicates defined for Type : %s\n" % col)
if col == "video_gameLabel":
continue
if col == "genre":
givenSet = genreSet
if col == "platform":
givenSet = platformSet
elif col == "gameModes":
givenSet = gameModesSet
elif col == "inputDevice":
givenSet = inputDeviceSet
for element in givenSet:
element_ = element.replace(" ","_")
predicateName = col+"_"+element_
predicate = predicatebase.replace("<Name>",predicateName)
#write predicatemap value to file
with open('Data/Predicates.txt', 'a', encoding='utf-8') as f:
f.write("%s\n" % predicate)
predicateMap[predicateName] = element
#store the predicates in a file
with open('Data/PredicateMap.txt', 'w', encoding='utf-8') as f:
for key,value in predicateMap.items():
f.write("%s,%s\n" % (key,value))
if __name__ == '__main__':
main()