Example #1
0
def blocksworld_test(atomspace):
    atomspace.clear()
    blocksworld.blocksworld_rules(atomspace)

    import logic

    target_tr = T(
        'SimultaneousAndLink',
        #parse_conditions_list(blocks, 'on A B | on B C')
        parse_conditions_list(blocks, 'on A B'))

    c = logic.Chainer(atomspace)

    res = logic.do_planning(atomspace, target_tr, c)

    f = '<blocksworld_test>'
    if len(res):
        print 'PASSED'
    else:
        print 'FAILED'
Example #2
0
def blocksworld_test(atomspace):
    atomspace.clear()
    blocksworld.blocksworld_rules(atomspace)

    import logic

    target_tr = T('SimultaneousAndLink',
        #parse_conditions_list(blocks, 'on A B | on B C')
        parse_conditions_list(blocks, 'on A B')
    )

    c = logic.Chainer(atomspace)

    res = logic.do_planning(atomspace, target_tr,c)

    f = '<blocksworld_test>'
    if len(res):
        print 'PASSED'
    else:
        print 'FAILED'
Example #3
0
def run_pln_example(a, f):
    a.clear()

    testdir = '../tests/reasoning/pln/targets/'
    datadirs = ['../tests/reasoning/pln/scm/', '../opencog/']
    fname = testdir + f
    config = ConfigParser.ConfigParser()
    read_files = config.read(fname)

    if not read_files:
        raise Exception("no such file:", fname)

    def get(field):
        return config.get('PLN_TEST', field)

    print f

    def load_axioms(fname):
        for d in datadirs:
            kf = d + fname + '.scm'
            try:
                tmp = open(kf, 'r')
                scheme_wrapper.load_scm(a, kf)
                print kf
                return
            except IOError:
                continue
        raise IOError("missing data file: " + kf)

    data_files = get('load').replace(' ', '').split(',')
    for fname in data_files:
        load_axioms(fname)
    scm_target = '(cog-handle %s)' % (get('target'), )
    print scm_target
    handle_str = scheme_wrapper.scheme_eval(scm_target)
    try:
        h = int(handle_str)
    except ValueError:
        print handle_str
        raise Exception("Scheme error in target")

    nsteps = int(get('max_steps'))

    target = Atom(Handle(h), a)

    print target

    import logic
    import tree
    # hack - won't work if the Scheme target is some variable that doesn't contain "Demand"
    if "Demand" in scm_target:
        # superhack - doesn't care which target you say
        target_tr = tree.tree_from_atom(target)
        res = logic.do_planning(a, target_tr)
    else:
        c = logic.Chainer(a)
        target_tr = tree.tree_from_atom(target)
        res = c.bc(target_tr, nsteps)

    if len(res):
        print 'PASSED'
        passed.append(f)
    else:
        print 'FAILED'
        failed.append(f)
Example #4
0
def run_pln_example(a, f):
    a.clear()
    
    testdir = '../tests/reasoning/pln/targets/'
    datadirs = ['../tests/reasoning/pln/scm/',
                '../opencog/']
    fname = testdir+f
    config = ConfigParser.ConfigParser()
    read_files = config.read(fname)
    
    if not read_files:
        raise Exception("no such file:",fname)
    
    def get(field):
        return config.get('PLN_TEST',field)

    print f
    
    def load_axioms(fname):
        for d in datadirs:
            kf = d+fname+'.scm'
            try:
                tmp = open(kf,'r')
                scheme_wrapper.load_scm(a, kf)
                print kf
                return
            except IOError:
                continue
        raise IOError("missing data file: "+kf)
        
    data_files = get('load').replace(' ','').split(',')
    for fname in data_files:
        load_axioms(fname)
    scm_target = '(cog-handle %s)' % (get('target'),)
    print scm_target
    handle_str = scheme_wrapper.scheme_eval(scm_target)
    try:
        h = int(handle_str)
    except ValueError:
        print handle_str
        raise Exception("Scheme error in target")

    nsteps = int(get('max_steps'))
    
    target = Atom(Handle(h), a)
    
    print target
    
    import logic
    import tree

    c = logic.Chainer(a)
    target_tr = tree.tree_from_atom(target)

    # hack - won't work if the Scheme target is some variable that doesn't contain "Demand"
    if "Demand" in scm_target:
        res = logic.do_planning(a, target_tr,c)
    else:
        res = c.bc(target_tr, nsteps)

    print map(str, res)

    if len(res):
        print 'PASSED'
        passed.append(f)
    else:
        print 'FAILED'
        failed.append(f)
Example #5
0
    target = Atom(Handle(h), a)

    try:
        rule_names = get_list('allowed_rules')
    except ConfigParser.NoOptionError, e:
        rule_names = []

    print target

    import logic
    import tree

    c = logic.Chainer(a, allowed_rule_names=rule_names, use_fc=True)
    target_tr = tree.tree_from_atom(target)

    # hack - won't work if the Scheme target is some variable that doesn't contain "Demand"
    if "Demand" in scm_target:
        res = logic.do_planning(a, target_tr, c)
    else:
        res = c.bc(target_tr, nsteps)

    print map(str, res)

    if len(res):
        print 'PASSED'
        passed.append(f)
    else:
        print 'FAILED'
        failed.append(f)