Describing Toki Pona with the computer language Prolog and DCG

Discuss any other topic in here.
Diskutu ĉiujn aliajn temojn ĉi tie.
janKipo
Posts: 3064
Joined: Fri Oct 09, 2009 2:20 pm

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by janKipo »

"modifier" works rather nicely in tp since there are no structural differences between adjectives and adverbs, only what they modify. I have a little trouble seeing 'suki' as an adverb in 'mi suli', say, since it seems only a noun is available to be modified. Similarly, 'ni li mi' for "this is mine", i.e. 'mi' as an adjective, seem rather odd, even in the face of 'ni li ijo mi'. One wouldn't, I think, take 'ni li jan' as "This is some man's".
for a conservative, by the book, grammarian, these are rather extreme moves from the norm (there may be hope for you yet).
User avatar
jan_Lope
Posts: 294
Joined: Sat Apr 06, 2013 1:30 pm
Location: mi lon ma tomo Pelin.
Contact:

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by jan_Lope »

toki!

I have modified all my DCG- and Prolog rules to support parse trees. This was a really stupid job. ;-)

"a a a!"

Code: Select all

?- check_grammar(Parse_tree).
|: a a a!
Parse_tree = (sentence_exclamatory(sentence_declarative([], interjection(interjection_word(a), interjection_word(a), interjection_word(a))), []), separator(!)) ;
"mi moku." has three grammar variants: "moku" as transitive verb, adjective or noun. Remember there is no "be" in Toki Pona.

Code: Select all

?- check_grammar(Parse_tree).
|: mi moku.

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(pronoun_no_li(pronoun(mi))), verb_phrase(verb_transitive_compound([], [], verb_transitive(moku), []), [], []))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(pronoun_no_li(pronoun(mi))), verb_phrase(verb_be(''), adjectives_at_least_one(adjectiv(moku)), adjectives([], [], [], [], [])))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(pronoun_no_li(pronoun(mi))), verb_phrase(verb_be(''), noun_compound(noun(moku), adjectives([], [], [], [], []), [])))), separator('.')) ;
For example: "tenpo pi suli mute li pona."

Code: Select all

?- check_grammar(Parse_tree).
|: tenpo pi suli mute li pona.

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(noun_compound(noun(tenpo), adjectives([], [], [], [], []), noun_pi_groups(noun_pi_group(separator(pi), noun(suli), adjectives_at_least_one(adjectiv(mute)), adjectives([], [], [], [], []), []))), [], separator(li)), verb_phrase(verb_transitive_compound([], [], verb_transitive(pona), []), [], []))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(noun_compound(noun(tenpo), adjectives([], [], [], [], []), noun_pi_groups(noun_pi_group(separator(pi), noun(suli), adjectives_at_least_one(adjectiv(mute)), adjectives([], [], [], [], []), []))), [], separator(li)), verb_phrase(verb_be(''), adjectives_at_least_one(adjectiv(pona)), adjectives([], [], [], [], [])))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(noun_compound(noun(tenpo), adjectives([], [], [], [], []), noun_pi_groups(noun_pi_group(separator(pi), noun(suli), adjectives_at_least_one(adjectiv(mute)), adjectives([], [], [], [], []), []))), [], separator(li)), verb_phrase(verb_be(''), noun_compound(noun(pona), adjectives([], [], [], [], []), [])))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(noun_compound(noun(tenpo), adjectives([], [], [], [], []), noun_pi_groups(noun_pi_group(separator(pi), noun(suli), adjectives_at_least_one(numeral(mute)), adjectives([], [], [], [], []), []))), [], separator(li)), verb_phrase(verb_transitive_compound([], [], verb_transitive(pona), []), [], []))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(noun_compound(noun(tenpo), adjectives([], [], [], [], []), noun_pi_groups(noun_pi_group(separator(pi), noun(suli), adjectives_at_least_one(numeral(mute)), adjectives([], [], [], [], []), []))), [], separator(li)), verb_phrase(verb_be(''), adjectives_at_least_one(adjectiv(pona)), adjectives([], [], [], [], [])))), separator('.')) ;

