view service/reasoning/oneShot @ 328:b069bb37f817

IR remote rule Ignore-this: 901771de421a81129f2ddf4316af91d9
author drewp@bigasterisk.com
date Sat, 03 Feb 2018 14:38:10 -0800
parents 79efb6fdcb95
children 79d041273e26
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, restkit, 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()
reasoning = restkit.Resource("http://bang:9071/")
ret = reasoning.post("oneShot",
                     headers={"content-type": "text/n3"},
                     payload=stmt)
g = float(ret.headers['x-graph-ms'])
print "%.1f ms for graph update; %.1f ms other overhead" % (g, 1000 * (time.time() - t1) - g)