Am Dienstag, 5. Mai 2020 09:10:54 UTC+1 schrieb Nil:
>
> Hi Alex, 
>
> I think there is no reasoning needed here, a pattern matcher query would 
> suffice, that is said it the BC should succeed at the first iteration. 
>
> I see query_B is using DefinedPredicateNode("is_tall_B") while your 
> DefineLink is using "tall_B" maybe that's the problem. 


Hi Nil,
no, sorry. That's a typo introduced while renaming things to make more 
sense in the example :/

Here is a cleaned up version of the full source and output (I'm aware there 
are no rules loaded, I just can't find a relevant one and I couldn't figure 
out how to load all the rules from python..or rather, I couldn't figure out 
how to tell the python chainer call to use the pln-created atomspace for 
the rules..(I don't know how to reference the correct atomspace from 
python)):

#!/usr/bin/env python


from opencog.type_constructors import *
from opencog.ure import BackwardChainer, ForwardChainer
from opencog.utilities import initialize_opencog
from opencog.atomspace import AtomSpace, TruthValue
from opencog.logger import log




def print_results(query,results):
    print("Query:\n{:}\n\nResults:\n{:}\n\nDetails:\n--------".format(query, 
results))
    if query.type_name == "GetLink":
        for setlink in results.get_out():
            for result in setlink.get_out():
                print("Result Truth: {:}".format(result.tv))
                print("Result:\n{:}".format(result))
                print("------------------------\n")
    elif query.type_name == "AndLink":
        for result in results.get_out():
            print("Result Truth: {:}".format(result.tv))
            print("Result:\n{:}".format(result))
            for condition in result.get_out():
                print("------------------------")
                print("Condition:{:}".format(condition))
                print("Condition Truth: {:}".format(condition.tv))
                if condition.type_name == "NotLink":
                    subcondition = condition.get_out()[0]
                    print("    Subcondition: {:}".format(subcondition))
                    print("    Subcondition Truth: {:}".format(subcondition.
tv))
            print("-----------------------------------------------------")
    else:
        for result in results.get_out():
            print("Result Truth: {:}".format(result.tv))
            print("Result:\n{:}".format(result))
            print("------------------------\n")




if __name__ == '__main__':

    # I patched the URE logger to use the standard logger instance, you're 
unlikely to get ure debug ouptput if you run the code.
    log.use_stdout()
    log.set_level("DEBUG")


    atomspace = AtomSpace()


    initialize_opencog(atomspace)


    height = PredicateNode("height")
    is_tall = DefinedPredicateNode("is_tall_B")


    someone = ConceptNode("bob").truth_value(1.0, 1.0)
    someone.set_value(height, FloatValue(1.9))


    var_person = VariableNode("person")
    var_x = VariableNode("X")




    DefineLink(
        is_tall,
            LambdaLink(
                var_x,
                    GreaterThanLink(
                        ValueOfLink(
                            var_x,
                            height),
                        NumberNode("1.75"))))


    variables = VariableList(
        TypedVariableLink(
            var_person,
            TypeNode("ConceptNode")))


    query = EvaluationLink(
        is_tall,
        var_person)




    chainer = BackwardChainer(_as=atomspace,
                      rbs=ConceptNode("none"), trace_as=None, control_as=
None, focus_set=None,
                      target=query, vardecl=variables)
    chainer.do_chain()
    results = chainer.get_results()
    print_results(query, results)



and the result of running it:

