Sie sind auf Seite 1von 8

/* * Grammar rules for different types of sentence and phrase.

* * Each specific rule is preceeded by examples of English phrases/sentences * it handles. * */ /* Assertions */ /* Snoopy is a beagle; a beagle is a dog; dogs are carnivores. */ assertion(isa(X, class(C)), Number) --> entity_name(X, Number), tobe(Number), class_name(class(C), Number). /* Snoopy is not a cat; a beagle is not a shepherd; dogs are not amphibians. */ assertion(~isa(X, class(C)), Number) --> entity_name(X, Number), not_tobe(Number), class_name(class(C), Number). /* Snoopy likes woodstock; Snoopy fears cats; an ai_student reads Nilsson; a dog chases cats; cats love Garfield; cats chase birds */ assertion(relationship(X, Y, R), Number) --> entity_name(X, Number), verb(R, Number), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. /* Garfield does not like Nermal; Garfield does not chase rodents; a jedi does not like Vader; a dog does not chase rodents; cats do not like Butch; dogs do not like fleas */ assertion(~relationship(X, Y, R), Number) --> entity_name(X, Number), not_todo(Number), verb(R, stem), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. assertion(property(X, Y, A), Number) --> definite_article, noun(Y, Number), genitive_preposition, entity_name(X, Number2), tobe(Number), adjective(A). assertion(~property(X, Y, A), Number) --> definite_article, noun(Y, Number), genitive_preposition, entity_name(X, Number2), not_tobe(Number), adjective(A). /* Yes no questions */ /* Is Snoopy a beagle? Is a beagle a dog? Are dogs carnivores? -- expected answer is yes */ /* Is Snoopy a cat? Is a beagle a shepherd? Are dogs amphibians? -- expected answer is no */ /* Is Snoopy a pilot? Is a cow an ungulate? Are fleas insects?

-- expected answer is "I don't know" */ yesno_question(isa(X, class(C)), Number) --> tobe(Number), entity_name(X, Number), class_name(class(C), Number). /* Does Snoopy like Woodstock? Does Snoopy fear cats? Does an ai_student read Nilsson? Does a dog chase cats? Do cats love Garfield? Do cats chase birds? -- expected answer is yes */ /* Does Garfield like Nermal? Does Garfield chase rodents? Does a jedi like Vader? Does a dog chase rodents? Do cats like Butch? Do dogs like fleas? -- expected answer is no */ /* Does Dilbert like Catbert? Does Dilbert love managers? Does a mathematician read Hilbert? Does an artist draw pictures? Do republicans like Bush? Do cs_majors write comments? -- expected answer is "I don't know */ yesno_question(relationship(X, Y, R), Number) --> todo(Number), entity_name(X, Number), verb(R, stem), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. yesno_question(property(X, Y, A), Number) --> tobe(Number), definite_article, noun(Y, Number), genitive_preposition, entity_name(X, Number2), adjective(A). /* Gapped questions */ /* What is Snoopy? What is a beagle? What are dogs? */ gapped_question(isa(X, class(C)), Number) --> interrogative(what), tobe(Number), entity_name(X, Number), { isa(X, _) }. /* Who is a beagle? */ gapped_question(isa(individual(I), class(C)), singular) --> interrogative(who), tobe(singular), class_name(class(C), singular). /* Who does Snoopy like? Who does an ai_student read? Who do cats love? -- Note: this form of question expects the answer to be an individual */ gapped_question(relationship(X, individual(I), R), Number) --> interrogative(who), todo(Number), entity_name(X, Number), verb(R, stem). /* What does Snoopy fear? What does a dog chase? What do cats chase? -- Note: this form of question expects the answer to be a class */ gapped_question(relationship(X, class(C), R), Number) --> interrogative(what), todo(Number), entity_name(X, Number), verb(R, stem). /* Who does Garfield not like? Who does a jedi not like ? Who do cats not like?

-- Note: this form of question expects the answer to be an individual */ gapped_question(~relationship(X, individual(I), R), Number) --> interrogative(who), todo(Number), entity_name(X, Number), negation, verb(R, stem). /* What does Garfield not chase? What does a dog not chase? What do dogs not like? -- Note: this form of question expects the answer to be a class */ gapped_question(~relationship(X, class(C), R), Number) --> interrogative(what), todo(Number), entity_name(X, Number), negation, verb(R, stem). /* Who likes Woodstock? Who fears cats? -- Note: this form of question expects the answer to be an individual */ gapped_question(relationship(individual(I), Y, R), singular) --> interrogative(who), verb(R, singular), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. /* What reads Nilsson? What chases cats? What loves Garfield? What chases birds? -- Note: this form of question expects the answer to be a class */ gapped_question(relationship(class(C), Y, R), singular) --> interrogative(what), verb(R, singular), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. /* Who doesn't like Nermal? Who does not chase rodents? -- Note: this form of question expects the answer to be an individual */ gapped_question(~relationship(individual(I), Y, R), singular) --> interrogative(who), not_todo(singular), verb(R, stem), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. /* What doesn't like Vader? What does not chase rodents? What don't like Butch? What do not like fleas? -- Note: this form of question expects the answer to be a class */ gapped_question(~relationship(class(C), Y, R), Number) --> interrogative(what), not_todo(Number), verb(R, stem), entity_name(Y, Number2), { (Y = individual(_), Number2 = singular) ; (Y = class(_), Number2 = plural) }. gapped_question(property(X, Y, A), Number) --> interrogative(what), tobe(Number), definite_article, noun(Y, Number), genitive_preposition, entity_name(X, Number2). gapped_question(property(class(X), Y, A), Number) --> interrogative(what), tobe(Number), genitive_preposition,

definite_article, noun(Y, Number),adjective(A). gapped_question(property(individual(X), Y, A), Number) --> interrogative(who), tobe(Number), genitive_preposition, definite_article, noun(Y, Number),adjective(A). /* * Phrases and words used in constructing the various forms of sentences * */ /* * An entity is either the name of an individual or of a class. Individual * names are singular nouns; class names are of the form "a noun" or * plural nouns. * */ entity_name(individual(I), singular) --> individual_name(individual(I), singular). entity_name(class(C), Number) --> class_name(class(C), Number). individual_name(individual(I), singular) --> { var(I) ; capitalized_form(I, Word) }, noun(Word, singular), { nonvar(I) ; I = Word }. /* We'll let any singular noun be an individual_name */ class_name(class(C), singular) --> indefinite_article(A), noun(C, singular), { appropriate_article(A, C) }. /* We'll let any singular noun be a class_name if it is preceeded by an indefinite article. */ class_name(class(C), plural) --> noun(C, plural). /* Likewise, we'll let any plural noun be a class name */ /* * Parts of speech. If a word is known, that is it's part of speech - otherwise, * infer part of speech from spelling and context of usage * */ noun(Stem, Number) --> [Word], { known_word(Word, Number, noun(Stem)) }. noun(Stem, singular) --> [Stem], { not known_word(Stem, _, _), not ends_in_s(Stem), not known_word(_, singular, noun(Stem)) }. noun(Stem, plural) --> { var(Stem) ; trailing_s(Stem, Word) }, [Word], { not known_word(Word, _, _), trailing_s(Stem, Word), not known_word(_, plural, noun(Stem)) }.

verb(Stem, Number) --> [Word], { known_word(Word, Number, verb(Stem)) }. verb(Stem, stem) --> [Stem], { known_word(_, _, verb(Stem)) }. verb(Stem, singular) --> { var(Stem) ; trailing_s(Stem, Word) }, [Word], { not known_word(Word, _, _), trailing_s(Stem, Word), not known_word(_, singular, verb(Stem)) }. verb(Stem, plural) --> [Stem], { not known_word(Stem, _, _), not ends_in_s(Stem), not known_word(_, plural, verb(Stem)) }. verb(Stem, stem) --> [Stem], { not known_word(Stem, _, _), not ends_in_s(Stem) }. tobe(Number) --> [Word], { known_word(Word, Number, tobe) }. not_tobe(Number) --> [Word], { known_word(Word, Number, not_tobe) }. not_tobe(Number) --> tobe(Number), [not]. todo(Number) --> [Word], { known_word(Word, Number, todo) }. not_todo(Number) --> [Word], { known_word(Word, Number, not_todo) }. not_todo(Number) --> todo(Number), negation. indefinite_article(Word) --> [Word], { known_word(Word, singular, indefinite_article) }. definite_article --> [Word], { known_word(Word, singular, definite_article) }. adjective(Word) --> [Word], { known_word(Word, _, adjective(Word)) }. adjective(Word) --> [Word], { not known_word(Word, _, _) }. genitive_preposition --> [Word], { known_word(Word, _, genitive_preposition) }. interrogative(what) --> [ Word ], { known_word(Word, _, interrogative(what)) }. interrogative(who) --> [ Word ], { known_word(Word, _, interrogative(who)) }. interrogative(why) -->

