view service/reasoning/oneShot @ 1055:e1693cc0b992

fix oneshot. more time reportin Ignore-this: c99ce7d8d31a8ed45bdcb8d0ad08a3aa darcs-hash:ae1b7c90ca9331b713af23a1f9a81cfb56380845
author drewp <drewp@bigasterisk.com>
date Tue, 09 Feb 2016 22:10:38 -0800
parents 3bb18b7d21df
children 79efb6fdcb95
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 = {
'room' : 'http://projects.bigasterisk.com/room/',
'shuttle': 'http://bigasterisk.com/room/livingRoom/shuttlepro/',
    }

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)