[2020-05-06 10:22:36:775] [DEBUG] initialize_opencog - initializing Python
[2020-05-06 10:22:36:775] [INFO] [global_python_initialize] Start
[2020-05-06 10:22:36:775] [INFO] [global_python_initialize] Adding OpenCog 
sys.path directories
[2020-05-06 10:22:36:775] [DEBUG] Python 'sys.path' is:
[2020-05-06 10:22:36:775] [DEBUG]      0 > 
/home/rasberry/git/ure/build/opencog/cython
[2020-05-06 10:22:36:775] [DEBUG]      1 > 
/home/rasberry/git/atomspace/build/opencog/cython
[2020-05-06 10:22:36:775] [DEBUG]      2 > 
/home/rasberry/catkin_ws/devel/lib/python2.7/dist-packages
[2020-05-06 10:22:36:775] [DEBUG]      3 > 
/opt/ros/kinetic/lib/python2.7/dist-packages
[2020-05-06 10:22:36:775] [DEBUG]      4 > 
/home/rasberry/catkin_ws/src/rasberry_hri/src
[2020-05-06 10:22:36:775] [DEBUG]      5 > 
/usr/local/lib/python2.7/dist-packages/webnsock-0.0.6-py2.7.egg
[2020-05-06 10:22:36:775] [DEBUG]      6 > 
/usr/local/lib/python2.7/dist-packages/web.py-0.40.dev1-py2.7.egg
[2020-05-06 10:22:36:775] [DEBUG]      7 > /usr/lib/python2.7/dist-packages
[2020-05-06 10:22:36:775] [DEBUG]      8 > 
/usr/local/lib/python2.7/dist-packages/pyproj-1.9.5.1-py2.7-linux-x86_64.egg
[2020-05-06 10:22:36:775] [DEBUG]      9 > 
/home/rasberry/git/ure/build/opencog/cython
[2020-05-06 10:22:36:775] [DEBUG]     10 > 
/home/rasberry/git/atomspace/build/opencog/cython
[2020-05-06 10:22:36:775] [DEBUG]     11 > 
/home/rasberry/catkin_ws/devel/lib/python2.7/dist-packages
[2020-05-06 10:22:36:775] [DEBUG]     12 > 
/opt/ros/kinetic/lib/python2.7/dist-packages
[2020-05-06 10:22:36:775] [DEBUG]     13 > /usr/lib/python2.7
[2020-05-06 10:22:36:775] [DEBUG]     14 > 
/usr/lib/python2.7/plat-x86_64-linux-gnu
[2020-05-06 10:22:36:775] [DEBUG]     15 > /usr/lib/python2.7/lib-tk
[2020-05-06 10:22:36:775] [DEBUG]     16 > /usr/lib/python2.7/lib-old
[2020-05-06 10:22:36:775] [DEBUG]     17 > /usr/lib/python2.7/lib-dynload
[2020-05-06 10:22:36:775] [DEBUG]     18 > 
/home/rasberry/.local/lib/python2.7/site-packages
[2020-05-06 10:22:36:775] [DEBUG]     19 > 
/usr/local/lib/python2.7/dist-packages
[2020-05-06 10:22:36:775] [DEBUG]     20 > 
/usr/lib/python2.7/dist-packages/PILcompat
[2020-05-06 10:22:36:775] [DEBUG]     21 > 
/usr/lib/python2.7/dist-packages/gtk-2.0
[2020-05-06 10:22:36:775] [DEBUG]     22 > 
/usr/lib/python2.7/dist-packages/wx-3.0-gtk2
[2020-05-06 10:22:36:775] [INFO] [global_python_initialize] Finish
[2020-05-06 10:22:36:775] [DEBUG] initialize_opencog - creating PythonEval 
singleton instance
[2020-05-06 10:22:36:775] [INFO] 
PythonEval::initialize_python_objects_and_imports Finished initialising 
python evaluator.
[2020-05-06 10:22:36:775] [DEBUG] Rule-base none, set parameter 
URE:maximum-iterations to 100 [default] 
[2020-05-06 10:22:36:775] [DEBUG] Rule-base none, set parameter 
URE:complexity-penalty to 0 [default] 
[2020-05-06 10:22:36:775] [DEBUG] Rule-base none, set parameter URE:jobs to 
1 [default] 
[2020-05-06 10:22:36:775] [DEBUG] Rule-base none, set parameter 
URE:FC:retry-exhausted-sources to 0 [default] 
[2020-05-06 10:22:36:775] [DEBUG] Rule-base none, set parameter 
URE:FC:full-rule-application to 0 [default] 
[2020-05-06 10:22:36:776] [DEBUG] Rule-base none, set parameter 
URE:BC:maximum-bit-size to -1 [default] 
[2020-05-06 10:22:36:776] [DEBUG] Rule-base none, set parameter 
URE:BC:MM:complexity-penalty to 0 [default] 
[2020-05-06 10:22:36:776] [DEBUG] Rule-base none, set parameter 
URE:BC:MM:compressiveness to 1 [default] 
[2020-05-06 10:22:36:776] [DEBUG] Default inference rule TVs:
[2020-05-06 10:22:36:776] [DEBUG] Start backward chaining
[2020-05-06 10:22:36:776] [DEBUG] With rule set:
size = 0
[2020-05-06 10:22:36:776] [DEBUG] Iteration 1/100
[2020-05-06 10:22:36:776] [DEBUG] Initialize BIT with:
(BindLink
  (TypedVariableLink
    (VariableNode "person") ; [40bf26ea112895be][1]
    (TypeNode "ConceptNode") ; [3494df0ad0397660][1]
  ) ; [cfa066b73bf288dd][1]
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
) ; [de1d20a71923fa1f][3]
[2020-05-06 10:22:36:776] [DEBUG] Selected and-BIT for fulfillment (fcs 
value):
[de1d20a71923fa1f][3]
[2020-05-06 10:22:36:776] [DEBUG] Results:
size = 0
[2020-05-06 10:22:36:776] [DEBUG] Iteration 2/100
[2020-05-06 10:22:36:776] [DEBUG] Weighted and-BITs:
1 [de1d20a71923fa1f][3]
[2020-05-06 10:22:36:776] [DEBUG] Selected and-BIT for expansion:
(BindLink
  (TypedVariableLink
    (VariableNode "person") ; [40bf26ea112895be][1]
    (TypeNode "ConceptNode") ; [3494df0ad0397660][1]
  ) ; [cfa066b73bf288dd][1]
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
) ; [de1d20a71923fa1f][3]
[2020-05-06 10:22:36:776] [DEBUG] Selected BIT-node for expansion:
body:
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
exhausted: 0
rules:
  size = 0
