Python InferenceAgent Example

Introduction

The python inferenceagent example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: Python

Namespace/package name: plnexamplestuffysmokessmokes_agent

Example#1
File: smokes_example.pyProject: Counterfly/opencog

data = ["opencog/atomspace/core_types.scm",
        "opencog/scm/utilities.scm",
        "opencog/python/pln/examples/tuffy/smokes/smokes.scm"]

if EXTRA_DATA:
    data.append("opencog/python/pln/examples/tuffy/smokes/extra-data.scm")

for item in data:
    load_scm(atomspace, item)

atoms = atomspace.get_atoms_by_type(types.Atom)
for atom in atoms:
    print(atom)
MAX_STEPS = 500

chainer = InferenceAgent()
chainer.create_chainer(atomspace=atomspace, stimulate_atoms=False)

answer = False
outputs_produced = 0

for i in range(0, MAX_STEPS):
    result = chainer.run(atomspace)

    output = None
    input = None
    rule = None
    if result is not None:
        (rule, input, output) = result
        outputs_produced += 1

Example#2
File: smokes_example.pyProject: vvanirudh/opencog

data = ["opencog/atomspace/core_types.scm",
        "opencog/scm/utilities.scm",
        "opencog/python/pln/examples/tuffy/smokes/smokes.scm"]

if EXTRA_DATA:
    data.append("opencog/python/pln/examples/tuffy/smokes/extra-data.scm")

for item in data:
    load_scm(atomspace, item)

atoms = atomspace.get_atoms_by_type(types.Atom)
for atom in atoms:
    print(atom)
MAX_STEPS = 500

chainer = InferenceAgent()
chainer.create_chainer(atomspace=atomspace)


def check_result():
    # Searches for EvaluationLinks where the first argument is: PredicateNode
    # "cancer" and the target of the predicate is a ConceptNode (representing a
    # person)
    eval_links = atomspace.get_atoms_by_type(types.EvaluationLink)

    num_results = 0
    for eval_link in eval_links:
        out = [atom for atom in atomspace.get_outgoing(eval_link.h)
               if atom.is_a(types.PredicateNode) and atom.name == "cancer"]
        if out:
            list_link = atomspace.get_outgoing(eval_link.h)[1]