ai-prolog8

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

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

1 Artificial Intelligence: Natural Language and Prolog More Prolog Prolog and NL Grammars

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

View Full Document
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]”
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]).

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

View Full Document
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 = []
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)

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

View Full Document
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.
7 Negation What if you want to say that something is true if something is can NOT be proved. Logically we would have:

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

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

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

View Full Document
Ask a homework question - tutors are online