Parse_tree = (sentence_declarative([], [], sentence_simple(noun_phrase(noun_compound(noun(tenpo), adjectives([], [], [], [], []), noun_pi_groups(noun_pi_group(separator(pi), noun(suli), adjectives_at_least_one(numeral(mute)), adjectives([], [], [], [], []), []))), [], separator(li)), verb_phrase(verb_be(''), noun_compound(noun(pona), adjectives([], [], [], [], []), [])))), separator('.')) ;
An example for a "where" question: "mi toki wawa e ni: sina pali e mi tawa seme?"

Code: Select all

?- check_grammar(Parse_tree).
|: mi toki wawa e ni: sina pali e mi tawa seme?

Parse_tree = (sentence_interrogative([], [], sentence_simple(noun_phrase(pronoun_no_li(pronoun(mi))), verb_phrase(verb_transitive_compound([], [], verb_transitive(toki), adverbs(adverb(wawa))), direct_objects(direct_object(separator(e), pronoun_compound(pronoun(ni), adjectives([], [], [], [], [])), []), []), [])), separator(:), [], question(question_whereto(noun_phrase(pronoun_no_li(pronoun(sina))), verb_phrases(verb_phrase(verb_transitive_compound([], [], verb_transitive(pali), []), direct_objects(direct_object(separator(e), pronoun_compound(pronoun(...), adjectives(..., ..., ..., ..., ...)), []), []), []), []), preposition(tawa), [], question_word(seme))), []), separator(?)) ;

Parse_tree = (sentence_interrogative([], [], sentence_simple(noun_phrase(pronoun_no_li(pronoun(mi))), verb_phrase(verb_transitive_compound([], adverbs(adverb(toki)), verb_transitive(wawa), []), direct_objects(direct_object(separator(e), pronoun_compound(pronoun(ni), adjectives([], [], [], [], [])), []), []), [])), separator(:), [], question(question_whereto(noun_phrase(pronoun_no_li(pronoun(sina))), verb_phrases(verb_phrase(verb_transitive_compound([], [], verb_transitive(pali), []), direct_objects(direct_object(separator(e), pronoun_compound(pronoun(...), adjectives(..., ..., ..., ..., ...)), []), []), []), []), preposition(tawa), [], question_word(seme))), []), separator(?)) ;


Here an example of a sentences with wrong grammar. The first "pi" phrase is false, because it is used after a verb. "pi" is for compound nouns.

Code: Select all

?- check_grammar(Parse_tree).
|: mi ken ala weka pi tan lawa e kama ni pi lon lon pi selo insa oko mi pi pali mute.
false.

As you can see, the code and the output are not optimal. But it works. As you can see the parse tree show not evertime the missing "be".
I hope the code will be better Next Year. These parse trees could be the basis for semantic analyses and later for mechanical understandings and translations.

Here are the source codes:

http://rowa.giso.de/languages/toki-pona ... sson18.php
Last edited by jan_Lope on Mon Dec 28, 2015 3:54 pm, edited 2 times in total.
pona!
jan Lope
https://jan-lope.github.io
(Lessons and the Toki Pona Parser - A tool for spelling, grammar check and ambiguity check of Toki Pona)

On my foe list are the sockpuppets janKipo and janSilipu because of permanent spamming.
janKipo
Posts: 3064
Joined: Fri Oct 09, 2009 2:20 pm

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by janKipo »

It would be interesting to see just why the failed sentence fails, since it seems to pass (if just barely) a standard test or two. It is also unclear on a first careful reading what the differences are between the two runs on the second case. Still this is a very impressive job of mechanizing a very conservative tp grammar. Whether it could be extended -- by someone else, obviously -- to a more up-to-date version remains to be seen.
janKipo
Posts: 3064
Joined: Fri Oct 09, 2009 2:20 pm

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by janKipo »

More careful reading. In the question case, the second parse has 'toki' as an adverb to 'wawa' as a transitive verb. But tp is rigorously NA, so the adverb has to come after the verb. I suspect there are possible ambiguities here, but the grammar should not support this one.

