Intro
 
Lession 1
 
Lession 2
 
Lession 3
 
Lession 4
 
Lession 5
 
Lession 6
 
Lession 7
 
Lession 8
 
Lession 9
 
Lession 10
 
Lession 11
 
Lession 12
 
Lession 13
 
Lession 14
 
Lession 15
 
Lession 16
 
Lession 17
 
Lession 18
 
Lession 19
 
Contact
 
 

 
Home | Text version
 
Download swi-prolog | Download these scripts

Learn Definite Clause Grammars (DCG) with Toki Pona

Lession 6

Now we add DCG rules for the Toki Pona lession Negation, Yes/No Questions. First we define a new sentence type for questions.

sentence                 --> sentence_interrogative,              separator('?').   

First we need rules for yes/no questions and answers.

sentence_interrogative   --> question_yes_no. 
 
sentence_declarative     --> answer_yes.                                                                                  
sentence_declarative     --> answer_no.                                                                                    

Questions could be yes/no-questions. Yes/no-question consist a noun phrase and a special verb phrase. "question_yn_verb_phrase" are defined by a verb, the negation word "ala" and the same verb.

question_yes_no          --> noun_phrase, question_yn_verb_phrase. 

question_yn_verb_phrase  -->                                                      verb_transitive(Verb),   adverb(ala), verb_transitive(Verb),   direct_objects,  prepositional_objects.
question_yn_verb_phrase  --> verb_pre(Verb_pre), adverb(ala), verb_pre(Verb_pre), verb_transitive(Verb), { Verb \= Verb_pre },                   direct_objects,  prepositional_objects.
question_yn_verb_phrase  --> verb_pre(Verb_pre), adverb(ala), verb_pre(Verb_pre),                                                                direct_objects,  prepositional_objects.
question_yn_verb_phrase  -->                                                      verb_intransitive(Verb), adverb(ala), verb_intransitive(Verb), intrans_objects, prepositional_objects.
question_yn_verb_phrase  --> verb_pre(Verb_pre), adverb(ala), verb_pre(Verb_pre), verb_intransitive(Verb), { Verb \= Verb_pre },                 intrans_objects, prepositional_objects.

Answers in this lesson could be an yes- or no-answer. A yes-answer is only a verb in this simple code snippet. A no-answer is a verb and the adverb "ala" or the noun "ala" alone.

answer_yes               -->                        verb_transitive(_).
answer_yes               --> verb_pre(Verb_pre),    verb_transitive(Verb), { Verb \= Verb_pre }.
answer_yes               --> verb_pre(_).

answer_no                -->                                            noun(ala).
answer_no                -->                        verb_transitive(_), adverb(ala).
answer_no                --> verb_pre(_),                               adverb(ala).
answer_no                --> verb_pre(Verb_pre),                        adverb(ala), verb_transitive(Verb), { Verb \= Verb_pre }.
Here is the source code of toki-pona-06.pro:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Learn Definite Clause Grammars with Toki Pona
% Toki Pona - Lession 06 - Negation, Yes/No Questions
% by Robert Warnke http://rowa.giso.de
% released under the GNU General Public License 
%
% ['toki-pona-06.pro'].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Grammar  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sentence types:

sentence                 --> sentence_declarative,                                                       separator('.').   % A declarative sentence states a fact or an argument and ends with a full stop.
sentence                 --> sentence_interrogative,                                                     separator('?').   % An interrogative sentence (questions) always ends in a question mark.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% definitions of the sentence types:

sentence_declarative     -->             sentence_simple.                                                                  % A declarative sentence can be an simple sentence. 
sentence_declarative     -->             sentence_simple,   separator(':'),              sentence_simple.                  % A declarative sentence can build of two simple sentences separated by a colon (sentence_hint).
sentence_declarative     --> answer_yes.                                                                                   % A declarative sentence can be a yes answer.
sentence_declarative     --> answer_no.                                                                                    % A declarative sentence can be a no answer.

sentence_interrogative   --> question_yes_no.                                                                              % A question can be a yes/no question.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% special sentences:

sentence_simple          --> noun_phrase,          verb_phrases.                                                           % A simple sentence consist of a noun phrase and verb phrases. 

answer_yes               -->                        verb_transitive(_).
answer_yes               --> verb_pre(Verb_pre),    verb_transitive(Verb), { Verb \= Verb_pre }.
answer_yes               --> verb_pre(_).

answer_no                -->                                            noun(ala).
answer_no                -->                        verb_transitive(_), adverb(ala).
answer_no                --> verb_pre(_),                               adverb(ala).
answer_no                --> verb_pre(Verb_pre),                        adverb(ala), verb_transitive(Verb), { Verb \= Verb_pre }.

question_yes_no          --> noun_phrase, question_yn_verb_phrase.                                                         % A yes/no questions consist of a noun phrase and a special verb phrase with "ala".


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  phrases:

noun_phrase              --> pronoun_no_li.
noun_phrase              --> pronoun_with_li,                                  separator(li).
noun_phrase              --> noun_compound,                                    separator(li).

verb_phrases             --> verb_phrase,         verb_phrase_add.
verb_phrase              --> verb_transitive_compound,                                       direct_objects,   prepositional_objects.
verb_phrase              --> verb_intransitive_compound,                                     intrans_objects,  prepositional_objects.
verb_phrase              --> adjectiv(_),               adjectives.                                                                     % In toki pona is no verb "to be". 
verb_phrase              --> pronoun_compound.                                                                                          % In toki pona is no verb "to be".
verb_phrase              --> noun_compound.                                                                                             % In toki pona is no verb "to be". 
verb_phrase_add          --> [].
verb_phrase_add          --> separator(li),       verb_phrase,          verb_phrase_add.

question_yn_verb_phrase  -->                                                      verb_transitive(Verb),   adverb(ala), verb_transitive(Verb),   direct_objects,  prepositional_objects.
question_yn_verb_phrase  --> verb_pre(Verb_pre), adverb(ala), verb_pre(Verb_pre), verb_transitive(Verb), { Verb \= Verb_pre },                   direct_objects,  prepositional_objects.
question_yn_verb_phrase  --> verb_pre(Verb_pre), adverb(ala), verb_pre(Verb_pre),                                                                direct_objects,  prepositional_objects.
question_yn_verb_phrase  -->                                                      verb_intransitive(Verb), adverb(ala), verb_intransitive(Verb), intrans_objects, prepositional_objects.
question_yn_verb_phrase  --> verb_pre(Verb_pre), adverb(ala), verb_pre(Verb_pre), verb_intransitive(Verb), { Verb \= Verb_pre },                 intrans_objects, prepositional_objects.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% objects:

direct_objects           --> [].                                                                                                        % no direct object
direct_objects           --> direct_object,       direct_objects.   
direct_object            --> separator(e),        noun_compound.
direct_object            --> separator(e),        pronoun_compound.

intrans_objects         --> [].      
intrans_objects         --> intrans_object.
intrans_object          --> noun_compound.                  
intrans_object          --> pronoun_compound.                  

prepositional_objects   --> [].                       
prepositional_objects   --> prepositional_object, prepositional_objects.
prepositional_object    --> comma_optional,       preposition(_),       noun_compound.
prepositional_object    --> comma_optional,       preposition(_),       pronoun_compound. 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pronouns:

pronoun_optional        --> [].
pronoun_optional        --> pronoun(_).

pronoun_no_li           --> pronoun(mi).                                                                                             % "mi" or "sina" need no "li".
pronoun_no_li           --> pronoun(sina).                                                                                           % "mi" or "sina" need no "li".
pronoun_with_li         --> pronoun(P), {P\=mi,P\=sina}.                                                                             % These pronouns need a "li".
pronoun_with_li         --> pronoun(_),                               adjectiv(mute).                                                % These compund pronouns need a "li".
pronoun_compound        --> pronoun(_),                               adjectives.                                                    % All (compound) pronouns.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% nouns:

noun_compound            -->  noun(_),     adjectives.                                                                                   % A compound noun can be build with a noun and optional adjectives.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% verbs:

verb_transitive_compound   --> verb_pre_optional,   adverbs,   verb_transitive(_),      adverbs.

verb_intransitive_compound --> verb_pre_optional,   adverbs,   verb_intransitive(_),    adverbs.

verb_pre_optional          --> [].
verb_pre_optional          --> verb_pre(_).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% adjectives:

adjectives              --> adjectives_pure,     pronoun_optional.

