Beispiel #1
0
		o_id = c.fetchone()[0]
		props[p][1].write(("{} {} 1" + "\n").format(s_id, o_id))
		

TSink = TensorSink()
g = NTriplesParser(TSink)
f = open("test.ttl", 'rb')
g.parse(f)
f.close()
conn.commit()
c.execute("SELECT count(*) FROM entities")
num_ents = c.fetchone()[0]

#close all writers and the database connection
for key, value in props.items():	
	value[1].close()
conn.close()

#create .mtx for all properties with proper head fields
for key, value in props.items():
	id_p = str(value[0])
	with open("matrices/" + id_p, "r") as f:
		num_nonZeros = sum([1 for line in f]) - 3
	with open("matrices/" + id_p, "r") as f, open("matrices/" + id_p + ".mtx", "w+") as g:
		for line in f:
			g.write(line.replace("num_ents num_ents num_nonZeros", "{} {} {}".format(num_ents, num_ents, num_nonZeros)))
	os.remove("matrices/" + id_p)