From 6ecea40c849effd171c1d27c961f5c1ee100481f Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sun, 8 Nov 2026 09:02:38 +0300 Subject: publish --- README.org | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 README.org (limited to 'README.org') diff --git a/README.org b/README.org new file mode 100644 index 0000000..d99ae1e --- /dev/null +++ b/README.org @@ -0,0 +1,134 @@ +#+title: Context-free grammar for a subset of a natural language +#+subtitle: Slovak language -- future tense +#+date: 2025H1 + +* Task +:PROPERTIES: +:CUSTOM_ID: task +:END: +Construct a context‑free grammar for a subset of natural language +sentences, defined by a certain time. Based on the created grammar, +implement the generation of random sentences belonging to the grammar +and an algorithm for recognizing entered sentences. + +* Problem statement +:PROPERTIES: +:CUSTOM_ID: problem-statement +:END: +The future tense in the Slovak language is called /budúci čas/ or +/futúrum/. The word order in the Slovak language is more or less free; +changing it does not alter the meaning of the sentence, but changing +the word order can be used to emphasize certain words. The usual word +order is: subject + predicate + other members of the sentence + final +punctuation mark (end mark). + +In the Slovak language, it is possible to build complex sentences (or +compound sentences) --- these are sentences consisting of several +simple sentences and expressing one complete thought. They can be +both simple and complex.: +- A simple complex sentence: +- Contains two predicative units (two grammatical bases). + - Example: Jano sadol do auta a odišiel. + - Translation: Jano got into the car and drove away. +- Compound complex sentence: + - Contains more than two predicative units (three or more + grammatical bases). + - Example: Mama vedela, že príde, lebo mu verila. + - Translation: Mom knew that he would come because she believed in him. + +There are many different types of compound sentences, but they always +use conjunctions or connective expressions to join the parts of the +sentence. + +To examine the applicability of context-free grammars in working with +morphologically correct sentences, we will implement the agreement of +person and number between the subject and the verb of the sentence +fragment. + +To display the result of the syntax analyzer’s operation, we'll +automatically generate a parse tree. + +* Documentation +:PROPERTIES: +:CUSTOM_ID: documentation +:END: +The exported report can be found at [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-03/report.pdf][this link]]. + +* Showcase +:PROPERTIES: +:CUSTOM_ID: showcase +:END: +I wrote a custom BNF parser for this, [[https://git.michalec.dev/uni/term-06/math-logic/lab-03/tree/src/slovak-sentence.bnf][here]] is an example of what it +can parse. + +Listing [[generated]] shows the generated sentences. You can see that +they consist of a different number of fragments, have different +endings, and in some fragments the subject is omitted. + +#+name: generated +#+caption: Generated sentences +#+begin_src text +Ty preľúbiš Kraskov, ona bude vedieť počítači, podliečíte dážď, cibuľa vyhľadá kuratá, ale oni ovaria morami, ty očítaš knihe, ono bude vedieť umenieie. +Ja načítam Kraskovi, ty budeš mať ruka, keď budeš vedieť stretnutia, ty prelietaš huslu, ale ono bude vedieť princeznej, keď vy učítate mláďatá, ale ty budeš plávať bruchom? +My budeme rozumieť dlaňe, bude robiť oleja. +Púšť bude páliť chlápät, keď ono podrozumie úskalia, keď my budeme mať orchideu, vy budete maľovať lístím, ale oni budú vedieť chlápäťu, keď ukupuje vysvedčeniach, ja utelefonujem pozadím. +Ty budeš telefonovať Nikaragua, keď ono bude vedieť Kraskovi, my budeme rozumieť noci, ale budem maľovať dážďmi? +Vy zaľúbite stromoch, budeš páliť bratoch... +Ty budeš tancovať uja. +Ty ukúpiš huslovi, lístia budú fotografovať Kraskovi, vy opálite umenieia, polia budú učiť mláďa, keď obľúbim knihe, keď my budeme tancovať chvíľe, vy privaríte trolejbusy, ony budú liečiť kosťou, vy budete liečiť vodopádi, bude učiť chvíľou! +Vy budete kupovať pieseňi, ale dážďe budú prerábovať nástupištia, my budeme robiť huslom? +Budú robiť rodiny, keď ja pohľadám bratoch. +Budem umývať sluhami, keď ty obliečíš kráľovnej. +My vypracujeme reportáž, keď ony budú ľúbiť úskaliam, vy budete rozumieť šľachtičnej, zarobia auto? +Nástupište opozná brata, keď ja ukúpim dlaňi, ale ja budem ľúbiť vodopád, ona prevedie kuliami, ona preliečí pážaťa... +Vody obhľadajú kôša, ale vy budete rozumieť zmesiach, ale vyčítam báseňiach, vy budete rozumieť košeľíc... +Vy obrozumiete huslov... +My oučíme stromi, keď obtancuje pecou, ty budeš liečiť hrdinovi? +Ty budeš mailovať stredám? +#+end_src + +In listing [[no-match-first]], an example is provided that does not comply +with the grammar rules because the sentence starts with a lowercase +letter instead of a capital one. + +#+name: no-match-first +#+caption: A sentence that does not follow the rules of grammar -- does not start with a capital letter +#+begin_src text +Enter string to parse: my oučíme stromi, keď obtancuje pecou, ty budeš liečiť hrdinovi? +didn't match! +#+end_src + +Lisiting [[no-match-number]] shows an example that does not conform to the +grammar due to a mismatch in number between the subject and the verb. +/"My oučím"/ can be matched in number in the following ways: /"My +oučíme"/, /"Ja oučím"/. + +#+name: no-match-number +#+caption: A sentence that does not conform to grammar -- an inconsistent number. +#+begin_src text +Enter string to parse: My oučím stromi, keď obtancuje pecou, ty budeš liečiť hrdinovi? +didn't match! +#+end_src + +Listing [[match]] shows an example of a sentence that complies with the +grammar. And figure [[tree]] presents the automatically generated parse tree +for it. + +#+name: match +#+caption: A sentence that complies with the grammar +#+begin_src text +Enter string to parse: My oučíme stromi, keď obtancuje pecou, ty budeš liečiť hrdinovi? +matched +./tmp/tree.dot:1:0: info: generated parsing tree +#+end_src + +#+name: tree +#+caption: Parsing tree of the complient sentence +#+attr_html: :width 100% +[[https://git.michalec.dev/files/uni/term-06/math-logic/lab-03/tree.png][https://git.michalec.dev/files/uni/term-06/math-logic/lab-03/tree.png]] + +* Unlicense +:PROPERTIES: +:CUSTOM_ID: unlicense +:END: +#+include: UNLICENSE verse -- cgit v1.3.1