Let me reply by top-posting ,,,

> Do you have an idea on how to check for SetLink membership? Or am I doing
something wrong?

Yes .. and yes...

I think you are mis-using the StateLink. The intent of the StateLink is to
force an atomic one-and-only-one "membership", ever. Thus the example
(State (Concept "traffic light") (Concept "red")) means that "traffic
light"  can only have one color at a time, whereas lots of things can be
red.  It's not symmetric -- only the first atom is the thing that has the
state.  (Its also atomic, and can be accessed in multiple threads in a
consistent, thread-safe manner)

You can count number of items in a link with ArityLink

scheme@(guile-user)> (use-modules (opencog) (opencog exec))
scheme@(guile-user)> (cog-execute! (Arity (Set (Concept "A") (Concept
"B"))))
   (NumberNode "2")

(cog-evaluate! (GreaterThan (Arity (Set (Concept "A") (Concept "B")))
(Number 1)))
   (stv 1.000000 1.000000)

-- linas

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"))))))
>>
>> 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/CAHrUA34NmyqBx9sYxY%2B%3D-VCuaB6oM-ewVCRfVaRHZj957LFUww%40mail.gmail.com.

Reply via email to