I just realized that the example below has a misleading, confusing bug in it. (besides the missing SetLink) The fix is ...
On Wed, May 6, 2020 at 7:31 AM Alexander Gabriel <[email protected]> wrote: > > Hi Linas! > > Am Mittwoch, 26. Februar 2020 22:24:45 UTC schrieb linas: >> >> If you really need it to work in *all* cases, then something like this: >> >> (DefineLink >> (DefinedPredicate "is in state") >> (Lambda >> (VariableList (Variable "a") (Variable "b")) >> (Equal (Variable "a") (Get (State (Variable "b") (Variable >> "x")))))) >> > Arghhh, The get part of it should have been (Get (Variable "x") (State (Variable "b") (Variable "x"))) so that the Lambda plugs in for the "b", and the Get does the search for the "x". Without this, the Get performs the searches for pairs "b" and "x" .. which was not the intent. And I am guessing that this is what screwed up everything, and lead to thoughts of SubsetLink... Sorry, this thinko on my part caused a lot of work on your part. Oooops. Anyway, I'm in the process of fixingin Subset and some other things so be sure to pull a new atomspace .. say in 12 hours... --linas > >> which you would use like so: >> >> (cog-evaluate! >> (EvaluationLink (DefinedPredicate "is in state") >> (List (Concept "red light") (Concept "stop light")))) >> >> and that should work just fine. This might be overkill for what you are >> trying to do ... but it does work, and the intent is that, for complex >> situations, this is how you would do it. >> > > What actually did work, was this: > > someone = ConceptNode("bob") > has_crate = ConceptNode("has crate") > StateLink(someone, has_crate) > > DefineLink( > DefinedPredicateNode("is in state"), > LambdaLink( > VariableList(VariableNode("target"), VariableNode("state")), > EqualLink(SetLink(ListLink(VariableNode("target"), > VariableNode("state"))), GetLink(StateLink(VariableNode("anything"), > VariableNode("state")))))) > > query = EvaluationLink(DefinedPredicateNode("is in state"), > ListLink(someone, ConceptNode("has crate"))) > > results = evaluate_atom(atomspace, query) > print(results) > > Notice the addition of the SetLink which is necessary as the GetLink > returns one. > Herein also lies the problem: This works fine if there is just one entity > with a given state, but it fails when there are multiple entities with a > given state because in this case the SetLink returned by the GetLink will > contain multiple ListLinks and so the EqualLink evaluates to (0, 1). > I tried to get around this using a SubSetLink, but that runs into a > NotImplemented error. > > [2020-05-06 12:24:50:065] [ERROR] Either incorrect or not implemented yet. > Cannot evaluate (SubsetLink > (SetLink > (ListLink > (ConceptNode "bob" (stv 1.000000 1.000000)) ; [510da4194021b685][1] > (ConceptNode "has crate") ; [7f11eb3c16f8beb0][1] > ) ; [8983ace7aae6590b][-1] > ) ; [e7b63e6f2f3e7452][-1] > (GetLink > (StateLink > (VariableNode "anything") ; [7f082726ca4ddba3][1] > (VariableNode "state") ; [38680c2d1603e9c8][1] > ) ; [df8079f1c9baf09d][-1] > ) ; [9e4a50ee0b3b95e2][-1] > ) ; [cf2ff93ac449180b][-1] > (/home/rasberry/git/atomspace/opencog/atoms/execution/EvaluationLink.cc:100) > Stack Trace: > 2: basic_string.h:222 std::__cxx11::basic_string<char, > std::char_traits<char>, std::allocator<char> >::_M_is_local() const > 3: Logger.cc:594 opencog::Logger::Error::operator()(char const*, ...) > 4: exceptions.cc:54 > opencog::StandardException::parse_error_message(char const*, > __va_list_tag*, bool) > 5: exceptions.cc:82 > opencog::StandardException::parse_error_message(char const*, char const*, > __va_list_tag*, bool) > 6: exceptions.cc:169 opencog::SyntaxException::SyntaxException(char > const*, char const*, __va_list_tag*) > 7: EvaluationLink.cc:100 _Z20throwSyntaxExceptionbPKcz() > 8: basic_string.h:222 std::__cxx11::basic_string<char, > std::char_traits<char>, std::allocator<char> >::_M_is_local() const > 9: EvaluationLink.cc:299 bool_to_tv() > 10: EvaluationLink.cc:999 > opencog::EvaluationLink::do_evaluate(opencog::AtomSpace*, opencog::Handle > const&, bool) > 11: shared_ptr_base.h:729 > std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() > 12: EvaluationLink.cc:868 > opencog::EvaluationLink::do_eval_scratch(opencog::AtomSpace*, > opencog::Handle const&, opencog::AtomSpace*, bool) > 13: EvaluationLink.cc:999 > opencog::EvaluationLink::do_evaluate(opencog::AtomSpace*, opencog::Handle > const&, bool) > 14: shared_ptr_base.h:758 > std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_swap(std::__shared_count<(__gnu_cxx::_Lock_policy)2>&) > 15: [0x4bc9ba] ??() ??:0 > 16: [0x4ba036] ??() ??:0 > 17: [0x4eb32f] ??() ??:0 > 18: [0x4e5592] ??() ??:0 > 19: [0x4e3e46] ??() ??:0 > 20: [0x493ade] ??() ??:0 > 21: libc-start.c:325 __libc_start_main() > 22: [0x4934a9] ??() ??:0 > > Traceback (most recent call last): > File "./example3.py", line 99, in <module> > results = evaluate_atom(atomspace, query) > File "opencog/bindlink.pyx", line 21, in opencog.bindlink.evaluate_atom > (/home/rasberry/git/atomspace/build/opencog/cython/opencog/bindlink.cpp:1268) > RuntimeError: Either incorrect or not implemented yet. Cannot evaluate > (SubsetLink > (SetLink > (ListLink > (ConceptNode "bob" (stv 1.000000 1.000000)) ; [510da4194021b685][1] > (ConceptNode "has crate") ; [7f11eb3c16f8beb0][1] > ) ; [8983ace7aae6590b][-1] > ) ; [e7b63e6f2f3e7452][-1] > (GetLink > (StateLink > (VariableNode "anything") ; [7f082726ca4ddba3][1] > (VariableNode "state") ; [38680c2d1603e9c8][1] > ) ; [df8079f1c9baf09d][-1] > ) ; [9e4a50ee0b3b95e2][-1] > ) ; [cf2ff93ac449180b][-1] > (/home/rasberry/git/atomspace/opencog/atoms/execution/EvaluationLink.cc:100) > > > > Do you have an idea on how to check for SetLink membership? Or am I doing > something wrong? > > Best regards, > 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/72094b32-a6e6-4820-9c5b-a97474f4d663%40googlegroups.com > <https://groups.google.com/d/msgid/opencog/72094b32-a6e6-4820-9c5b-a97474f4d663%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- cassette tapes - analog TV - film cameras - you -- 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/CAHrUA36c%2Bv41-UhaNkTHt63mVrXbJb72Ej6L7nptp-2P1Vs%3DLw%40mail.gmail.com.
