-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSON2RDF.py
53 lines (48 loc) · 1.48 KB
/
JSON2RDF.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
def analyser1(word):
if( word.find(":") == -1 ):
return False
else:
return True
def analyser2(word):
if( word.find("@") == -1 ):
return False
else:
return True
out_arquivo = open("Dt_Neymar.nt", "w+")
in_arquivo = open("Dt_Neymar.json", "r")
#out_arquivo.write("{\"dados\":[")
fix_control = 0
ctrl = 0
next(in_arquivo)
for linha in in_arquivo:
n_elem = 0
string = []
separacao = linha.split(",")
if(len(separacao) > 2):
for n in range( len(separacao) ):
if(n_elem < 3):
valores = separacao[n].split(": ")
res = valores[1].replace("}", "").replace("\n","")
if(analyser1(res)):
res = res.replace("\"", "")
elif(analyser2(res)):
gui1 = res.split("@")
res = gui1[0]+"\""+"@"+gui1[1][0]+gui1[1][1]
string.append(res)
n_elem += 1
#print(string)
if(string):
if(ctrl > 0):
#print(string)
out_arquivo.write( "\n"+
"<"+string[0]+">"+" "+
"<"+string[1]+">"+" "+
"<"+string[2]+">"+" .")
else:
out_arquivo.write( "<"+string[0]+">"+" "+
"<"+string[1]+">"+" "+
"<"+string[2]+">"+" .")
ctrl += 1
#out_arquivo.write("\n\n]}"
in_arquivo.close()
out_arquivo.close()