Describing Toki Pona with the computer language Prolog and DCG

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

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

Postby janKipo » Thu Dec 17, 2015 10:57 pm

"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).

jan_Lope
Posts: 141
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

Postby jan_Lope » Wed Dec 23, 2015 8:12 am

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
http://rowa.giso.de/languages/toki-pona/ (Lessons)
http://rowa.giso.de/languages/toki-pona/dcg/ (Prolog and DCG)

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

janKipo
Posts: 2741
Joined: Fri Oct 09, 2009 2:20 pm

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

Postby janKipo » Wed Dec 23, 2015 10:42 am

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: 2741
Joined: Fri Oct 09, 2009 2:20 pm

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

Postby janKipo » Wed Dec 23, 2015 11:48 am

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.


Return to “ijo ante | miscellaneous | diversaj”

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests