{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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.

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern