ai-prolog8 - Artificial Intelligence: Natural Language and...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Artificial Intelligence: Natural Language and Prolog More Prolog Prolog and NL Grammars
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Prolog and Lists In Prolog you can use the following data structures: An atom (e.g., “john”) A functor-argument structure (e.g., “mother_of(john)”) A list of items. A list can be a list of atoms, functor argument structures, or a list of lists. Lists look like this: “[john, mary, sue]”
Background image of page 2
3 Prolog and Lists All these are lists: [1,2,3] [john, sue] [mary] [1, 2, mary, mother_of(john)] An empty list looks like this: [] All these are Prolog facts with lists: loves(mary, [john, joe,fred]). jugs_contain([3, 2]).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Lists and Matching Which do you think match? What bindings? [X, Y] = [1, 2] [X, 1] = [4, 1] [X,Y,Z] = [1, 2] [X] = [1, 2] A special pattern [X|Y] matches list with first item X and remainder Y (var names unimportant) [X|Y]=[1, 2, 3] X = 1, Y = [2, 3] [X|Y=[1] X = 1, Y = []
Background image of page 4
5 Arithmetic and Operators Prolog has the usual range of Arithmetic Operators (+, -, =, * . .) But unless you force it to, it won’t evalulate arithmetic expressions. They will simply be prolog structures to be matched. ?- 1+1 = 2. No ?- 1+1 = 1+X. X = 1 data(tweety, [legs=2, feathers=yes]). ?- data(tweety, Data), member(legs=X, Data). X = 2 ( Note how we can call several goals from Prolog prompt)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Arithmetic We can force Prolog to evaluate things using the special operator “is”. ?- X is 1 + 1. X = 2. ?- Y=1, X is Y + 1. X is 2. We could therefore write a limbs-counting predicate: no_limbs(animal, N) :- no_arms(animal, Narms), no_legs(animal, Nlegs), N is Narms + Nlegs.
Background image of page 6
7 Negation What if you want to say that something is true if something is can NOT be proved. Logically we would have:
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 24

ai-prolog8 - Artificial Intelligence: Natural Language and...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online