LING 388: Language and Computers Sandiway Fong Lecture 4: 9/1.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
LING 364: Introduction to Formal Semantics Lecture 24 April 13th.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/25.
LING 364: Introduction to Formal Semantics Lecture 8 February 7th.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/22.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING/C SC/PSYC 438/538 Lecture 4 9/1 Sandiway Fong.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
LING 388 Language and Computers Lecture 3 9/09/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/7.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/7.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.
LING 388 Language and Computers Lecture 7 9/23/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
1 LING 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388 Language and Computers Lecture 12 10/9/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 8.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
MBAC 611.  We have been using MS Access to query and modify our databases.  MS Access provides a GUI (Graphical User Interface) that hides much of the.
LING 388: Language and Computers Sandiway Fong Lecture 22: 11/10.
LING 388: Language and Computers Sandiway Fong Lecture 4.
LING 388: Language and Computers Sandiway Fong Lecture 7.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
LING 408/508: Programming for Linguists Lecture 3 August 31 st.
LING 388: Language and Computers Sandiway Fong Lecture 3.
LING 388: Language and Computers Sandiway Fong Lecture 30 12/8.
LING 388: Language and Computers Sandiway Fong Lecture 6.
LING 388: Language and Computers Sandiway Fong Lecture 7 9/15.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 2 (submit by midnight Friday) Today is Perl.
LING 388: Language and Computers Sandiway Fong Lecture 26 11/22.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
LING 388: Language and Computers Sandiway Fong Lecture 10.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
LING 388: Language and Computers Sandiway Fong Lecture 27: 12/6.
Linux+ Guide to Linux Certification, Third Edition
Files Tutor: You will need ….
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
LING/C SC/PSYC 438/538 Lecture 16 Sandiway Fong. SWI Prolog Grammar rules are translated when the program is loaded into Prolog rules. Solves the mystery.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong. Homework 4 Submit one PDF file Your submission should include code and sample runs Due date Monday 21.
For Friday No reading Prolog Handout 2. Homework.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Operational Semantics of Scheme
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong.
Presentation transcript:

LING 388: Language and Computers Sandiway Fong Lecture 4: 9/1

Administrivia LING 388 Homework #1 –handed out today –submit homework by –due date is one week from now Wednesday September 8th (by midnight) Reminder –No class on Monday (Labor Day) –Resume next Wednesday (Harvill 208)

Today’s Topic Backup lecture material with an introduction to SWI-Prolog – –manuals available online –SWI-Prolog is already installed on all the lab machines

SWI-Prolog How to start it? –from the Windows Program menu –interpreter window pops up and is ready to accept database queries ( ?- ) How to see what’s in the database? –?- listing. How to see what the current working directory is? –(the working directory is where your files are stored) –?- working_directory(X,Y). –X : current working directory, Y : new working directory How to change to a new working directory? –?- working_directory(X,NEW).

SWI-Prolog How to enter facts and rules into the database? –Method 1: At the interpreter prompt ?- assert(medal(gold)). will add to the database the fact: –medal(gold). Remember that Prolog cares about the order of facts in the database: –?- asserta(medal(gold)). »adds medal(gold). to the front –?- assertz(medal(gold)). »adds medal(gold). to the end

SWI-Prolog How to enter facts and rules into the database? –Method 2: Create a file in the current working directory containing database facts and rules. Load the file using: ?- consult(FILE). or ?- [FILE ]. –(comma-delimited list notation)

SWI-Prolog A note on filenames –Convention: Prolog files normally have extension.pl e.g. mydb.pl (.pl is also used by Perl) –FILE above should be the filename without the extension e.g. ?- [mydb]. –The period (.) is a special symbol in Prolog. If you wish to specify the full name, you must enclose it in single quotes e.g. ?- [’mydb.pl’].

SWI-Prolog Stepping through the computation tree –By default, Prolog just returns answers without showing its work –Turn on tracing mode for the Prolog debugger ?- trace. –Run queries as before Hit the return key to step (“creep”) through the computation e.g. –?- a(X). –1 1 Call: a(_430) ? RETURN –1 1 Exit: a(1) ? RETURN –X = 1 ? ; –1 1 Redo: a(1) ? RETURN Type h (help) instead of RETURN to see other options –Turn off Prolog debugger ?- nodebug.

Exercise 1a: Prolog Queries Create database –modal(should). –modal(could). –modal(shall). –modal(may). Load the database into Prolog Run queries –?- modal(X). use ; to get all answers –?- \+ modal(be). Note Prolog doesn’t give you the opportunity to use ; to get more answers. Why? –?- findall(X,modal(X),L). What does findall/3 do?/3 means “has three arguments”

Exercise 1b: Prolog Queries Modify the database to include facts –aux(am). –aux(are). –aux(is). –aux(was). –aux(were). –aux(do). –aux(does). –aux(did). and the rules for hasCNeg/1 implementing –English modals and auxiliaries have a contracted negative form –hasCNeg(X) :- modal(X). –hasCNeg(X) :- aux(X).

Exercise 1b: Prolog Queries Verify the operation of hasCNeg/1 by running queries –?- hasCNeg(X). –?- findall(X,hasCNeg(X),L). –?- hasCNeg(sleep). Homework Question (3pts) –Modify predicate hasCNeg/1 to block –?- hasCNeg(shall). *shalln’t –?- hasCNeg(may). *mayn’t –?- hasCNeg(am). *amn’t Hint: see previous lecture –(Submit both your definition and results of queries)

Exercise 2a: Building and Taking Names Apart Built-in predicate atom_chars/2 has two modes of usage 1.takes names apart ?- atom_chars(will,X). – X is the list of characters representing will 2.builds names from a list of characters ?- atom_chars(X,[ ’ J’,o,h,n]). –use quotes around capitalized J to avoid intepretation as a variable ?- atom_chars(X,[w,o,n,’’’’,t]). – ’’’’ denotes the single quote

Exercise 2a: Building and Taking Names Apart Run queries –?- atom_chars(has,[h,a,s]). –?- atom_chars(will,[w,X,l,l]). –?- atom_chars(X,Y). –?- atom_chars(X,[J,o,h,n]). –What happens in the last two cases?

Exercise 2b: Building and Taking Names Apart append/3 is a built-in predicate in SWI-Prolog defined as follows: –append(L1,L2,L3) holds if list L3 is the linear concatenation of lists L1 and L2 –append/3 has multiple modes of usage Run example queries: ?- append([1],[2,3],X). ?- append(X,Y,[1,2]). ?- append(_,[X],[1,2,3]). ?- append(X,Y,Z). –Note: the underscore character ‘_’ is a special variable no binding will be reported by the interpreter for underscores

Exercise 2b: Building and Taking Names Apart Homework Question (6pts) –Use both atom_chars/2 and append/3 to define a new rule addNT/2 such that: addNT(X,Y) converts between a modal or auxiliary verb X and its contracted negative counterpart Y –Examples: ?- addNT(could,’couldn’’t’). ?- addNT(is,’isn’’t’). Make sure it (A) rejects may mayn’t (B) handles irregular forms –can can`t, shall shan`t, will won`t –(Submit both your definition and results of relevant queries)

Exercise 3: Computation Tree append/3 can be defined recursively as follows: –app([],L2,L2). Base case –app([X|L1],L2,[X|L3]) :- app(L1,L2,L3). Recursive case –append/3 is already defined (built-in), so we use the predicate name app/3 to avoid a naming clash Re-run queries for append/3 with app/3 to see that app/3 has the same behavior: ?- app([1],[2,3],X). ?- app(X,Y,[1,2]). ?- app(_,[X],[1,2,3]). ?- app(X,Y,Z). Make use of the tracing facility to convince yourself that the definition is correct

Exercise 3: Computation Tree Homework Question (3pts) –(A) How many inference steps does it take to run the following query: ?- app([1,2,3],[4],L). –(B) How many inference steps does it take to run the following query: ?- app([1],[2,3,4],L). –(C) Explain why the number of steps differ despite the fact both queries return the same result. –For inference steps: count the number of CALL s

Summary 3 homework questions –12 pts on offer