-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathLoad_comp_KG(linear)_generate_script.py
103 lines (88 loc) · 3.92 KB
/
Load_comp_KG(linear)_generate_script.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import xml.etree.ElementTree as xml
import random
from random import randrange
from datetime import datetime
from datetime import timedelta
Max_Objects = 7500000 #Model 1
Max_Options = 7500000 #Model 2
Max_Step_1 = 100000 #Maximum number of model elements in each rdf file
Max_Step_2 = 50000 #Maximum number of model elements in each rdf file
#Constants
SPARQL_path = "C:/Blazegraph/1" #The path is used for UPDATE RDF DB creation script
Model_path = "Linear_model/" #The path for output files
def createXML(filename):
#Open SPARQL file
spql = open(Model_path + "sparql_script.spql", "wt")
# Add header
header = str("<?xml version='1.0' encoding='UTF-8'?>\n<rdf:RDF\nxmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'\nxmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'\nxmlns:my='http://127.0.0.1/bg/ont/test1#'\n>")
f = open(Model_path + filename + "_static.nq", "wt")
f.write(header)
# Model 1 hierarchy definition
# Add Core definitions
f.write("\n<!--Model 1 Core definitions-->\n<rdf:Description rdf:about='http://127.0.0.1/Core_1/'>\n<my:has_id>Core_1</my:has_id>\n</rdf:Description>")
# Model 2 hierarchy definition
# Add Core definitions
f.write("\n<!--Model 2 Core definitions-->\n<rdf:Description rdf:about='http://127.0.0.1/Core_2/'>\n<my:has_id>Core_2</my:has_id>\n</rdf:Description>")
f.write("\n</rdf:RDF>\n")
f.close()
spql.write("\nLOAD <file:///" + str(SPARQL_path) + "/" + filename + "_static.nq>;\n")
# Add Object definitions
FileNum = 0
i = 1
k = 1
while i <= Max_Objects:
FileNum = FileNum + 1
f = open(Model_path + filename + "_object_" + str(FileNum) + "_.nq", "at")
f.write(header)
f.write("\n<!--Objects definitions-->\n")
while k <= Max_Step_1:
body = str("<rdf:Description rdf:about='http://127.0.0.1/Object_") + str(i) + str("/'>\n<my:has_id>Object_") + str(i) + str("</my:has_id>\n<my:has_parent_id>Core_1</my:has_parent_id>\n</rdf:Description>\n")
f.write(body)
i = i + 1
k = k + 1
f.write("\n</rdf:RDF>\n")
f.close()
spql.write("\nLOAD <file:///" + str(SPARQL_path) + "/" + filename + "_object_" + str(FileNum) + "_.nq>;\n")
k = 1
# Add Options definitions
FileNum = 0
i = 1
k = 1
while i <= Max_Options:
FileNum = FileNum + 1
f = open(Model_path + filename + "_option_" + str(FileNum) + "_.nq", "at")
f.write(header)
f.write("\n<!--Options definitions-->\n")
while k <= Max_Step_1:
body = str("<rdf:Description rdf:about='http://127.0.0.1/Option_") + str(i) + str(
"/'>\n<my:has_id>Option_") + str(i) + str("</my:has_id>\n<my:has_parent_id>Core_2</my:has_parent_id>\n</rdf:Description>\n")
f.write(body)
i = i + 1
k = k + 1
if i >= Max_Options: break
f.write("\n</rdf:RDF>\n")
f.close()
spql.write("\nLOAD <file:///" + str(SPARQL_path) + "/" + filename + "_option_" + str(FileNum) + "_.nq>;\n")
k = 1
# Add Object-option links links Type-1 definitions
FileNum = 0
i = 1
k = 1
while i <= Max_Objects:
FileNum = FileNum + 1
f = open(Model_path + filename + "_links_1_" + str(FileNum) + "_.nq", "at")
f.write(header)
f.write("\n<!--Add Object-option links Type-Linear-->\n")
while k <= Max_Step_1:
body = str("<rdf:Description rdf:about='http://127.0.0.1/Object_") + str(i) + str(
"/'>\n<my:has_option_id>Option_") + str(random.randint(1, Max_Options)) + str("</my:has_option_id>\n</rdf:Description>\n")
f.write(body)
i = i + 1
k = k + 1
f.write("\n</rdf:RDF>\n")
f.close()
spql.write("\nLOAD <file:///" + str(SPARQL_path) + "/" + filename + "_links_1_" + str(FileNum) + "_.nq>;\n")
k = 1
spql.close()
if __name__ == "__main__":
createXML("KG_telecom")