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 3

We improve our code to fit with the Toki Pona lession Adjectives, Compound Nouns, Adverbs.

One or more adverbs can follow one verb and describe the verb. I have limit the maximal number of adverbs to three, because more than four are not easy to unterstand and not Toki Pona style. Second the adverbs have to be different. Here is the code snippet:

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} .              
          

Now If you check the grammar of the sentence "mi moku." you will get three possibilities. This is why "moku" can be a verb, noun or adverb. Remember Toki Pona has no word for "be". So "moku" can be the adverb for "be". This it not easy to translate. But the grammar is correct.

?- check_grammar. 
|: mi moku. 
true ;
true ;
true ;

Adjectives describe nouns. A noun followed by one or more adjectives build a compound noun. The rules for pure adjectives are similar to the rule for adverbs. Because an adjective can not only be an pure adjectiv there are additional rules. At the end of adjectives can be an pronoun. Here is the code snippet:

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}.    

For a more clear code we define some rules for 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.

We put a noun and "adjectives" together as "noun_compound".

noun_compound            -->  noun(_),     adjectives.

In a similar way we define "verb_transitive_compound".

verb_transitive_compound   -->                      verb_transitive(_),          adverbs.
verb_transitive_compound   --> verb_pre(Verb_pre),  verb_transitive(Verb),       adverbs.

The rules "verb_phrase" and "direct_object" are clearer now.

verb_phrase              --> verb_transitive_compound,                                          direct_objects.
verb_phrase              --> adjectiv(_),               adjectives.                                               
verb_phrase              --> pronoun_compound.                                                                 
verb_phrase              --> noun_compound.                                                                   
	
direct_object            --> separator(e),        noun_compound.
direct_object            --> separator(e),        pronoun_compound.

Here are the source code of toki-pona-03.pro. As you can see at the beginning the adjectiv "mute" can follow "mi", "sina" or "ona" to build the plural.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Learn Definite Clause Grammars with Toki Pona
% Toki Pona - Lession 03 - Adjectives and Adverbs
% by Robert Warnke http://rowa.giso.de
% released under the GNU General Public License 
%
% ['toki-pona-03.pro'].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

sentence                 --> sentence_declarative, separator('.').       % A declarative sentence states a fact or an argument and ends with a full stop.


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

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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  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.
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.


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

direct_objects           --> [].                                                                                                        % no direct object
direct_objects           --> direct_object,       direct_objects.   
direct_object            --> separator(e),        noun_compound.
direct_object            --> separator(e),        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_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


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

adjectiv(Adjectiv) --> [Adjectiv], { member(Adjectiv, [     
     ijo,          % of something
     ike,          % bad, negative, wrong, evil, overly complex, (figuratively) unhealthy
     jaki,         % dirty, gross, filthy
     jan,          % human, somebody's, personal, of people
     jo,           % private, personal
     kili,         % fruity
     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
     mute,         % many, very, much, several, a lot, abundant, numerous, more
     nasa,         % silly, crazy, foolish, drunk, strange, stupid, weird
     pakala,       % destroyed, ruined, demolished, shattered, wrecked
     pona,         % good, simple, positive, nice, correct, right
     seli,         % hot, warm, cooked
     sewi,         % superior, elevated, religious, formal
     suli,         % big, tall, long, adult, important
     suno,         % sunny, sunnily
     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
%     wile          % necessary
 ])
}.

adverb(Adverb) --> [Adverb], { member(Adverb, [
     ijo,           % of something
     ike,           % bad, negative, wrong, evil, overly complex, (figuratively) unhealthy
     jaki,          % dirty, gross, filthy
     jan,           % human, somebody's, personal, of people
     kili,          % fruity
     lawa,          % main, leading, in charge
     lili,          % small, little, young, a bit, short, few, less
     lukin,         % visual(ly)
     moku,          % eating
     mute,          % many, very, much, several, a lot, abundant, numerous, more
     nasa,          % silly, crazy, foolish, drunk, strange, stupid, weird
     pakala,        % destroyed, ruined, demolished, shattered, wrecked
     pona,          % good, simple, positive, nice, correct, right
     seli,          % hot, warm, cooked
     sewi,          % superior, elevated, religious, formal
     suli,          % big, tall, long, adult, important
     suno,          % sunny, sunnily
     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
%     wile,           % necessary
 ])
}.

noun(Noun) --> [Noun], { member(Noun, [   
     ijo,          % thing, something, stuff, anything, object
     ike,          % negativity, badness, evil
     ilo,          % tool, device, machine, thing used for a specific purpose
     jaki,         % dirt, pollution, garbage, filth
     jan,          % person, people, human, being, somebody, anybody
     jo,           % having
     kili,         % fruit, pulpy vegetable, mushroom
     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
     mute,         % amount, quantity
     nasa,         % stupidity, foolishness, silliness, nonsense, idiocy, inanity, obtuseness, ninny, muddler
     pakala,       % blunder, accident, mistake, destruction, damage, breaking
     pipi,         % bug, insect, spider
     pona,         % good, simplicity, positivity
     seli,         % fire, warmth, heat
     sewi,         % high, up, above, top, over, on
     suli,         % size
     suno,         % sun, light
     telo,         % water, liquid, juice, sauce
     toki,         % language, speech, tongue, lingo, jargon, 
     tomo,         % indoor constructed space, e.g. house, home, room, building
     unpa          % sex, sexuality
%     wile          % desire, need, will
 ])
}.

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.
 ])
}.

