Skip to content

Commit

Permalink
Continuing with the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Apr 16, 2015
1 parent 77ed51c commit 19d6325
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
2 changes: 2 additions & 0 deletions examples/pattern-matcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ See `../guile/README` for for an intro on running the guile shell needed
to run te demos here.

* simple.scm: a basic introduction to pattern matching.
* gsn.scm: calling arbitrary functions upon a match

* fsm-basic.scm: A simple Finite State Machine demo.
* fsm-full.scm: A generic finite-state-machine constructor
* markov-chain.scm: A Markov chain (probabilistic FSM) based on above.
59 changes: 35 additions & 24 deletions examples/pattern-matcher/gpn.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,59 @@

(load-from-path "utilities.scm")

(define (rand-ok atom)
(if (< 0 (random 2))
(begin
(simple-format #t "Picked ~A\n" (cog-name atom))
(stv 1 1) ; return true
)
(begin
(simple-format #t "Did not pick ~A\n" (cog-name atom))
(stv 0 1) ; return true
)
)
)

(EvaluationLink
(PredicateNode "is-a")
(ListLink
(ConceptNode "Linas")
(ConceptNode "Aristotle")
(ConceptNode "human")
)
)

(define (say-hello atom)
(display "hello!")
(newline)
(stv 0.5 0.5)
(EvaluationLink
(PredicateNode "is-a")
(ListLink
(ConceptNode "Pierce")
(ConceptNode "human")
)
)

(define find-humans
(BindLink
(VariableNode "$person")
(ImplicationLink
(EvaluationLink
(PredicateNode "is-a")
(ListLink
(VariableNode "$person")
(ConceptNode "human")
)
)
(EvaluationLink
(GroundedPredicateNode "scm: say-hello")
(ListLink
(VariableNode "$person")
)
(AndLink
(EvaluationLink
(PredicateNode "is-a")
(ListLink
(VariableNode "$person")
(ConceptNode "human")
)
)
(EvaluationLink
(GroundedPredicateNode "scm: rand-ok")
(ListLink
(VariableNode "$person")
)
)
)
(VariableNode "$person")
)
)
)

; (cog-bind find-humans)

(cog-evaluate! (EvaluationLink
(GroundedPredicateNode "scm: say-hello")
(ListLink
(ConceptNode "Linas")
)
)
)

0 comments on commit 19d6325

Please sign in to comment.