18
PROPS Junli Tao [email protected] Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf ’ from Pat Langley

PROPS - Auckland · PROPS Junli Tao [email protected] Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

PROPS

Junli Tao [email protected]

Rm 321-723, Tamaki Campus

(Wed. 1:00pm-2:00pm)

Partially based on lecture node ‘productions. pdf’ from Pat Langley

Page 2: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

PROPS

• Based on Prolog

• Implemented in ‘props.txt’ by Benjamin Meadows

– shall be renamed to ‘props.pl’

• To use PROPS, you need to code

– working memory (facts)

– production memory (rules)

Page 3: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Working Memory

• Working memory elements play a role similar to Prolog fact but they may NOT include variables

• In the language parsing case, you may need

– a stack: stack([])

– a buffer: buffer([])

– dictionary knowledge: noun(john), verb(dance)…

Page 4: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Working Memory

• add command

– add new elements to working memory

– take a single argument that satisfy the syntax of a working memory element

– proceed each instance with ":-“ if used in a file

e.g.

:- add(stack([])). :- add(noun(john)).

:- add(buffer([])). :- add(verb(dance)).

Page 5: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Working Memory

• remove command

– remove elements from working memory

– takes one argument that satisfy the syntax of a working memory element

– may contain the variable "_" for one or more of the predicate's arguments

e.g.

remove(buffer(_)) remove(stack(_))

Page 6: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Production Memory

• Contain generalized rules

– A condition side

• With conditions that must match working memory

• That share pattern-match variables across conditions

– Action sides

• With one or more actions that alter memory

• That share pattern-match variables with conditions

Page 7: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Production Memory

• Rule syntax – begin with a name – next comes the word "if“ – one or more conditions that are separated by ‘and’ – followed by the word "then“ – followed by one or more actions

infer_taller if taller_than(X, Y) and taller_than(Y, Z) then add(taller_than(X, Z)).

Page 8: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Interpretion

• Pattern matchiing

– Simple matches – verb(dance)

– Complex matches – taller_than(X, Y) and taller_than(Y, Z)

• Rule chaining

Page 9: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Conflict Resolution

• instantiations that match against more recent elements

• instantiations that match against more specific sets of elements

• production rules that have more conditions

• production rules that were added earlier (PROPS)

– if more than one instantiation of the same rule matches with different bindings

– selects one of them at random

Page 10: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

check Predicate

• take single argument

• begin with any of the predicates

– equal, not_equal, is_in, is_not_in, member, not_member

– is_in checks for the presence of a symbol at any level of embedding

Page 11: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Add and Remove Rules

• add rule

– takes a single argument that should satisfy the syntax of a production rule

• :- add_rule(grandfather if father(X, Y) and father(Y, Z) then add(grandfather(X, Z))).

• remove_rule

– takes one argument and removes from production memory any rule with that name

Page 12: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Print and Read

• Print

– take a single argument that may be either a string or a bound variable

– print the argument

• print('What is the next sentence?\n')

• Read

– take a single unbound variable as an argument

– bind it to what the user types

• read(List)

Page 13: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

end and reset

• end

– stop execution

• reset

– the interpreter removes information about previous rule firings

– instantiations selected earlier become available for consideration

Page 14: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

trace_wm

• trace_wm

– Trace stack and buffer in working memory

wm_trace(original_list(_)), wm_trace(reversed_list(_)).

• show_wm

– show the elements in working memory

show_wm.

Page 15: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

List Structure: head|tail

• The first element of a list is called its head and the remaining list is called the tail

– ?- [1, 2, 3, 4, 5] = [Head | Tail].

Head = 1

Tail = [2, 3, 4, 5]

– ?- [[a],[b,c],[d,e,f]] = [Head |Tail].

Head = [a]

Tail = [[b,c],[d,e,f]]

Page 16: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

List Structure

• Given a list • stack( [[np], [s],[whatever]])

• Contains several lists

• Check the first element in the first list • stack([[np|_]|_])

• Add one a list [noun, john] in the first list behind the first element

• stack ([[np|X]|Y])

• remove(stack(_))

• add(stack[[np,[noun,john]|X]|Y])

Page 17: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Reverse List

reverse_list

if

original_list([X|Rest]) and

reversed_list(Y)

then

remove(original_list(_)) and remove(reversed_list(Y)) and add(original_list(Rest)) and add(reversed_list([X|Y])).

Given original_list([[a,c],[d]], reversed_list([])

- X bound to [a,c]

- Rest bound to [d]

- Remove original_list and reversed_list

- Add original_list([d]) to working memory

- Add reversed_list([[a,c]])

Page 18: PROPS - Auckland · PROPS Junli Tao jtao076@aucklanduni.ac.nz Rm 321-723, Tamaki Campus (Wed. 1:00pm-2:00pm) Partially based on lecture node ‘productions. pdf’ from Pat Langley

Using append

contains2 if list_of_interest([X|Y]) and some_list_structure(Z) and check(is_in(X, Z)) and contained(W) then remove(list_of_interest([X|Y])) and remove(contained(W)) and add(list_of_interest(Y)) and append(W, X, Appended) and add(contained(Appended)).