-
Notifications
You must be signed in to change notification settings - Fork 235
/
put-filter.scm
60 lines (50 loc) · 1.62 KB
/
put-filter.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;
; put-filter.scm -- Using PutLink to remove unwanted entries in a set.
;
; The PutLink can be used to filter a set of atoms. This filtering
; is accomplished by using the built-in type-checking facilities
; that accompany any LambdaLink.
;
; See also the `filter.scm` example, for more general filter-mapping
; of sets and lists.
;
(use-modules (opencog) (opencog exec))
; Define a PutLink that will keep ConceptNodes, and ignore the rest.
(define filter-it
(Put
; Declare a single variable: The variable must be a ConceptNode.
(TypedVariable (Variable "%x") (Type "ConceptNode"))
; The body of the PutLink is just the variable itself.
(Variable "%x")
; This is the set of things that will be filtered.
(Set
(Number "42")
(Concept "foo")
(Predicate "biffle")
(Evaluation (Predicate "foo") (Concept "thingy"))
(Schema "finagle")
(Concept "bar"))))
; Now, perform the actual filtering:
(cog-execute! filter-it)
; It is expected that the above returns just two items:
(Set
(Concept "foo")
(Concept "bar"))
; Similar to the above, but this time, we accept only EvaluationLinks.
(define filter-links
(Put
; Declare a single variable: The variable must be an
; EvaluationLink.
(TypedVariable (Variable "%x") (Type "EvaluationLink"))
; The body of the put is just the variable.
(Variable "%x")
; This is the set of things that will be filtered.
(Set
(Number "42")
(Concept "foo")
(Predicate "biffle")
(Evaluation (Predicate "foo") (Concept "thingy"))
(Schema "finagle")
(Concept "bar"))))
; Now, perform the actual filtering:
(cog-execute! filter-links)