adjectives_pure         --> [].                                                                                                        % no adjectiv
adjectives_pure         --> adjectiv(_).                                                                                               % only one adjectiv
adjectives_pure         --> adjectiv(A), adjectiv(B),                           {A\=B}.                                                % two adjectives
adjectives_pure         --> adjectiv(A), adjectiv(B), adjectiv(C),              {A\=B,A\=C,B\=C}.              


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% adverbs:

adverbs                  --> [].                                                                                                         % no adverb
adverbs                  --> adverb(_).                                                                                                  % only one adverb
adverbs                  --> adverb(A),    adverb(B),                { A\=B } .                                                          % several adverbs
adverbs                  --> adverb(A),    adverb(B),   adverb(C),   { A\=B, A\=C , B\=C} .                                              % max. 3 different adverbs


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% miscellaneous:

comma_optional         --> [].
comma_optional         --> separator(',').


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Words 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

adjectiv(Adjectiv) --> [Adjectiv], { member(Adjectiv, [     
     ala,          % no, not, none, un- 
     ale,          % all, every, complete, whole  (ale = ali)
     ali,          % all, every, complete, whole  (ale = ali)
     anpa,         % low, lower, bottom, down
     ijo,          % of something
     ike,          % bad, negative, wrong, evil, overly complex, (figuratively) unhealthy
     insa,         % inner, internal
     jaki,         % dirty, gross, filthy
     jan,          % human, somebody's, personal, of people
     jo,           % private, personal
     kama,         % coming, future
     kili,         % fruity
     kiwen,        % hard, solid, stone-like, made of stone or metal
     kon,          % air-like, ethereal, gaseous
     lape,         % sleeping, of sleep, dormant
     lawa,         % main, leading, in charge
     len,          % dressed, clothed, costumed, dressed up 
     lili,         % small, little, young, a bit, short, few, less
     lukin,        % visual(ly)
     moku,         % eating
     monsi,        % back, rear
     musi,         % artful, fun, recreational
     mute,         % many, very, much, several, a lot, abundant, numerous, more
     nasa,         % silly, crazy, foolish, drunk, strange, stupid, weird
     pakala,       % destroyed, ruined, demolished, shattered, wrecked
     pali,         % active, work-related, operating, working
     pana,         % generous
     poka,         % neighbouring
     pona,         % good, simple, positive, nice, correct, right
     sama,         % same, similar, equal, of equal status or position
     seli,         % hot, warm, cooked
     sewi,         % superior, elevated, religious, formal
     suli,         % big, tall, long, adult, important
     sona,         % knowing, cognizant, shrewd
     suno,         % sunny, sunnily
     tan,          % causal, 
     tawa,         % moving, mobile
     telo,         % wett, slobbery, moist, damp, humid, sticky, sweaty, dewy, drizzly
     toki,         % speaking, eloquent, linguistic, verbal, grammatical
     tomo,         % urban, domestic, household
     unpa,         % erotic, sexual
     utala,        % fighting
     wawa         % energetic, strong, fierce, intense, sure, confident
%     wile          % necessary
 ])
}.

adverb(Adverb) --> [Adverb], { member(Adverb, [
     ala,           % don't
     ale,           % always, forever, evermore, eternally (ale = ali)
     ali,           % always, forever, evermore, eternally (ale = ali)
     ijo,           % of something
     ike,           % bad, negative, wrong, evil, overly complex, (figuratively) unhealthy
     jaki,          % dirty, gross, filthy
     jan,           % human, somebody's, personal, of people
     kama,          % coming, future
     kili,          % fruity
     kiwen,         % hard, solid, stone-like, made of stone or metal
     kon,           % air-like, ethereal, gaseous
     lape,          % asleep
     lawa,          % main, leading, in charge
     lili,          % small, little, young, a bit, short, few, less
     lukin,         % visual(ly)
     moku,          % eating
     musi,          % cheerfully
     mute,          % many, very, much, several, a lot, abundant, numerous, more
     nasa,          % silly, crazy, foolish, drunk, strange, stupid, weird
     pakala,        % destroyed, ruined, demolished, shattered, wrecked
     pali,          % actively, briskly
     pona,          % good, simple, positive, nice, correct, right
     sama,          % just as, equally, exactly the same, just the same, similarly
     seli,          % hot, warm, cooked
     sewi,          % superior, elevated, religious, formal
     suli,          % big, tall, long, adult, important
     sona,          % knowingly, deliberately, intentionally
     suno,          % sunny, sunnily
     tawa,          % moving, mobile
     telo,          % wett, slobbery, moist, damp, humid, sticky, sweaty, dewy, drizzly
     toki,          % speaking, eloquent, linguistic, verbal, grammatical
     tomo,          % urban, domestic, household
     unpa,          % erotic, sexual
     utala,         % fighting
     wawa          % strongly, powerfully
%     wile           % necessary
 ])
}.

