aboutsummaryrefslogtreecommitdiff
path: root/README.org
blob: d99ae1ed2cef93f8536a10781e67385441ad9d3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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