[ Word ], { known_word(Word, _, interrogative(why)) }. else --> [ Word ], { known_word(Word, _, else) }. negation --> [ Word ], { known_word(Word, _, negation) }. /* * Vocabulary * * This section contains definitions for certain key vocabulary words like * the forms of "to be". For most words, the program guesses the part of * speech from context, and uses standard English rules to deal with singular * and plural forms of nouns, and with stem and third singular forms of * verbs. However, entries can be made here for words that are known to the * program to be of a particular part of speech (and should not be assumed to * be something else) orirregular nouns and verbs. * * These entries take the following form * * known_word(Form, Number, Interpretation) * * (Where interpretation is "special" if the word appears directly in the * grammar rules, and should only be recognized in one of the roles where * explicitly used.) * * Note that, in the database, nouns are always stored in their singular form * and verbs in their stem form. The grammar rules for noun and verb always * return this canonical form. * */ known_word(is, singular, tobe). known_word(are, plural, tobe). known_word('isn''t', singular, not_tobe). known_word('aren''t', plural, not_tobe). known_word(does, singular, todo). known_word(do, plural, todo). known_word('doesn''t', singular, not_todo). known_word('don''t', plural, not_todo). known_word(a, singular, indefinite_article). known_word(an, singular, indefinite_article). known_word(the, singular, definite_article). known_word(of, _, genitive_preposition). known_word(quit, _, quit). known_word(what, _, interrogative(what)). known_word(who, _, interrogative(who)). known_word(why, _, interrogative(why)). known_word(else, _, else). known_word(not, _, negation). known_word(mice, plural, noun(mouse)). known_word(deer, plural, noun(deer)).

/* * Special functions necessitated by English syntax * */ /* * appropriate_article/2 * * Unifies first argument with "a" or "an" depending on first letter of * noun represented by second argument. * */ appropriate_article(An, Noun) :name(Noun, [H|T]), member(H, "aeiou"), !, An = an. appropriate_article(a, _). /* * ends_in_s/1 - succeeds if argument is an atom that ends in the letter s * */ ends_in_s(Form) :atom(Form), name(Form, FormName), append(_, "s", FormName). /* * trailing_s/2 * * add/remove trailing s to/from a form. The first argument is the form without * the s; the second, with the s. One argument needs to be instantiated to an atom * this predicate is called; the other will be unified with the appropriately * transformed version. This goal will fail if its first argument is * instantiated to a form that already ends in s, or if its second is * instantiated to a form that does not. * * If called with both arguments uninstantiated or instantiated to something * other than an atom, this predicate fails. * */ trailing_s(Form, Form_s) :atom(Form), !, not ends_in_s(Form), name(Form, FormName), append(FormName, "s", Form_sName), name(Form_s, Form_sName). trailing_s(Form, Form_s) :atom(Form_s), !, name(Form_s, Form_sName),

append(FormName, "s", Form_sName), name(Form, FormName). trailing_s(_, _). /* * capitalized_form/2 - instantiates second argument to capitalized form of first. * first argument must be nonvar. * * If called with the first argument uninstantiated, or * instantiated to something other than an atom, this predicate * fails. * */ capitalized_form(Noun, Cap) :atom(Noun), !, name(Noun, [ H | T ]), capitalize(H, HC), name(Cap, [ HC | T ]).

Das könnte Ihnen auch gefallen