Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
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
• 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)
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)…
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)).
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(_))
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
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)).
Interpretion
• Pattern matchiing
– Simple matches – verb(dance)
– Complex matches – taller_than(X, Y) and taller_than(Y, Z)
• Rule chaining
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
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
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
Print and Read
– 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)
end and reset
• end
– stop execution
• reset
– the interpreter removes information about previous rule firings
– instantiations selected earlier become available for consideration
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.
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]]
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])
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]])
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)).