Пример #1
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)

    def get_list(field):
        return get(field).replace(' ', '').split(',')

    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_list('load')
    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)

    try:
        rule_names = get_list('allowed_rules')
    except ConfigParser.NoOptionError, e:
        rule_names = []
Пример #2
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)
Пример #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

    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)