Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to filter values from temporary set? #2202

Closed
vsbogd opened this issue Jun 5, 2019 · 3 comments
Closed

How to filter values from temporary set? #2202

vsbogd opened this issue Jun 5, 2019 · 3 comments
Labels

Comments

@vsbogd
Copy link
Contributor

vsbogd commented Jun 5, 2019

I have the set which is dynamically created. In fact it is returned by GroundedSchemaNode. I would like to filter some values from set using GroundedPredicateNode as filter.

I tried to use the folowing MapLink expression but it returns empty set and doesn't call filter. Is it intended behavior?

Since MapLink seems to be the only atom which can perform pattern matching on some set of atoms (not on the whole atomspace) it looks like there is no possibility to make such filtering.

(define (filter atom)
  (display "filter called ") (display atom) (newline)
  (SimpleTruthValue 1 1)
)

(cog-execute!
  (Map
    (ImplicationScope
      (TypedVariable (Variable "x") (Type "ConceptNode"))
      (Evaluation (GroundedPredicate "scm:filter") (Variable "x"))
      (Variable "x")
    )
    (Set (Concept "a") (Concept "b"))
  )
)
@vsbogd vsbogd added the question label Jun 5, 2019
@linas
Copy link
Member

linas commented Jun 5, 2019

For now, just use GetLink/BindLink. These "search the entire atomspace" only at the conceptual level; in practice, they search only a very tiny part of it, so performance should not be an issue. However you were able to corral (Concept "a") (Concept "b") into a single set, you should also be able to tag them with MemberLinks, and then pattern-match the memberlinks: e.g

(MemberLink (Concept "a") (Concept "my set"))
(MemberLink (Concept "b") (Concept "my set"))

(cog-execute! (Get (And
   (PresentLink (MemberLink (Variable "x") (Concept "my set")))
   (Evaluation (GroundedPredicate "scm:filter") (Variable "x")))
)))

and that should work (modulo optional (TypedVariable (Variable "x") (Type "ConceptNode")) and whatever bugs I've introduced)

Even better:

(cog-execute! (Bind
   (And
      (PresentLink (MemberLink (Variable "x") (Concept "my set")))
      (Evaluation (GroundedPredicate "scm:filter") (Variable "x")))  )
   (MemberLink  (Variable "x") (Concept "the next stage set"))))

which is a processing pipeline: accepts my-set as input, and places results into "the next stage set". Also BTW, I use AnchorNode for this (i.e. (Anchor "my set") instead of (Concept "my set") - anchors are a cleaner more obvious drop-off/pick-up points.

MapLink is a half-baked experiment, that never really worked very well, and perhaps it might be time to remove it. Here's what happened:

  • It seemed like "not searching the whole atomspace" was somehow a good idea. as pointed out above, GetLink already doesn't search the whole atomspace, so it's actually a mediocre idea.
  • MapLink potentially allows you to build pipelines ... but so does GetLink.
  • Turns out SetLink is a bad idea .. see the wiki page for SetLink, and also issue Stop using SetLink for search results! #1502 for this. I want to replace all users of SetLink by MemberLink.
  • ... all this suggests that maybe MapLink serves no known purpose in life, and should be removed. See Eliminate MapLink #2203

@linas
Copy link
Member

linas commented Jun 5, 2019

p.s. the advantage of MemberLink vs SetLink is:

  • you can add/delete elements by creating/deleting to MemberLinks at any time.
  • you can have named sets with MembeLlink
  • SetLinks have to be manually deleted when you are done with them; if you don't delete them, they accumulate as zombie garbage in the atomspace, alive but playing no role.
  • SetLinks are hard to search, even with GlobNodes, they are hard to search.
  • SetLinks don't allow incremental reporting of results. e.g. if you have a very long-running algo, and you have to collect all results in a set-link, then you have to wait until it is done, instead of being able to report partial results immediately the way you might with a promise/future. (proposal Design a Publish/Subscribe System (aka Futures) #1750)

@linas
Copy link
Member

linas commented Jun 5, 2019

reply edited, click to see full reply...

@vsbogd vsbogd closed this as completed Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants