view service/reasoning/oneShot @ 1401:2ec49c958f91

rule updates Ignore-this: e0e881f196303f76ee6f8a4a16dfad44 darcs-hash:995049f78867de2cbcbe23a0b4a0b3e1afc42a52
author drewp <drewp@bigasterisk.com>
date Tue, 23 Jul 2019 10:15:33 -0700
parents d8acab2b01f5
children 0996e3a91c85
line wrap: on
line source

#!/usr/bin/python
"""
send a statement to the reasoning server for one update cycle. Args
are s/p/o in n3 notation, with many prefixes predefined here.
"""
import sys, requests, time
s, p, o = sys.argv[1:]

prefixes = {
    '': 'http://projects.bigasterisk.com/room/',
    'room' : 'http://projects.bigasterisk.com/room/',
    'shuttle': 'http://bigasterisk.com/room/livingRoom/shuttlepro/',
    'sensor': 'http://bigasterisk.com/homeauto/sensor/',
}

def expand(term):
    if ':' not in term or term.startswith(('<', '"', "'")):
        return term
    left, right = term.split(':', 1)
    if left in prefixes:
        return '<%s%s>' % (prefixes[left], right)
    return term

stmt = '%s %s %s .' % (expand(s), expand(p), expand(o))
print "Sending: %s" % stmt

t1 = time.time()
ret = requests.post(
    'http://bang:9071/oneShot',
    headers={"content-type": "text/n3"},
    data=stmt.encode('ascii'))
g = float(ret.headers['x-graph-ms'])
print "%.1f ms for graph update; %.1f ms other overhead" % (g, 1000 * (time.time() - t1) - g)