annotate sparql.py @ 12:30a553efb31e draft

Uploaded
author sem4j
date Mon, 30 Sep 2013 23:21:54 -0400
parents 2c9827b61b71
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
1 # sparql.py version:0.1
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
2 # USAGE: python sparql.py <str_select> <input_file> <output_file>
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
3
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
4 import sys, os, commands
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
5
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
6 argvs = sys.argv
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
7 if (len(argvs) != 4):
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
8 print 'Number of argv is incorrect'
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
9 quit()
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
10
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
11 out = open('query.tmp', 'w')
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
12 out.write(argvs[1])
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
13 out.close()
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
14
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
15 os.system('mv ' + argvs[2] + ' ' + argvs[2] + '.nt')
9
2c9827b61b71 Uploaded
sem4j
parents: 2
diff changeset
16 stdout = commands.getoutput('sparql --query=query.tmp --data=' + argvs[2] + '.nt -results=TSV')
2
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
17 os.system('mv ' + argvs[2] + '.nt ' + argvs[2])
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
18
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
19 out = open(argvs[3], 'w')
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
20 out.write(stdout)
dba28145ab27 Uploaded
sem4j
parents:
diff changeset
21 out.close()