Examples from the live prax 16 March
geostats.py:
#!/usr/bin/env python3
import sys
import json
import sqlite3
#: loodenurk 59.730786, 21.734843
#: kagunurk 57.319992, 28.744707
# latitude on 57, pohjas suur, lounas vaike
# longitude on 21, laanes vaike, idas suur
def main():
# vota yhendust: kui baasi pole, see tehakse
conn = sqlite3.connect("estgeodata2")
cur = conn.cursor()
#sql_query = "select distinct object from rdf"
sql_query = "select * from rdf"
cur.execute(sql_query)
rows = cur.fetchall()
stats={}
for row in rows:
pred=row[2]
if pred in stats:
stats[pred]=stats[pred]+1
else:
stats[pred]=1
for pred in stats:
print(pred,stats[pred])
main()
geoexport.py, mis teeb jsonit (saada väljatrükk näiteks faili geodata.js):
#!/usr/bin/env python3
import sys
import json
import sqlite3
#: loodenurk 59.730786, 21.734843
#: kagunurk 57.319992, 28.744707
# latitude on 57, pohjas suur, lounas vaike
# longitude on 21, laanes vaike, idas suur
def main():
# vota yhendust: kui baasi pole, see tehakse
conn = sqlite3.connect("estgeodata2")
cur = conn.cursor()
#sql_query = "select distinct object from rdf"
sql_query = "select * from rdf"
cur.execute(sql_query)
rows = cur.fetchall()
stats={}
count=0
l=len(rows)
print("[")
for row in rows:
count+=1
#print(row)
data=["$arc",row[1],row[2],row[3]]
jsdata=json.dumps(data)
print(jsdata,end="")
if count<l: print(",")
print("\n]")
main()
Uue sqlite-ga peaks saama teha ka a la nii:
select json_array('$arc', object, property, value) from estonia limit 10;
Mikro-ülesanne prove1.js:
// ./gkc geodata.js prove.js -json -print 12 -strategy strategy.js -parallel 0
[
//X,hasCapital,Y -> X,type,region
//{"@role": "assumption", "@logic": [["$arc", "?:X", "<hasCapital>", "?:Y"],"=>",["$arc", "?:X", "hasProperty", "region"]]},
[["$arc", "?:X", "<hasCapital>", "?:Y"],"=>",["$arc", "?:X", "hasProperty", "region"]],
{"@question": ["$arc", "?:X", "hasProperty", "region"]}
//[["$arc", "?:X", "hasProperty", "region"],"=>",["$ans","?:X"]]
]
Näiteks kuidas käivitada (ei pea andma -strategy ja -parallel):
./gkc geodata.js prove1.js -strategy strategy.js -parallel 0
näitestrateegia strategy.js, mida eelmine käsurida kasutab:
{
"max_seconds":10,
"strategy":["query_focus","positive_pref"],
"query_preference":1,
"max_answers":3
}