noun(Noun) --> [Noun], { member(Noun, [   
     ala,          % nothing, negation, zero
     ale,          % everything, anything, life, the universe
     ali,          % everything, anything, life, the universe
     anpa,         % bottom, lower part, under, below, floor, beneath
     ijo,          % thing, something, stuff, anything, object
     ike,          % negativity, badness, evil
     ilo,          % tool, device, machine, thing used for a specific purpose
     insa,         % inside, inner world, centre, stomach
     jaki,         % dirt, pollution, garbage, filth
     jan,          % person, people, human, being, somebody, anybody
     jo,           % having
     kama,         % event, happening, chance, arrival, beginning
     ken,          % possibility, ability, power to do things, permission
     kili,         % fruit, pulpy vegetable, mushroom
     kiwen,        % hard thing, rock, stone, metal, mineral, clay
     kon,          % air, wind, smell, soul
     lape,         % sleep, rest
     lawa,         % head, mind
     len,          % clothing, cloth, fabric
     lili,         % smallness, youth, immaturity
     lukin,        % view, look, glance, sight, gaze, glimpse, seeing, vision, sight 
     ma,           % land, earth, country, (outdoor) area
     moku,         % food, meal
     monsi,        % back, rear end, butt, behind
     musi,         % fun, playing, game, recreation, art, entertainment
     mute,         % amount, quantity
     nasa,         % stupidity, foolishness, silliness, nonsense, idiocy, inanity, obtuseness, ninny, muddler
     pakala,       % blunder, accident, mistake, destruction, damage, breaking
     pali,         % activity, work, deed, project
     pana,         % giving, transfer, exchange
     pipi,         % bug, insect, spider
     poka,         % side, hip, next to
     poki,         % container, box, bowl, cup, glass
     pona,         % good, simplicity, positivity
     sama,         % equality, parity, equity, identity, par, sameness
     seli,         % fire, warmth, heat
     sewi,         % high, up, above, top, over, on
     sona,         % knowledge, wisdom, intelligence, understanding
     suli,         % size
     suno,         % sun, light
     tan,          % origin, cause
     tawa,         % movement, transportation
     telo,         % water, liquid, juice, sauce
     toki,         % language, speech, tongue, lingo, jargon, 
     tomo,         % indoor constructed space, e.g. house, home, room, building
     unpa,         % sex, sexuality
     wawa          % energy, strength, power
%     wile          % desire, need, will
 ])
}.

preposition(Preposition) --> [Preposition], { member(Preposition, [
     kepeken,     % with
     lon,         % be (located) in/at/on
     poka,        % in the accompaniment of, with
     sama,        % like, as, seem
     tan,         % from, by, because of, since
     tawa         % to, in order to, towards, for, until
 ])
}.

pronoun(Pronoun) --> [Pronoun], { member(Pronoun, [
     mi,          % I, we (pronoun 1. person)
     sina,        % you (pronoun 2. person)
     ona,         % she, he, it, they (pronoun 3. person)
     ni           % this, that (pronoun determiner)
 ])
}.

separator(Separator) --> [Separator], { member(Separator, [
     e,             % introduces a direct object
     li,            % between any subject except mi and sina and its verb
     '.',           % At the end of a sentence.
     '!',           % At the end of an interjection.
     '?',           % At the end of a question.
     ':',           % Between an hint sentences and a sentences.
     ','            % comma    
 ])
}.

verb_intransitive(Verb_intransitive) --> [Verb_intransitive], { member(Verb_intransitive, [
     ike,           % to be bad, to suck
     ken,           % can, is able to, is allowed to, may, is possible
     kepeken,       % use
     lape,          % to sleep, to rest
     lon,           % be there, be present, be real/true, exist, be awake
     lukin,         % look, watch out, pay attention
     musi,          % play, have fun
     pakala,        % screw up, fall apart, break
     pali,          % act, work, function
     sewi,          % to get up 
     sona,          % know, understand
     tawa,          % go to, walk, travel, move, leave
     toki,          % talk, chat, communicate
     unpa           % have sex
 ])
}.

