Beispiel #1
0
 def _make_entity_node(self, data):
     if isinstance(data, dict):
         return calc_graph.CG([{'node_type': 'entity', 'data': data}])
     else:
         return calc_graph.CG([{
             'node_type': 'entity',
             'data': x
         } for x in data])
Beispiel #2
0
    def __init__(self, fname=None, data=None):
        if not data and not fname:
            raise ValueError('either `fname` or `data` must be not None')

        if not data:
            data = json.load(open(fname))
        self.cg = calc_graph.CG(data)
Beispiel #3
0
 def test_basic(self):
     cg = calc_graph.CG(self.CG_DATA)
     calc_graph.CGNode()
     self.assertFalse(cg.value.is_set())
     cgdict = cg.root.to_dict()
     self.assertEquals(len(cgdict['children']), len(self.CG_DATA))
     # computational step
     cg.step()
     self.assertTrue(cg.value.value)
Beispiel #4
0
 def init_convo(self, protocol_name, external_token=None):
     if protocol_name in self.protocol_data:
         if external_token:
             token = external_token
         else:
             token = str(uuid.uuid4())
         cg = calc_graph.CG(self.protocol_data[protocol_name])
         self.conversations[token] = cg
         return token
     else:
         raise Exception('protocol not found')
Beispiel #5
0
    def test_flu(self):
        pp = pprint.PrettyPrinter()
        data = json.load(open('lib/tests/test2.json'))
        convo_protocol = convo_fact.ConvoProtocol(data)
        cg = calc_graph.CG()
        cg.root = convo_protocol
        pp.pprint(cg.root.to_dict())

        print cg.step()
        print cg.step('220')
        pp.pprint(cg.root.to_dict())
        resp = cg.step('yes')
        self.assertTrue('flu' in resp[1].text)
        pp.pprint(cg.root.to_dict())
Beispiel #6
0
 def test_ent_node_graph(self):
     cg = calc_graph.CG([{
         'node_type': 'entity',
         'data': {
             'class': 459,
             'subclass': 3,
             'id': 'HEADACHE',
             'name': 'Headache'
         }
     }])
     val, ret = cg.step()
     self.assertFalse(val.value)
     self.assertFalse(ret.step_occured)
     val, ret = cg.step('got headache')
     self.assertTrue(val.value)
     self.assertTrue(ret.step_occured)
Beispiel #7
0
    def test_911(self):
        pp = pprint.PrettyPrinter()
        data = json.load(open('lib/tests/test2.json'))
        convo_protocol = convo_fact.ConvoProtocol(data)
        cg = calc_graph.CG()
        cg.root = convo_protocol
        pp.pprint(cg.root.to_dict())

        print cg.step()
        print cg.step('190')
        print cg.root.to_dict()
        print cg.root.index
        resp = cg.step('140')
        print resp
        pp.pprint(cg.root.to_dict())
        resp = cg.step('140')
        print resp
        self.assertTrue('911' in resp[1].text)
Beispiel #8
0
from lib import calc_graph
from lib import convo_fact
import json

data = json.load(open('protocols/test2.json'))
cg = calc_graph.CG(data)
print cg.root.to_dict()