[2020-05-06 10:22:36:776] [DEBUG] No valid rule for the selected BIT-node, 
abort expansion
[2020-05-06 10:22:36:776] [DEBUG] Cannot fulfill an empty and-BIT. Abort 
BIT fulfillment
[2020-05-06 10:22:36:776] [DEBUG] Iteration 3/100
[2020-05-06 10:22:36:776] [DEBUG] Weighted and-BITs:
1 [de1d20a71923fa1f][3]
[2020-05-06 10:22:36:776] [DEBUG] Selected and-BIT for expansion:
(BindLink
  (TypedVariableLink
    (VariableNode "person") ; [40bf26ea112895be][1]
    (TypeNode "ConceptNode") ; [3494df0ad0397660][1]
  ) ; [cfa066b73bf288dd][1]
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
  (EvaluationLink
    (DefinedPredicateNode "is_tall_B") ; [633392579119c32][1]
    (VariableNode "person") ; [40bf26ea112895be][1]
  ) ; [c0a7dafcd6614da1][1]
) ; [de1d20a71923fa1f][3]
[2020-05-06 10:22:36:776] [DEBUG] All BIT-nodes of this and-BIT are 
exhausted (or possibly fulfilled). Abort expansion.
[2020-05-06 10:22:36:776] [DEBUG] Cannot fulfill an empty and-BIT. Abort 
BIT fulfillment
[2020-05-06 10:22:36:776] [DEBUG] Terminate: all AndBITS are exhausted
[2020-05-06 10:22:36:776] [DEBUG] Finished backward chaining with results:
size = 0
Query:
(EvaluationLink (DefinedPredicateNode "is_tall_B") (VariableNode "person"))

Results:
(SetLink)

Details:
--------


Thank you for your time!

Best,
Alex

-- 
You received this message because you are subscribed to the Google Groups 
"opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/opencog/a60e0622-9bed-46e1-8e40-93dad595640a%40googlegroups.com.

Reply via email to