-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneratePredicateDefinition.py
35 lines (25 loc) · 1.17 KB
/
generatePredicateDefinition.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
# Read CSV File
import csv
import json
def createPredicateDefinitions():
# Open the CSV
f = open('Data/PredicateMap.csv', 'r', encoding='utf-8')
fields = ['genre', 'platform', 'gameModes', 'inputDevice']
fieldName = {"genre": "Genre", "platform": "Platform", "gameModes": "GameMode", "inputDevice": "InputDevice"}
#baseString = f"(isa {predicateType} {predicateName})"
# For each entry in CSV file, read each row and build a string
for row in f:
try:
t,n = row.split(",")
#remove all punctuation and spaces from n
n = n.strip().replace(':','').replace(';','_').replace("'",'').replace('/','_').replace('-','_').replace('_','').replace(' ','')
# find if the t begins with any of the fields
for field in fields:
if t.startswith(field):
#print(f" ( isa {fieldName[field]} {field}_{n} ) ")
# write to a file
with open('Data/generatePredications.krf', 'a') as file:
file.write(f" ( isa {fieldName[field]} {field}_{n} ) \n")
except:
pass
createPredicateDefinitions()