In the second case. There are two ambiguities discovered: 'pona' as noun, adjective, and verb and 'mute' as adjective (I suppose "many") and numeral."twenty" So we have "The time of many/twenty bigshots is a plus/is good/heals." But nothing about a very long time or a time of great (or many) expansions, all of which are also in text and, indeed, among the more likely readings ("A long time is good" being the obvious case). This results from the very narrow 'pi' rule that Lope actually sticks to, unlike his sources: what comes after 'pi' can only be noun + adjective. never, say, verb + adverb nor adjective + adverb. And certainly never something+ another 'pi' phrase nor a prepositional phrase.
User avatar
jan_Lope
Posts: 294
Joined: Sat Apr 06, 2013 1:30 pm
Location: mi lon ma tomo Pelin.
Contact:

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by jan_Lope »

toki!

I made a complete redesign of the last script. First of all I made the source code clearer. After this I optimized the code. I put example sentences as comments before most the rules. Now you can get a clearer parse tree. With the former scripts you can only check the spelling and grammar of a sentence. Now you can determine the ambiguities of a sentence. For example the sentence "mi moku." With the semikolon you get the next possibility in Prolog.

Code: Select all

?- check_grammar(P).
|: mi moku.
P = s(dec(sim(np(sub(pronoun(mi))), vp(verb_tra(moku)))), sep('.')) ;
P = s(dec(sim(np(sub(pronoun(mi))), vp(be, obj_be(adjective(moku))))), sep('.')) ;
P = s(dec(sim(np(sub(pronoun(mi))), vp(be, obj_be(noun(moku))))), sep('.')) ;
false.
The sentence "mi moku e moku." is unambiguously.

Code: Select all

?- check_grammar(P).
|: mi moku e moku.
P = s(dec(sim(np(sub(pronoun(mi))), vp(verb_tra(moku), obj_d(sep(e), noun(moku))))), sep('.')) ;
false.
Please see the scripts
http://rowa.giso.de/languages/toki-pona ... sson18.php
Last edited by jan_Lope on Fri Jun 09, 2017 6:48 am, edited 1 time in total.
pona!
jan Lope
https://jan-lope.github.io
(Lessons and the Toki Pona Parser - A tool for spelling, grammar check and ambiguity check of Toki Pona)

On my foe list are the sockpuppets janKipo and janSilipu because of permanent spamming.
janKipo
Posts: 3064
Joined: Fri Oct 09, 2009 2:20 pm

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by janKipo »

Odd as always, but useful sometimes. The most unintelligible thing is why all these end in false, which seems to say they are not grammatical, which they clearly are (in several ways). I suppose "false" means something else, "the end" maybe. The other notable things is the insistence that there is an invisible "be" verb in those cases where the verb slot is filled by a noun or adjective. The noun or adjective is then an object of yet another sort. While invisible "be" verbs are sometimes legitimate (in Greek, for example, as in "athantos he psyche" in my youth), that is because there are visible ones elsewhere and clearly connected. There aren't in tp, not anywhere. To be sure, the "be" is not listed as a morpheme under vb but as the whole of the verb part of vp, instead of "verb_x(be)". Of course, it is also odd that, once you have this, we don't have separate ones for a noun object and an adjective object. That is, this is just a borrowing of English "be" (and German "sein" and so on for many SAE languages). Given how conservative Lope usually is, and how fiercely loyal to (his vision of) Sonja, these are rather peculiar.
User avatar
jan_Lope
Posts: 294
Joined: Sat Apr 06, 2013 1:30 pm
Location: mi lon ma tomo Pelin.
Contact:

Re: Describing Toki Pona with the computer language Prolog and DCG

Post by jan_Lope »

Update:

Rules for paragraphs added.

http://rowa.giso.de/languages/toki-pona ... sson18.php
pona!
jan Lope
https://jan-lope.github.io
(Lessons and the Toki Pona Parser - A tool for spelling, grammar check and ambiguity check of Toki Pona)

On my foe list are the sockpuppets janKipo and janSilipu because of permanent spamming.
Post Reply