verb_transitive(Verb_transitive) --> [Verb_transitive], { member(Verb_transitive, [
     anpa,          % defeat, beat, vanquish, conquer
     ijo,           % objectify
     ike,           % to make bad, to worsen, to have a negative effect upon
     jaki,          % pollute, dirty
     jan,           % personify, humanize, personalize
     jo,            % have, contain
     kama,          % bring about, summon
     ken,           % make possible, enable, allow, permit
     kiwen,         % to solidify, to harden, to petrify, to fossilize
%     lape,          % to sleep, to rest
     lawa,          % lead, control, rule, steer
     len,           % to wear, to be dressed, to dress
     lili,          % reduce, shorten, shrink, lessen
     lukin,         % see, look at, watch, read
     moku,          % eat, drink, swallow, ingest, consume
     musi,          % amuse, entertain
     mute,          % make many or much
     nasa,          % drive crazy, make weird
     pakala,        % screw up, fuck up, botch, ruin, break, hurt, injure, damage, spoil, ruin
     pali,          % do, make, build, create
     pana,          % give, put, send, place, release, emit, cause
     pona,          % improve, fix, repair, make good
     seli,          % heat, warm up, cook
     sewi,          % to lift
     sona,          % know, understand, know how to
     suli,          % enlarge, lengthen
     suno,          % to light, to illumine
     tawa,          % move, displace
     telo,          % water, wash with water
     toki,          % speak, talk, say, pronounce, discourse
     unpa,          % have sex with, sleep with, fuck
     utala,         % hit, strike, attack, compete against
     wawa           % strengthen, energize, empower
 ])
}.

verb_pre(Verb_pre) --> [Verb_pre], { member(Verb_pre, [
     kama,          % to become, to mange to
     sona,          % to know how to
     wile           % to want, need, wish, have to, must, will, should
 ])
}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For a user friendly input:
:- ['check_grammar.pro']. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Possible queries
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Possible queries with the syntax of the Difference Lists:

?- noun(X,_,_).
?- verb_transitive(X,_,_).


% Sentences with right grammar:

mi lape ala.
mi musi ala.
mi wawa ala.
mi wile ala tawa musi.
mi wile ala pali e tomo tawa.
jan li toki ala.
ala li jaki.
jan ali li wile tawa.
ma ali li pona.
jan utala ali li nasa.
ali li pona.
sina pona ala pona?
suno li suli ala suli?
len sina li telo ala telo?
tomo tawa sina li pakala ala pakala?
sina ken ala ken lape?
ona li lon ala lon tomo?
ona li tawa ala tawa ma ike?
sina pana ala pana e moku tawa?
pipi li moku ala moku e kili?
sina wile ala wile moku?
wile.
wile ala.
ala.
sina lukin ala lukin e kiwen?
lukin.
lukin ala.
sina sona ala sona e toki mi?
sona.
sona ala.
ni li musi ala musi?
sina wile toki e tan tawa mi.
pipi li lon ala lon poka mi?
mi pona ala pona tawa sina?
mi ken ala lape.                                                     % many variants!
mi wile ala toki tawa sina.
ona li tawa ala telo.                                                % many variants!
sina wile ala wile pali?
wile ala.
jan utala li seli ala seli e tomo?
jan lili li ken ala moku e telo nasa.
sina kepeken ala kepeken ni?
sina ken ala ken kama?
mi pona tan ni: mi lon.
mi sona ala e tan.
pipi li lon ala lon poka mi.


% Sentences with wrong grammar:

?- check_grammar.
|: sina wile ala mute moku?
false.

?- check_grammar.
|: sina lukin ala moku e kiwen?
false.

?- check_grammar.
|: sina sona ala pona e toki mi?
false.

?- check_grammar.
|: ni li musi ala pona?
false.





?- check_grammar.
|: sina kepeken ala kepeken e ni?
false.

*/

Download swi-prolog | Download these scripts | My langugage Projects on Github

 


rowa.giso.de | contact | Berlin (Good Old Europe)
This unofficial fan site by Robert Warnke is based on the official Toki Pona book and website: tokipona.org