verb_intransitive(Verb_intransitive) --> [Verb_intransitive], { member(Verb_intransitive, [
     ike,           % to be bad, to suck
     lukin,         % look, watch out, pay attention
     pakala,        % screw up, fall apart, break
     sewi,          % to get up 
     unpa           % have sex
 ])
}.

verb_transitive(Verb_transitive) --> [Verb_transitive], { member(Verb_transitive, [
     ijo,           % objectify
     ike,           % to make bad, to worsen, to have a negative effect upon
     jaki,          % pollute, dirty
     jan,           % personify, humanize, personalize
     jo,            % have, contain
     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
     mute,          % make many or much
     nasa,          % drive crazy, make weird
     pakala,        % screw up, fuck up, botch, ruin, break, hurt, injure, damage, spoil, ruin
     pona,          % improve, fix, repair, make good
     seli,          % heat, warm up, cook
     sewi,          % to lift
     suli,          % enlarge, lengthen
     suno,          % to light, to illumine
     telo,          % water, wash with water
     toki,          % speak, talk, say, pronounce, discourse
     unpa,          % have sex with, sleep with, fuck
     utala,         % hit, strike, attack, compete against
     wile           % (verb transitive) to want, need, wish, have to, must, will, should
 ])
}.

verb_pre(Verb_pre) --> [Verb_pre], { member(Verb_pre, [
     wile           % to want, need, wish, have to, must, will, should
 ])
}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For a user friendly input:
:- ['check_grammar.pro']. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

% Simple sentences with right grammar:
% Instead of "?- sentence([mi,moku,'.'],[])." you can use "check_grammar." 
% But "check_grammar." does not work in ​http://swish.swi-prolog.org. 

% For example the sentence "mi moku" has more than two possibilities (verb, noun, adverb).
?- check_grammar. 
|: mi moku. 
true ;
true ;
true ;

% Sentences with right grammar:

mi moku e moku mi. 
jan utala nasa mute li ike. 
jan li ike lukin. 
jan ni li pona lukin. 
jan ike li ni. 
jan lawa li lawa. 
jan lili li wile moku e telo moku lili. 
jan sewi li ilo. 
jan unpa li sewi. 
ma telo li ike mute. 
ma tomo mi li pona mute. 
mi mute li moku e telo nasa mute.   
ona mute li telo e tomo telo. 
tomo toki li pona. 
toki sina li telo. 
tomo mi li pona. 
ma sina li lili. 
telo ona li pona. 
len jan li ike mute. 
mi lawa pona e jan. 
mi utala ike. 
sina lukin sewi e suno. 
ona li wile mute e ni. 
mi mute li lukin lili e ona.   
mi jo e kili. 
ona li pona li lili. 
mi moku lili e kili lili. 
jan lawa li moku e telo jaki. 
mi wile e ilo moku. 
jan ike li utala e ona mute. 
jan ike ni li jo e len nasa. 
mi mute li moku e telo nasa mute. 
jan lili li lukin e jan suli. 
mi lukin sewi e tomo suli. 
seli suno li seli e tomo mi. 
jan lili li wile e telo kili. 
ona mute li nasa e jan suli. 
ni mute li ni mute.
mi moku e moku mute mi. 


% Wrong grammar:

?- check_grammar.
|: mi moku e moku mute mute mi. 
false.


?- check_grammar. 
|: jan sewi li ilo li. 
false

?- check_grammar. 
|: jan sewi e ilo li pona. 
false


% Possible queries with the syntax of the Difference Lists:

% nouns
?- sentence([mi,moku,e,X,'.'],[]).
% adjectives
?- sentence([mi,moku,e,moku,X,'.'],[]).
% adverbs
?- sentence([mi,moku,X,e,moku,'.'],[]).
?- adverb(X,_,_).
?- adverbs(X,[]).
?- adjectives(X,[]).
?- adjectives([mute,mute,mute],[]).
?- adjectives([utala,nasa,mute],[]).
?- adjectives([utala,nasa,ni],[]).
?- noun_phrase([jan,pona,li],[]).
?- direct_object([e,jan,pona],[]).
?- noun_phrase([jan,pakala,li],[]).
?- direct_object([e,jan,pakala],[]).
?- noun_phrase([ilo,moku,li],[]).
?- direct_object([e,ilo,moku],[]).
?- noun_phrase([jan,utala,nasa,mute,li],[]).
?- direct_object([e,jan,utala,nasa,mute],[]).

*/

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