Difference between revisions of "Apertium, Tvorba novej dvojice jazykov"

From Apertium
Jump to navigation Jump to search
Line 632: Line 632:
 
^see<vblex><pri><p1><sg>$^@
 
^see<vblex><pri><p1><sg>$^@
 
</pre>
 
</pre>
Analýza zbehla korektne, no keď skúsime generovať tvar z tohoto, dostaneme '#', ako vidíme nižšie:
+
Analýza zbehla korektne, no keď skúsime generovať výsledný tvar z tohoto, dostaneme '#', ako vidíme nižšie:
 
We get the analysis passed through correctly, but when we try and generate a surface form from this, we get a '#', like below:
 
We get the analysis passed through correctly, but when we try and generate a surface form from this, we get a '#', like below:
 
<pre>
 
<pre>
Line 641: Line 641:
 
#see\@
 
#see\@
 
</pre>
 
</pre>
  +
'#' znamená, že generátor nemôže vygenerovať správny lexikálny tvar, pretože ho neobsahuje. Prečo sa to deje?
 
This '#' means that the generator cannot generate the correct lexical form because it does not contain it. Why is this?
 
This '#' means that the generator cannot generate the correct lexical form because it does not contain it. Why is this?
   
  +
V podstate, analýza nenašla zhodu pre 'see', pretože v slovníku je see<vblex><pri>, ale see, ktoré dostane analyzátor prenosom je see<vblex><pri><p1><sg>. Srbochorvátska strana slovníka poskytuje viac informácií ako anglická strana vyžaduje. Môžete to otestovať pridaním chýbajúcich symbolov do anglického slovníka a opätovným testom.
 
Basically the analyses don't match, the 'see' in the dictionary is see<vblex><pri>, but the see delivered by the transfer is see<vblex><pri><p1><sg>. The Serbo-Croatian side has more information than the English side requires. You can test this by adding the missing symbols to the English dictionary, and then recompiling, and testing again.
 
Basically the analyses don't match, the 'see' in the dictionary is see<vblex><pri>, but the see delivered by the transfer is see<vblex><pri><p1><sg>. The Serbo-Croatian side has more information than the English side requires. You can test this by adding the missing symbols to the English dictionary, and then recompiling, and testing again.
   
  +
Lepší spôsob je však pomocou nového pravidla. Otvoríme teda súbor s pravidlami (<code>apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin</code> ak ste zabudli).
 
However, a more paradigmatic way of taking care of this is by writing a rule. So, we open up the rules file (<code>apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin</code> in case you forgot).
 
However, a more paradigmatic way of taking care of this is by writing a rule. So, we open up the rules file (<code>apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin</code> in case you forgot).
   
  +
Potrebujeme pridať novú kategóriu pre sloveso ('verb').
 
We need to add a new category for 'verb'.
 
We need to add a new category for 'verb'.
 
<pre>
 
<pre>
Line 653: Line 657:
 
</def-cat>
 
</def-cat>
 
</pre>
 
</pre>
  +
  +
Musíme tiež pridať atribúty pre osobu a čas. Spravíme to zatiaľ veľmi jednoduché, môžete pridať aj p2 a p3, ale ja budem šetriť miestom.
 
We also need to add attributes for tense and for person. We'll make it really simple for now, you can add p2 and p3, but I won't in order to save space.
 
We also need to add attributes for tense and for person. We'll make it really simple for now, you can add p2 and p3, but I won't in order to save space.
 
<pre>
 
<pre>
Line 663: Line 669:
 
</def-attr>
 
</def-attr>
 
</pre>
 
</pre>
  +
Teraz by sme mali aj pridať atribút slovesám.
 
We should also add an attribute for verbs.
 
We should also add an attribute for verbs.
 
<pre>
 
<pre>
Line 669: Line 676:
 
</def-attr>
 
</def-attr>
 
</pre>
 
</pre>
  +
A teraz pravidlo:
 
Now onto the rule:
 
Now onto the rule:
 
<pre>
 
<pre>
Line 686: Line 694:
 
</rule>
 
</rule>
 
</pre>
 
</pre>
  +
Keď se skúsili zakomentovať 'clip' tagy v predchádzajúcom pravidle, a tie potom zmizly z prenosu, tak tu robíme prakticky to isté. Vezmeme sloveso s plnou analýzou, ale vrátime len jej časť (lemma + tag slovesa + tag času).
 
Remember when you tried commenting out the 'clip' tags in the previous rule example and they disappeared from the transfer, well, thats pretty much what we're doing here. We take in a verb with a full analysis, but only output a partial analysis (lemma + verb tag + tense tag).
 
Remember when you tried commenting out the 'clip' tags in the previous rule example and they disappeared from the transfer, well, thats pretty much what we're doing here. We take in a verb with a full analysis, but only output a partial analysis (lemma + verb tag + tense tag).
   
  +
Ak teda teraz rekompilujeme, dostaneme:
 
So now, if we recompile that, we get:
 
So now, if we recompile that, we get:
 
<pre>
 
<pre>
Line 695: Line 705:
 
^see<vblex><pri>$^@
 
^see<vblex><pri>$^@
 
</pre>
 
</pre>
and:
+
a:
 
<pre>
 
<pre>
 
$ echo "vidim" | lt-proc sh-en.automorf.bin | \
 
$ echo "vidim" | lt-proc sh-en.automorf.bin | \
Line 703: Line 713:
 
see\@
 
see\@
 
</pre>
 
</pre>
  +
Teraz to skúste s 'vidimo' (we see), či dostávame správny výstup.
 
Try it with 'vidimo' (we see) to see if you get the correct output.
 
Try it with 'vidimo' (we see) to see if you get the correct output.
   
  +
Teraz to skúste s "vidim gramofone":
 
Now try it with "vidim gramofone":
 
Now try it with "vidim gramofone":
 
<pre>
 
<pre>
Line 715: Line 727:
   
 
==But what about personal pronouns?==
 
==But what about personal pronouns?==
  +
==Ale čo osobné zámená?==
   
  +
To je úžasné, ale stále nám chýba osobné zámeno potrebné v Angličtine. Aby sme ho pridali, musíme najprv pozmeniť anglický morfologický slovník.
 
Well, thats great, but we're still missing the personal pronoun that is necessary in English. In order to add it in, we first need to edit the English morphological dictionary.
 
Well, thats great, but we're still missing the personal pronoun that is necessary in English. In order to add it in, we first need to edit the English morphological dictionary.
   
  +
Najprv musíme pridať potrebné symboly:
 
As before, the first thing to do is add the necessary symbols:
 
As before, the first thing to do is add the necessary symbols:
 
<pre>
 
<pre>
Line 723: Line 738:
 
<sdef n="subj"/>
 
<sdef n="subj"/>
 
</pre>
 
</pre>
  +
prn je prísudok, a subj je podmet.
 
Of the two symbols, prn is pronoun, and subj is subject (as in the subject of a sentence).
 
Of the two symbols, prn is pronoun, and subj is subject (as in the subject of a sentence).
   
  +
Pretože tu nie je žiaden koreň, alebo 'lemma' pre osobné zámená, pridáme len nasledovné paradigmy:
 
Because there is no root, or 'lemma' for personal subject pronouns, we just add the pardef as follows:
 
Because there is no root, or 'lemma' for personal subject pronouns, we just add the pardef as follows:
 
<pre>
 
<pre>
Line 731: Line 748:
 
</pardef>
 
</pardef>
 
</pre>
 
</pre>
  +
Kde 'prsubj' je 'osobný podmet'. Zvyšok z nich (You, We atď.) je ponechaný ako cvičenie pre čitateľa.
 
With 'prsubj' being 'personal subject'. The rest of them (You, We etc.) are left as an exercise to the reader.
 
With 'prsubj' being 'personal subject'. The rest of them (You, We etc.) are left as an exercise to the reader.
   
  +
Môžeme pridať záznam do hlavnej sekcie:
 
We can add an entry to the main section as follows:
 
We can add an entry to the main section as follows:
 
<pre>
 
<pre>
 
<e lm="personal subject pronouns"><i/><par n="prsubj__prn"/></e>
 
<e lm="personal subject pronouns"><i/><par n="prsubj__prn"/></e>
 
</pre>
 
</pre>
  +
Takže, rekompilujte a testujte, mali by sme dostať niečo ako:
 
So, save, recompile and test, and we should get something like:
 
So, save, recompile and test, and we should get something like:
 
<pre>
 
<pre>
Line 742: Line 762:
 
^I/PRPERS<prn><subj><p1><sg>$
 
^I/PRPERS<prn><subj><p1><sg>$
 
</pre>
 
</pre>
  +
Poznámka: Je to veľkými písmenami pretože 'I' je veľkými písmenami.
 
 
(Note: it's in capitals because 'I' is in capitals).
 
(Note: it's in capitals because 'I' is in capitals).
   
  +
Teraz potrebujeme doplniť 'verb' pravidlo, aby vracalo osobné zámeno spolu so správnym tvarom slovesa.
 
Now we need to amend the 'verb' rule to output the subject personal pronoun along with the correct verb form.
 
Now we need to amend the 'verb' rule to output the subject personal pronoun along with the correct verb form.
   
  +
Najprv, pridáme kategóriu (čo sa už zrejme stáva trochu obyčajné):
 
First, add a category (this must be getting pretty pedestrian by now):
 
First, add a category (this must be getting pretty pedestrian by now):
 
<pre>
 
<pre>
Line 753: Line 775:
 
</def-cat>
 
</def-cat>
 
</pre>
 
</pre>
  +
Teraz pridáme typy prísudkov ako atribúty. Môžeme aj pridať typ 'obj', hoci ho zatiaľ nebudeme potrebovať:
 
Now add the types of pronoun as attributes, we might as well add the 'obj' type as we're at it, although we won't need to use it for now:
 
Now add the types of pronoun as attributes, we might as well add the 'obj' type as we're at it, although we won't need to use it for now:
 
<pre>
 
<pre>
Line 760: Line 783:
 
</def-attr>
 
</def-attr>
 
</pre>
 
</pre>
  +
A teraz vstup pre pravidlo:
 
And now to input the rule:
 
And now to input the rule:
 
<pre>
 
<pre>
Line 785: Line 809:
 
</rule>
 
</rule>
 
</pre>
 
</pre>
  +
Toto je prakticky rovnalé pravidlo ako vyššie, spravili sme len zopár malých zmien.
 
This is pretty much the same rule as before, only we made a couple of small changes.
 
This is pretty much the same rule as before, only we made a couple of small changes.
   
  +
Potrebovali sme výstup:
 
We needed to output:
 
We needed to output:
 
<pre>
 
<pre>
 
^prpers<prn><subj><p1><sg>$ ^see<vblex><pri>$
 
^prpers<prn><subj><p1><sg>$ ^see<vblex><pri>$
 
</pre>
 
</pre>
  +
tak aby mohol generátor vybrať správny prísudok a správny tvar slovesa.
 
so that the generator could choose the right pronoun and the right form of the verb.
 
so that the generator could choose the right pronoun and the right form of the verb.
   
  +
Takže, rýchly prehlad:
 
So, a quick rundown:
 
So, a quick rundown:
  +
  +
* <code><lit></code>, vypíše reťazec, v tomto prípade "prpers"
  +
* <code><lit-tag></code>, vypíše tag, pretože nemôžeme získať tagy zo slovesa, pridáme teda vlastné, "prn" pre prísudok, a "subj" pre podmet.
  +
* <code><b/></code>, vypíše medzeru.
   
 
* <code><lit></code>, prints a literal string, in this case "prpers"
 
* <code><lit></code>, prints a literal string, in this case "prpers"
Line 799: Line 831:
 
* <code><b/></code>, prints a blank, a space.
 
* <code><b/></code>, prints a blank, a space.
   
  +
Všimnite si že sme získali informáciu pre číslo a pád priamo zo slovesa.
 
Note that we retrieved the information for number and tense directly from the verb.
 
Note that we retrieved the information for number and tense directly from the verb.
   
  +
Ak teda rekompilujeme a otestujeme znovu:
 
So, now if we recompile and test that again:
 
So, now if we recompile and test that again:
 
<pre>
 
<pre>
Line 809: Line 843:
 
I see gramophones
 
I see gramophones
 
</pre>
 
</pre>
  +
Čo, hoci nie je práve oceňované dielo (ako preklad tohoto článku), je cekom presné.
 
Which, while it isn't exactly prize-winning prose (much like this HOWTO), is a fairly accurate translation.
 
Which, while it isn't exactly prize-winning prose (much like this HOWTO), is a fairly accurate translation.
   
  +
==Povedzte mi o svojom digitálnom gramofóne (slovné spojenia)==
 
==So tell me about the record player (Multiwords)==
 
==So tell me about the record player (Multiwords)==
   
  +
Hoci je gramofón anglické slovo, nie je to najpresnejší preklad. Gramofón väčšinou označuje veľmi starý druh prístroja, s ihlou a bez zosilovača. Lepší preklad by bol 'record player'. Je to viacslovné spojenie, no môžeme ho považovať za jedno slovo, ak použijeme konštrukciu multiword.
 
While gramophone is an English word, it isn't the best translation. Gramophone is typically used for the very old kind, you know with the needle instead of the stylus, and no powered amplification. A better translation would be 'record player'. Although this is more than one word, we can treat it as if it is one word by using multiword (multipalabra) constructions.
 
While gramophone is an English word, it isn't the best translation. Gramophone is typically used for the very old kind, you know with the needle instead of the stylus, and no powered amplification. A better translation would be 'record player'. Although this is more than one word, we can treat it as if it is one word by using multiword (multipalabra) constructions.
   
  +
Nepotrebujeme meniť srbochorvátsky slovník, stačí len anglický a bilingválny.
 
We don't need to touch the Serbo-Croatian dictionary, just the English one and the bilingual one, so open it up.
 
We don't need to touch the Serbo-Croatian dictionary, just the English one and the bilingual one, so open it up.
   
  +
Plurál 'record player' je 'record players', takže používa rovnakú paradigmu ako gramopnohe (gramophone__n) — len pridávame 's'. Pridáme teda len nový záznam do hlavnej sekcie.
 
The plural of 'record player' is 'record players', so it takes the same paradigm as gramophone (gramophone__n) — in that we just add 's'. All we need to do is add a new element to the main section.
 
The plural of 'record player' is 'record players', so it takes the same paradigm as gramophone (gramophone__n) — in that we just add 's'. All we need to do is add a new element to the main section.
 
<pre>
 
<pre>
 
<e lm="record player"><i>record<b/>player</i><par n="gramophone__n"/></e>
 
<e lm="record player"><i>record<b/>player</i><par n="gramophone__n"/></e>
 
</pre>
 
</pre>
  +
Jediný rozdiel je použite tagu <b/>, ktorý tiež nie je pre nás úplne nový.
 
The only thing different about this is the use of the <b/> tag, although this isn't entirely new as we saw it in use in the rules file.
 
The only thing different about this is the use of the <b/> tag, although this isn't entirely new as we saw it in use in the rules file.
   
  +
Takže, znovu rekompilujeme a testujeme:
 
So, recompile and test in the orthodox fashion:
 
So, recompile and test in the orthodox fashion:
 
<pre>
 
<pre>
Line 831: Line 872:
 
I see record players
 
I see record players
 
</pre>
 
</pre>
  +
  +
Perfektné. Veľká výhoda používania konštrukcie multiword je preklad idióm bez potreby prekladať jednotlivé slová. Napríklad anglická fráza "at the moment" by bola preložená ako "trenutno" (trenutak = ''chvíľa'', trenutno je odvodená príslovnka) &mdash; nebolo by možné preložiť túto anglickú frázu slovo po slove.
 
Perfect. A big benefit of using multiwords is that you can translate idiomatic expressions verbatim, without having to do word-by-word translation. For example the English phrase, "at the moment" would be translated into Serbo-Croatian as "trenutno" (trenutak = ''moment'', trenutno being adverb of that) &mdash; it would not be possible to translate this English phrase word-by-word into Serbo-Croatian.
 
Perfect. A big benefit of using multiwords is that you can translate idiomatic expressions verbatim, without having to do word-by-word translation. For example the English phrase, "at the moment" would be translated into Serbo-Croatian as "trenutno" (trenutak = ''moment'', trenutno being adverb of that) &mdash; it would not be possible to translate this English phrase word-by-word into Serbo-Croatian.
   
  +
==Ako sa vysporiadať s obmenami==
 
==Dealing with minor variation==
 
==Dealing with minor variation==
  +
  +
Srbochorváčtina má zopár spôsobov, ako zapísať každé slovo, kvôli nárečovým odchýlkam. Má totiž fonetický systém písania, teda píš ako počuješ. Napríklad, ľudia hovoriaci po Ijekavsky povedia "rječnik", kým ľudia hovoriaci po Ekavsky povedia "rečnik", čo odráža odlišnosti vo výslovnosti protoslovanskej samohlásky ''yat''.
   
 
Serbo-Croatian typically has a few ways of writing each word because of dialectal variation. It has a cool phonetic writing system so you write how you speak. For example, people speaking in Ijekavian would say "rječnik", while someone speaking Ekavian would say "rečnik", which reflects the differences in pronunciation of the proto-Slavic vowel ''yat''.
 
Serbo-Croatian typically has a few ways of writing each word because of dialectal variation. It has a cool phonetic writing system so you write how you speak. For example, people speaking in Ijekavian would say "rječnik", while someone speaking Ekavian would say "rečnik", which reflects the differences in pronunciation of the proto-Slavic vowel ''yat''.
   
  +
===Analýza===
 
===Analysis===
 
===Analysis===
   
  +
Mala by byť celkom jednoduchá cesta, ako sa s týmto vysporiadať, a to pomocou paradigiem. Paradigmy niesu pužívané len pre pridávanie gramatických symbolov, ale môžu byť taktiež použité na zámenu znakov za iné. Napríklad, táto paradigma akceptuje aj "e" aj "je" v analýze. Mala by byť jednojazyčnom srbochorvátskom slovíku.
 
There should be a fairly easy way of dealing with this, and there is, using paradigms again. Paradigms aren't only used for adding grammatical symbols, but they can also be used to replace any character/symbol with another. For example, here is a paradigm for accepting both "e" and "je" in the analysis. The paradigm should, as with the others go into the monolingual dictionary for Serbo-Croatian.
 
There should be a fairly easy way of dealing with this, and there is, using paradigms again. Paradigms aren't only used for adding grammatical symbols, but they can also be used to replace any character/symbol with another. For example, here is a paradigm for accepting both "e" and "je" in the analysis. The paradigm should, as with the others go into the monolingual dictionary for Serbo-Croatian.
   
Line 858: Line 906:
 
</pre>
 
</pre>
   
  +
Potom v hlavnej sekcii:
 
Then in the "main section":
 
Then in the "main section":
   
Line 864: Line 913:
 
</pre>
 
</pre>
   
  +
Toto nám umožnuje analyzovať obe tvary. Na tvorbu oboch tvarov by bolo potrebné viac práce.
 
This only allows us to analyse both forms however... more work is necessary if we want to generate both forms.
 
This only allows us to analyse both forms however... more work is necessary if we want to generate both forms.
   
===Generation===
+
===Tvorba===
   
==See also==
+
==Pozri tiež==
   
 
*[[Building dictionaries]]
 
*[[Building dictionaries]]

Revision as of 21:08, 26 November 2010

Apertium - Tvorba novej dvojice jazykov

Tento dokument popíše, ako vytvorit novú dvojicu jazykov pre Apertium, systém pre strojový preklad, od začiatku. This HOWTO document will describe how to start a new language pair for the Apertium machine translation system from scratch.

Nepredpokladá žiadne znalosti ohľadom ligvistiky alebo strojového prekladu okrem schopnosti rozlišovať slovné druhy. It does not assume any knowledge of linguistics, or machine translation above the level of being able to distinguish nouns from verbs (and prepositions etc.)

Úvod

Introduction

Apertium je, ako ste si už pravdepodobne uvedomili, systém pre strojový preklad. Nie je to však presné, ide o platformu pre strojový preklad. Poskytuje podklad a nástroje ktoré vám umožnia vybudovať si takýto systém. Jediné, čo musíte robiť, je poskytnúť mu dáta, obsahujúce trojicu slovníkov a pravidlá pre poradie slov a gramatiku.

Apertium is, as you've probably realised by now, a machine translation system. Well, not quite, it's a machine translation platform. It provides an engine and toolbox that allow you to build your own machine translation systems. The only thing you need to do is write the data. The data consists, on a basic level, of three dictionaries and a few rules (to deal with word re-ordering and other grammatical stuff).

Pre podrobnejší úvod do fungovania celého systému, na stránke Publications nájdete výborné zdroje. For a more detailed introduction into how it all works, there are some excellent papers on the Publications page..

Čo budete potrebovať

You will need

  • lttoolbox (>= 3.0.0)
  • libxml utils (xmllint etc.)
  • apertium (>= 3.0.0)
  • textový editor (alebo XML editor)
  • lttoolbox (>= 3.0.0)
  • libxml utils (xmllint etc.)
  • apertium (>= 3.0.0)
  • a text editor (or a specialised XML editor if you prefer)

Inštaláciu týchto programov popisuje dokumentácia projektu Apertium. This document will not describe how to install these packages, for more information please see the documentation section of the Apertium website.

Z čoho pozostáva jazyková dvojica?

What does a language pair consist of?

Apertium je shallow-transfer systém pre strojový preklad. To znamená, že pracuje zo slovníkmi a pravidlami na preklad, na rozdiel od deep-transfer systémov, ktoré vykonávajú plnú syntaktickú analýzu. Pravidlá obyčajne popisujú operácie nad skupinami lexikálnych jednotiek, nie nad syntaktickými stromami. V podstate obsahuje trojicu slovníkov:

  1. Morfologický slovník pre jazyk xx obsahuje pravidlá pre skloňovanie a časovanie slov v jazyku xx. V našom príklade sa bude nazývať apertium-sh-en.sh.dix
  2. Morfologický slovník pre jazyk yy obsahuje pravidlá pre skloňovanie a časovanie slov v jazyku yy. V našom príklade sa bude nazývať code>apertium-sh-en.en.dix
  3. Dvojjazyčný slovník obsahuje spojenia medzi slovami a symbolmi oboch jazykov. V našom príklade sa bude nazývať apertium-sh-en.sh-en.dix

Apertium is a shallow-transfer type machine translation system. Thus, it basically works on dictionaries and shallow transfer rules. In operation, shallow-transfer is distinguished from deep-transfer in that it doesn't do full syntactic parsing, the rules are typically operations on groups of lexical units, rather than operations on parse trees. At a basic level, there are three main dictionaries:

  1. The morphological dictionary for language xx: this contains the rules of how words in language xx are inflected. In our example this will be called: apertium-sh-en.sh.dix
  2. The morphological dictionary for language yy: this contains the rules of how words in language yy are inflected. In our example this will be called: apertium-sh-en.en.dix
  3. Bilingual dictionary: contains correspondences between words and symbols in the two languages. In our example this will be called: apertium-sh-en.sh-en.dix

Oba jazyky vo dvojici môžu byť rovnako cieľ aj zdroj prekladu. In a translation pair, both languages can be either source or target for translation, these are relative terms.

Taktiež existujú dva súbory pre pravidlá prepisu. Tieto pravidlá riadia poradie slov vo vete, ako napr. chat noir -> cat black -> black cat. Naviac riadia zhody v rode, čísle atď. Tieto pravidlá môžu vkladať alebo mazať lexikálne položky, ako bude popísané neskôr. Tieto súbory sú:

There are also two files for transfer rules. These are the rules that govern how words are re-ordered in sentences, e.g. chat noir -> cat black -> black cat. It also governs agreement of gender, number etc. The rules can also be used to insert or delete lexical items, as will be described later. These files are:

  • pravidlá pre prepis z jazyka xx do jazyka yy, popisujúce zmeny jazyka xx pri preklade do jazyka yy. V našom príklade budú v súbore apertium-sh-en.sh-en.t1x
  • pravidlá pre prepis z jazyka yy do jazyka xx, popisujúce zmeny jazyka yy pri preklade do jazyka xx. V našom príklade budú v súbore apertium-sh-en.en-sh.t1x
  • language xx to language yy transfer rules: this file contains rules for how language xx will be changed into language yy. In our example this will be: apertium-sh-en.sh-en.t1x
  • language yy to xx language transfer rules: this file contains rules for how language yy will be changed into language xx. In our example this will be: apertium-sh-en.en-sh.t1x

Veľké množstvo jazykových dvojíc má aj ďalšie súbory, no tu sa nimi nebudeme zaoberať. Vyššie popísané súbory stačia na vytvorenie funkčného systému. Many of the language pairs currently available have other files, but we won't cover them here. These files are the only ones required to generate a functional system.

Dvojica jazykov

Language pair

Ako ste už možno zistili z názvov súborov, tento návod použije ako príklad Srbochorváčtiny do Angličtiny, aby vysvetlil spôsob tvorby základného systému. Nie je to ideálna dvojica, pretože systém pracuje lepšie pre príbuzné jazyky, no nebude to problém pre jednoduché príklady použité v dokumente. As may have been alluded to by the file names, this HOWTO will use the example of translating Serbo-Croatian to English to explain how to create a basic system. This is not an ideal pair, since the system works better for more closely related languages. This shouldn't present a problem for the simple examples given here.

Krátka poznámka o pojmoch

A brief note on terms

Je zopár pojmov, ktoré treba chápať pre tvorbu novej dvojice. There are number of terms that will need to be understood before we continue.

Prvý je lemma. Lemma je základný tvar slova, ako býva uvedená v slovníkoch. Napríklad lemma slova mačkami je mačka. V Angličtine to bude väčšinou jednotné číslo podstatného mena, alebo neurčitok slovesa bez to. The first is lemma. A lemma is the citation form of a word. It is the word stripped of any grammatical information. For example, the lemma of the word cats is cat. In English nouns this will typically be the singular form of the word in question. For verbs, the lemma is the infinitive stripped of to, e.g. the lemma of was would be be.

Ďalší pojem je symbol. V kontexte systému Apertium, symbol je gramatická vlastnosť. Slovo mačky je množné číslo podstatného mena, preto bude mať symbly podstatné meno a plurál. Na vstupe a výstupe modulov pre Apertium, symboly bývajú väčšinou určené medzi ostrými zátvorkami: The second is symbol. In the context of the Apertium system, symbol refers to a grammatical label. The word cats is a plural noun, therefore it will have the noun symbol and the plural symbol. In the input and output of Apertium modules these are typically given between angle brackets, as follows:

  • <n>; for noun.
  • <pl>; for plural.

Iné príklady symbolov sú <sg> singular, <p1> prvá osoba, atď. Napísané v ostrých zátvorkách, symboly môžu byť označované ako tagy. Je vhodné poznamenať, že v časti dvojíc jazykov sú menjá symbolov vytvorené skrátením Katalánčiny, ako napríklad vbhaver, vb (verb) a haver ("mať" v Katalánčine). Symboly sú definované v <sdef> tagoch a používane v <s> tagoch. Other examples of symbols are <sg> singular, <p1> first person, <pri> present indicative, etc. When written in angle brackets, the symbols may also be referred to as tags. It is worth noting that in many of the currently available language pairs the symbol definitions are acronyms or contractions of words in Catalan. For example, vbhaver — from vb (verb) and haver ("to have" in Catalan). Symbols are defined in <sdef> tags and used in <s> tags.

Tretí výraz je paradigma. V systéme Apertium, paradigma popisuje príklad, ako sa určitá skupina slov ohýba. V morfologickom slovníku sú lemmy spojené s paradigmami, ktoré nám dovolujú popisovať, ako sa daná lema ohýba bez toho, aby sme museli vypisovať všetky koncovky. The third word is paradigm. In the context of the Apertium system, paradigm refers to an example of how a particular group of words inflect. In the morphological dictionary, lemmas (see above) are linked to paradigms that allow us to describe how a given lemma inflects without having to write out all of the endings.

Ako príklad užitočnosti paradigiem, keby sme chceli uložiť dve anglické prídavné mená happy a lazy, namiesto okladania dva krát tej istej veci: An example of the utility of this is, if we wanted to store the two adjectives happy and lazy, instead of storing two lots of the same thing:

  • happy, happ (y, ier, iest)
  • lazy, laz (y, ier, iest)

Môžeme jednoducho uložiť jedno a potom povedať "lazy, skloňuje sa ako happy", ale aj shy inflects like happy", "naughty inflects like happy", "friendly inflects like happy", atď. V tomto príklade, happy by bolo paradigmou, modelom pre ohýbanie iných slov. Presná definícia bude vysvetlená o chvíľu. Paradigmy sú definovaný tagom <pardef>, používané tagom <par>. We can simply store one, and then say "lazy, inflects like happy", or indeed "shy inflects like happy", "naughty inflects like happy", "friendly inflects like happy", etc. In this example, happy would be the paradigm, the model for how the others inflect. The precise description of how this is defined will be explained shortly. Paradigms are defined in <pardef> tags, and used in <par> tags.

Začíname

Getting started

Jednojazyčné slovníky

Monolingual dictionaries

See also: List of dictionaries and Incubator

Začnime tvorbou nášho prvého slovníka. Slovník je XML súbor. Spustite váš textový editor a napíšte: Let's start by making our first source language dictionary. The dictionary is an XML file. Fire up your text editor and type the following:


<?xml version="1.0" encoding="UTF-8"?>
<dictionary>

</dictionary>

Zatiaľ tento súbor definuje, že chcemem vetvoriť slovník. Aby bol užitočný, treba pridať viac vstupov, prvým je abeceda. Definuje množinu písmen použivaných v Srbochorvátskom slovníku. Bude vyzerať nasledovne, obsahuje všetky znaky Srbochorvátskej abecedy: So, the file so far defines that we want to start a dictionary. In order for it to be useful, we need to add some more entries, the first is an alphabet. This defines the set of letters that may be used in the dictionary, for Serbo-Croatian. It will look something like the following, containing all the letters of the Serbo-Croatian alphabet:

<alphabet>ABCČĆDDžĐEFGHIJKLLjMNNjOPRSŠTUVZŽabcčćddžđefghijklljmnnjoprsštuvzž</alphabet>

Abecedu umiestnite pod tag <dictionary>. Place the alphabet below the <dictionary> tag.

Ďalej musíme definovať symboly. Začnime so základmi, podstatné meno (n) môže byť v singulári (sg) alebo v pluráli (pl). Next we need to define some symbols. Let's start off with the simple stuff, noun (n) in singular (sg) and plural (pl).

<sdefs>
   <sdef n="n"/>
   <sdef n="sg"/>
   <sdef n="pl"/>
</sdefs>

Mená symoblov nemusia byť krátke, no pretože ich budete opakovane písať, je výhodné ich skrátiť. The symbol names do not have to be so small, in fact, they could just be written out in full, but as you'll be typing them a lot, it makes sense to abbreviate.

Naneštastie, nie je to také jednoduché, podstatné mená v Srbochorváčtine skloňuje okrem čísla aj rod a pád. Pre náš príklad však budeme predpokladať, že podstatné mená budú mužského rodu v nominatíve (kompletný príklad nájdete na konci dokumentu). Unfortunately, it isn't quite so simple, nouns in Serbo-Croatian inflect for more than just number, they also inflect for gender and case. However, we'll assume for the purposes of this example that the noun is masculine and in the nominative case (a full example may be found at the end of this document).

Ďalej definujeme časť obsahujúcu paradigmy: The next thing is to define a section for the paradigms,

<pardefs>

</pardefs>

a slovníkovú časť: and a dictionary section:

<section id="main" type="standard">

</section>

Sú dva typy sekcií, štandardná sekcia obsahujúca slová, príklonky atď. Druhý typ je inconditional section, ktorá obyčajne obsahuje iterpunkciu atp. Takúto sekciu ešte nemáme. There are two types of sections, the first is a standard section, that contains words, enclitics, etc. The second type is an inconditional section which typically contains punctuation, and so forth. We don't have an inconditional section here.

Takže, náš súbor by mal vyzerať nasledovne: So, our file should now look something like:

<?xml version="1.0" encoding="UTF-8"?>
<dictionary>
   <sdefs>
     <sdef n="n"/>
     <sdef n="sg"/>
     <sdef n="pl"/>
   </sdefs>
   <pardefs>

   </pardefs>
   <section id="main" type="standard">

   </section>
</dictionary>

Keď teraz máme kostru, môžeme začať pridaním podstatného mena. Podstatné meno bude 'gramofon' (čo znamená gramofón). Now we've got the skeleton in place, we can start by adding a noun. The noun in question will be 'gramofon' (which means 'gramophone' or 'record player').

Prvú vec, ktorú musíme spraviť, je definovať paradigmy, pretožie ešte žiadne nemáme. The first thing we need to do, as we have no prior paradigms, is to define a paradigm.

Používame nominatív a mužský rod, pridáme teda len paradigmu pre singulár 'gramofon' a plurál 'gramofoni': Remember, we're assuming masculine gender and nominative case. The singular form of the noun is 'gramofon', and the plural is 'gramofoni'. So:

<pardef n="gramofon__n">
   <e><p><l/><r><s n="n"/><s n="sg"/></r></p></e>
   <e><p><l>i</l><r><s n="n"/><s n="pl"/></r></p></e>
</pardef>

Poznámka: tag '<l/>' (ekvivalnetné s <l></l>) znamená, že už netreba pridať ku kmeňu slova v singulári. Note: the '<l/>' (equivalent to <l></l>) denotes that there is no extra material to be added to the stem for the singular.

Možno to vyzerá ako celkom dlhý spôsob, ako to opísať, no je odôvodnený a rýchlo sa vám stane prirodzený. Zrejme vás zaujíma čo znamená <e>,

, <l> a <r>. Takže: This may seem like a rather verbose way of describing it, but there are reasons for this and it quickly becomes second nature. You're probably wondering what the <e>,

, <l> and <r> stand for. Well,

  • e znamená záznam (entry).
  • p znamená dvojicu (pair).
  • l znamená ľavý (left).
  • r znamená pravý (right).
  • e, is for entry.
  • p, is for pair.
  • l, is for left.
  • r, is for right.

Prečo pravý a ľavý? Morfologický slovík bude skompilovaný do konečného automatu. Kompilácia zľava doprava analyzuje slová, a kompilácia zprava doľava vytvára z analýzy slová. Napríklad: Why left and right? Well, the morphological dictionaries will later be compiled into finite state machines. Compiling them left to right produces analyses from words, and from right to left produces words from analyses. For example:

* gramofoni (left to right) gramofon<n><pl> (analýza)
* gramofon<n><pl> (right to left) gramofoni (tvorba)

Teraz sme definovali paradigmu, potrebujeme ju spojiť s príslošnou lemmou, gramofon. Vložíme to teda do sekcie ktorú sme definovali. Now we've defined a paradigm, we need to link it to its lemma, gramofon. We put this in the section that we've defined.

Záznam pre túto sekciu vyzerá nasledovne: The entry to put in the </dictionary>

Teraz potrebujeme pridať záznam na preklad medzi dvoma slovami: Now we need to add an entry to translate between the two words. Something like:

<e><p><l>gramofon<s n="n"/></l><r>gramophone<s n="n"/></r></p></e>

Pretože tu bude veľa takýchto záznamov, bývajú obyčajne kvôli čitateľnosti písané na jeden riadok. Znova používame 'l' a 'r'. Pri kompilácii zľava dostaneme preklad Srbochorváčtina → Angličtina a pri kompilácii zprava dostaneme preklad Angličtina → Srbochorváčtina. Because there are a lot of these entries, they're typically written on one line to facilitate easier reading of the file. Again with the 'l' and 'r' right? Well, we compile it left to right to produce the Serbo-Croatian → English dictionary, and right to left to produce the English → Serbo-Croatian dictionary.

Keď je toto hotové, spustite nasledujúce príkazy: So, once this is done, run the following commands:

$ lt-comp lr apertium-sh-en.sh.dix sh-en.automorf.bin
$ lt-comp rl apertium-sh-en.en.dix sh-en.autogen.bin

$ lt-comp lr apertium-sh-en.en.dix en-sh.automorf.bin
$ lt-comp rl apertium-sh-en.sh.dix en-sh.autogen.bin

$ lt-comp lr apertium-sh-en.sh-en.dix sh-en.autobil.bin
$ lt-comp rl apertium-sh-en.sh-en.dix en-sh.autobil.bin

Aby ste vygenerovali morfologické analyzátory (automorf), morfologické generátory (autogen) a vyhľadávač slov (autobil, bil ako bilingválny). To generate the morphological analysers (automorf), the morphological generators (autogen) and the word lookups (autobil), the bil is for "bilingual".

Pravidlá prenosu

Transfer rules

Teraz máme dva morfologické slovníka a dvojjazyčný slovník. Všetko, čo potrebujeme, sú pravidlá na prenos podstatných mien. Súbory popisujúce tieto pravidlá majú vlstný DTD (transfer.dtd), ktorý môžete nájsť v balíčku Apertium. Ak potrebujete vytvoriť pravidlo, často je dobrý nápad nazrieť do súborov pravidiel iných jazykových dvojíc. Veľa pravidiel môže byť znovu použitých aj medzi jazykmi. Napríklad, tento konkrétky popísaný nižie by bol užitočný pre každý jazyk so zamlčaným podmetom So, now we have two morphological dictionaries, and a bilingual dictionary. All that we need now is a transfer rule for nouns. Transfer rule files have their own DTD (transfer.dtd) which can be found in the Apertium package. If you need to implement a rule it is often a good idea to look in the rule files of other language pairs first. Many rules can be recycled/reused between languages. For example the one described below would be useful for any null-subject language.

Začnime ako obyčajne so základnou kostrou: Start out like all the others with a basic skeleton:

<?xml version="1.0" encoding="UTF-8"?>
<transfer>

</transfer>

V tejto chvíli, pretože ignorujeme pády, stačí len vytvoriť pravidlo, ktoré načíta gramatické symboly a zase ich vypíše. At the moment, because we're ignoring case, we just need to make a rule that takes the grammatical symbols input and outputs them again.

Najprv musíme definovať kategórie a atribúty. Obe nám dovoľujú spájať gramatické symboly. Kategórie umožňujú spájať symboly za účelom párovania (napríklad 'n.*' sú všetky podstatné mená). Atribúty zase spájajú skupiny symbolov, z ktorých sa môžu symboly vyberať, napríklad 'sg' a 'pl' môžu byť spojené v atribúte číslo ('number'). We first need to define categories and attributes. Categories and attributes both allow us to group grammatical symbols. Categories allow us to group symbols for the purposes of matching (for example 'n.*' is all nouns). Attributes allow us to group a set of symbols that can be chosen from. For example ('sg' and 'pl' may be grouped a an attribute 'number').

Pridajme teda potrebné sekcie: Lets add the necessary sections:

<section-def-cats>

</section-def-cats>
<section-def-attrs>

</section-def-attrs>

Pretože iba skloňujeme podstatné mená v singulári a pluráli, potrebujeme pridať kategóriu pre podstatné mena a atribút pre číslo: As we're only inflecting, nouns in singular and plural then we need to add a category for nouns, and with an attribute of number. Something like the following will suffice:

Do section-def-cats pridajte: Into section-def-cats add:

<def-cat n="nom">
   <cat-item tags="n.*"/>
</def-cat>

Toto zachytí všetky podstatné mená (lemmy nasledované <n>, potom hocičím) a pomenuje ich "nom" (neskôr to využijeme). This catches all nouns (lemmas followed by <n> then anything) and refers to them as "nom" (we'll see how thats used later).

Do sekcie section-def-attrs, pridajte: Into the section section-def-attrs, add:

<def-attr n="nbr">
   <attr-item tags="sg"/>
   <attr-item tags="pl"/>
</def-attr>

a potom and then

<def-attr n="a_nom">
   <attr-item tags="n"/>
</def-attr>

Prvý definuje atribút nbr (číslo), ktoré môže byť buď singulár alebo plurál. The first defines the attribute nbr (number), which can be either singular (sg) or plural (pl).

Druhý definuje atribút a_nom (atribút podstatné meno). The second defines the attribute a_nom (attribute noun).

Ďalej potrebujeme pridať sekciu pre globálne premenné: Next we need to add a section for global variables:

<section-def-vars>

</section-def-vars>

Tieto premenné sú používané na ukladanie alebo prenos atribútov medzi pravidlami. Na teraz potrebujeme len jedno, These variables are used to store or transfer attributes between rules. We need only one for now,

<def-var n="number"/>

Nakoniec, potrebujeme pridať pravidlo, ktoré vyberie podstatné meno a vypíše ho v správnom tvare. Budeme potrebovať sekciu pravidiel... Finally, we need to add a rule, to take in the noun and then output it in the correct form. We'll need a rules section...

<section-rules>

</section-rules>

Zmením tempo z predchádzajúcich príkladov, len sem vložím toto pravidlo a potom ho opíšem. Changing the pace from the previous examples, I'll just paste this rule, then go through it, rather than the other way round.

<rule>
   <pattern>
     <pattern-item n="nom"/>
   </pattern>
   <action>
     <out>
       <lu>
         <clip pos="1" side="tl" part="lem"/>
         <clip pos="1" side="tl" part="a_nom"/>
         <clip pos="1" side="tl" part="nbr"/>
       </lu>
     </out>
   </action>
</rule>

Prvý tag je zrejmý, definuje pravidlo. Druhý tag, pattern, v zásade hovorí: "použi toto pravidlo, ak nájdeš tento vzor". V tomto príklade tento vzor pozostáva z jediného podstatného mena (definovného kategóriou nom). Všimnite si, že vzor je napárovaný s najdlším výskytom najprv. Takže ak máte tri pravidlá, prvé zachytáva "<prn><vblex><n>", druhé zachytáva "<prn><vblex>" tretie zachytáva "<n>", a bol zachytený vzor, a vykonané pravidlo bude to prvé. The first tag is obvious, it defines a rule. The second tag, pattern basically says: "apply this rule, if this pattern is found". In this example the pattern consists of a single noun (defined by the category item nom). Note that patterns are matched in a longest-match first. So if you have three rules, the first catches "<prn><vblex><n>", the second catches "<prn><vblex>" and the third catches "<n>", the pattern matched, and rule executed will be the first.

Pre každý vzor existuje akcia, ktorá produkuje výstup. Tento výstup je lexikálna jednotka (lu). For each pattern, there is an associated action, which produces an associated output, out. The output, is a lexical unit (lu).

Tag clip umožnuje používateľovi vybrať a manipulovať atribúty a časti zdrojového jazyka (side="sl"), alebo lexikálne poločky cielového jazyka (side="tl"). The clip tag allows a user to select and manipulate attributes and parts of the source language (side="sl"), or target language (side="tl") lexical item.

Skompilujme a otestuje to. Pravidlá prenosu sú skompilované s : Let's compile it and test it. Transfer rules are compiled with:

$ apertium-preprocess-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin

Čo vygeneruje súbor sh-en.t1x.bin. Which will generate a sh-en.t1x.bin file.

Teraz sme takmer pripravení otestovať náš systém pre strojový preklad. Chýba jedna dôležitá časť na určenie slovných druhov (tzv. PoS tagger), no to bude rýchlo vysvetlené. Zatiaľ ho môžeme otestovať v takomto stave: Now we're ready to test our machine translation system. There is one crucial part missing, the part-of-speech (PoS) tagger, but that will be explained shortly. In the meantime we can test it as is:

Najprv, analyzujme slovo, gramofoni: First, lets analyse a word, gramofoni:

$ echo "gramofoni" | lt-proc sh-en.automorf.bin 
^gramofon/gramofon<n><pl>$

Teraz by PoS tagger vybral správnu verziu podľa slovného druhu, ale keďže ho ešte nemáme, použijeme malý gawk script (vďaka Sergiovi) ktorý vypíše prvú možnosť. Now, normally here the POS tagger would choose the right version based on the part of speech, but we don't have a POS tagger yet, so we can use this little gawk script (thanks to Sergio) that will just output the first item retrieved.

$ echo "gramofoni" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}'
^gramofon<n><pl>$

Teraz pokračujme s pravidlom pre prenos: Now let's process that with the transfer rule:

$ echo "gramofoni" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin

Čo vypíše: It will output:

^gramophone<n><pl>$^@
  • 'gramophone' je lemma (lem) v cielovom jazyku (side="tl") na pozícii 1 (pos="1").
  • '<n>' je a_nom v cielovom jazyku na pozícii 1.
  • '<pl>' je atribút číslo (nbr) v cielovom jazyku na pozícii 1.


  • 'gramophone' is the target language (side="tl") lemma (lem) at position 1 (pos="1").
  • '<n>' is the target language a_nom at position 1.
  • '<pl>' is the target language attribute of number (nbr) at position 1.

Vyskúšajte zakomentovať niektoré tagy clip, znovu skompilovať a sledovať, čo sa stane. Try commenting out one of these clip statements, recompiling and seeing what happens.

Takže, teraz máme výstup z prenosu, ostáva len vygenerovať ohnuté tvary na cielový jazyk. Na to použijeme lt-proc, ale v móde generácie (-g), nie analýzy. So, now we have the output from the transfer, the only thing that remains is to generate the target-language inflected forms. For this, we use lt-proc, but in generation (-g), not analysis mode.

$ echo "gramofoni" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin

gramophones\@

A je to! Teraz máte systém pre strojový preklad, ktorý prekladá srbochorvátske podstatné meno na anglické podstatné meno. Očividne ešte nie je veľmi mocný, no dostaneme sa ku komplikovaniejším záležitostiam. Taktiež zachvíľu vysvetlím symbol '@'. And c'est ca. You now have a machine translation system that translates a Serbo-Croatian noun into an English noun. Obviously this isn't very useful, but we'll get onto the more complex stuff soon. Oh, and don't worry about the '@' symbol, I'll explain that soon too.

Nájdite iné slová, ktoré sa skloňujú ako gramofon. Skúste ich pridať. Nepotrebujeme pridávať žiadne paradigmy, len záznamy do hlavnej sekcie jednojazyčných a dvojjazyčného slovníka. Think of a few other words that inflect the same as gramofon. How about adding those. We don't need to add any paradigms, just the entries in the main section of the monolingual and bilingual dictionaries.

Slovesá

Bring on the verbs

Teraz máme systém, ktorý dokáže prekladať podstatné mená, no nie je veľmi užitočný, chceme prekladať aj slovesá a celé vety! Začnime so slovesom vidieť, aglicky see, srbochorvástky videti. Srbochorváčtina je, na rozdiel od Angličtiny, jazyk so zamlčanými podmetmi, čo znamená že väčšinou nepoužíva osobné zámená pred časovaným slovesom. I see sa do Srbochorváčtiny preloží ako vidim. Ok, so we have a system that translates nouns, but thats pretty useless, we want to translate verbs too, and even whole sentences! How about we start with the verb to see. In Serbo-Croatian this is videti. Serbo-Croatian is a null-subject language, this means that it doesn't typically use personal pronouns before the conjugated form of the verb. English is not. So for example: I see in English would be translated as vidim in Serbo-Croatian.

  • Vidim
  • see<p1><sg>
  • I see

Poznámka: <p1> označuje prvú osobu. Note: <p1> denotes first person

Toto sa stane dôležitým pri pravidlách prenosu pre slovesá. Ďalšie príklady jazykov so zamlčaným podmetom sú: Španielčina, Rumunčina a Polština. Taktiež to spôsobuje, že hoci potrebujeme pridať len sloveso do srbochorvátskeho slovníku, do anglického slovníku musíme pridať naviac aj zámená. This will be important when we come to write the transfer rule for verbs. Other examples of null-subject languages include: Spanish, Romanian and Polish. This also has the effect that while we only need to add the verb in the Serbo-Croatian morphological dictionary, we need to add both the verb, and the personal pronouns in the English morphological dictionary. We'll go through both of these.

Ďalšie tvary slovesa videti sú : vidiš, vidi, vidimo, vidite, vide, korešpondujúce s anglickými tvarmi : you see (singular), he sees, we see, you see (plural), they see. The other forms of the verb videti are: vidiš, vidi, vidimo, vidite, and vide; which correspond to: you see (singular), he sees, we see, you see (plural), and they see.

Existujú dva tvary you see, plurál a formály singulár vidite (vykanie) a neformálny singular vidiš (tykanie). There are two forms of you see, one is plural and formal singular (vidite) and the other is singular and informal (vidiš).

Ideme preložiť vetu "Vidim gramofoni" do "I see gramophones". V záujme miesta, pridáme informáciu len na tento príklad, a necháme vypĺňanie ostatných tvarov časovaného slovesa ako cvičenie pre čitateľa. We're going to try and translate the sentence: "Vidim gramofoni" into "I see gramophones". In the interests of space, we'll just add enough information to do the translation and will leave filling out the paradigms (adding the other conjugations of the verb) as an exercise to the reader.

Pozorný čitatel si už zrejme uvedomil že nemôžeme preložiť vidim gramofoni pretože to nie je gramaticky správna srbochorvátska veta. Správna veta by bola vidim gramofone, podstatné meno je totiž v akuzatíve. Budeme musieť pridať aj tento tvar, no teraz nepotrebujeme informáciu o pádoch, pridáme ho len ako ďalšiu možnosť pre plurál. Takže len skopírujte 'i' blok a zmente 'i' na 'e'. The astute reader will have realised by this point that we can't just translate vidim gramofoni because it is not a grammatically correct sentence in Serbo-Croatian. The correct sentence would be vidim gramofone, as the noun takes the accusative case. We'll have to add that form too, no need to add the case information for now though, we just add it as another option for plural. So, just copy the 'e' block for 'i' and change the 'i' to 'e' there.

Prvú vec, ktorú musíme spraviť, je pridať viac symbolov. Najprv pridáme symbol pre sloveso, ktorý budeme nazývať "vblex" (čo značí lexikálne sloveso, na rozdiel od napr. pomocných slovies). Sloveso má osobu, čas a číslo, takže pridajme symboly aj pre ne. Potrebujeme preložiť "I see", takže osoba bude "p1" a čas "pri", prítomný. First thing we need to do is add some more symbols. We need to first add a symbol for 'verb', which we'll call "vblex" (this means lexical verb, as opposed to modal verbs and other types). Verbs have 'person', and 'tense' along with number, so lets add a couple of those as well. We need to translate "I see", so for person we should add "p1", or 'first person', and for tense "pri", or 'present indicative'.

<sdef n="vblex"/>
<sdef n="p1"/>
<sdef n="pri"/>

Potom, čo sme to spravili, urobíme to isté s podstatnými menami, pridáme paradigmu pre časovanie slovies. Prvý riadok bude: After we've done this, the same with the nouns, we add a paradigm for the verb conjugation. The first line will be:

<pardef n="vid/eti__vblex">

'/' tu značí kde budú pridané prípony (medzi tagmi <l> a </l>). The '/' is used to demarcate where the stems (the parts between the <l> </l> tags) are added to.

Potom časovanie pre prvú osobu singuláru bude: Then the inflection for first person singular:


<e><p><l>im</l><r>eti<s n="vblex"/><s n="pri"/><s n="p1"/><s n="sg"/></r></p></e>

'im' je koncovka (ako vo 'vidim'), je potrebné pridať 'eti' do sekcie <r>, pretože to bude useknuté. Zvyšok je jednoduchý, 'vblex' je lexikálne slovesok, 'pri' je prítomný čas, 'p1' je prvá osoba a 'sg' je singulár. Môžeme rovnako pridať plurál, len 'imo' miesto 'im' a 'pl' miesto 'sg'. The 'im' denotes the ending (as in 'vidim'), it is necessary to add 'eti' to the <r> section, as this will be chopped off by the definition. The rest is fairly straightforward, 'vblex' is lexical verb, 'pri' is present indicative tense, 'p1' is first person and 'sg' is singular. We can also add the plural which will be the same, except 'imo' instead of 'im' and 'pl' instead of 'sg'.

Po tomto potrebujeme pridať lemmu, paragdigmu mapujúcu do hlavnej sekcie: After this we need to add a lemma, paradigm mapping to the main section:

<e lm="videti"><i>vid</i><par n="vid/eti__vblex"/></e>

Poznámka: obsah <i> </i> je koreň, nie lemma. Note: the content of <i> </i> is the root, not the lemma.

Tým sme nateraz dokončili prácu na srbochorvátskom slovníku, skompilujme a otestujme ho. Thats the work on the Serbo-Croatian dictionary done for now. Lets compile it then test it.

$ lt-comp lr apertium-sh-en.sh.dix sh-en.automorf.bin
main@standard 23 25
$ echo "vidim" | lt-proc sh-en.automorf.bin
^vidim/videti<vblex><pri><p1><sg>$
$ echo "vidimo" | lt-proc sh-en.automorf.bin
^vidimo/videti<vblex><pri><p1><pl>$

Teraz urobíme to isté pre anglický slovník (nezabudnite pridať rovnaké definície symbolov ako do srbochorvátskeho). Ok, so now we do the same for the English dictionary (remember to add the same symbol definitions here as you added to the Serbo-Croatian one).

Paradigma je: The paradigm is:

<pardef n="s/ee__vblex">

pretože minulý čas je 'saw'. Teraz by sme mohli pridať aj prvú a druhú osobu, ale obe majú rovnaký tvar. Všetky, okrem tretej osoby singuláru, majú rovnaký tvar slovesa, teda 'see'. Takže spravíme jeden záznam pre 'see' a dáme mu len 'pri' symbol. because the past tense is 'saw'. Now, we can do one of two things, we can add both first and second person, but they are the same form. In fact, all forms (except third person singular) of the verb 'to see' are 'see'. So instead we make one entry for 'see' and give it only the 'pri' symbol.


<e><p><l>ee</l><r>ee<s n="vblex"/><s n="pri"/></r></p></e>

a ako vždy, záznam do hlavnej sekcie: and as always, an entry in the main section:

<e lm="see"><i>s</i><par n="s/ee__vblex"/></e>

Uložme, znovu skomilujme a otestujme: Then lets save, recompile and test:

$ lt-comp lr apertium-sh-en.en.dix en-sh.automorf.bin
main@standard 18 19

$ echo "see" | lt-proc en-sh.automorf.bin
^see/see<vblex><pri>$

Teraz záznam pre dvojjazyčný slovvík: Now for the obligatory entry in the bilingual dictionary:

<e><p><l>videti<s n="vblex"/></l><r>see<s n="vblex"/></r></p></e>

(znovu, nezabudnite pridať sdef) (again, don't forget to add the sdefs from earlier)

A znovu skompilovať: And recompile:

$ lt-comp lr apertium-sh-en.sh-en.dix sh-en.autobil.bin
main@standard 18 18
$ lt-comp rl apertium-sh-en.sh-en.dix en-sh.autobil.bin
main@standard 18 18

Otestujme: Now to test:

$ echo "vidim" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin

^see<vblex><pri><p1><sg>$^@

Analýza zbehla korektne, no keď skúsime generovať výsledný tvar z tohoto, dostaneme '#', ako vidíme nižšie: We get the analysis passed through correctly, but when we try and generate a surface form from this, we get a '#', like below:

$ echo "vidim" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
#see\@

'#' znamená, že generátor nemôže vygenerovať správny lexikálny tvar, pretože ho neobsahuje. Prečo sa to deje? This '#' means that the generator cannot generate the correct lexical form because it does not contain it. Why is this?

V podstate, analýza nenašla zhodu pre 'see', pretože v slovníku je see<vblex><pri>, ale see, ktoré dostane analyzátor prenosom je see<vblex><pri><p1><sg>. Srbochorvátska strana slovníka poskytuje viac informácií ako anglická strana vyžaduje. Môžete to otestovať pridaním chýbajúcich symbolov do anglického slovníka a opätovným testom. Basically the analyses don't match, the 'see' in the dictionary is see<vblex><pri>, but the see delivered by the transfer is see<vblex><pri><p1><sg>. The Serbo-Croatian side has more information than the English side requires. You can test this by adding the missing symbols to the English dictionary, and then recompiling, and testing again.

Lepší spôsob je však pomocou nového pravidla. Otvoríme teda súbor s pravidlami (apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin ak ste zabudli). However, a more paradigmatic way of taking care of this is by writing a rule. So, we open up the rules file (apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin in case you forgot).

Potrebujeme pridať novú kategóriu pre sloveso ('verb'). We need to add a new category for 'verb'.

<def-cat n="vrb">
   <cat-item tags="vblex.*"/>
</def-cat>

Musíme tiež pridať atribúty pre osobu a čas. Spravíme to zatiaľ veľmi jednoduché, môžete pridať aj p2 a p3, ale ja budem šetriť miestom. We also need to add attributes for tense and for person. We'll make it really simple for now, you can add p2 and p3, but I won't in order to save space.

<def-attr n="temps">
   <attr-item tags="pri"/>
</def-attr>

<def-attr n="pers">
   <attr-item tags="p1"/>
</def-attr>

Teraz by sme mali aj pridať atribút slovesám. We should also add an attribute for verbs.

<def-attr n="a_verb">
   <attr-item tags="vblex"/>
</def-attr>

A teraz pravidlo: Now onto the rule:

<rule>
   <pattern>
     <pattern-item n="vrb"/>
   </pattern>
   <action>
     <out>
       <lu>
         <clip pos="1" side="tl" part="lem"/>
         <clip pos="1" side="tl" part="a_verb"/>
         <clip pos="1" side="tl" part="temps"/>
       </lu>
     </out>
   </action>
</rule>

Keď se skúsili zakomentovať 'clip' tagy v predchádzajúcom pravidle, a tie potom zmizly z prenosu, tak tu robíme prakticky to isté. Vezmeme sloveso s plnou analýzou, ale vrátime len jej časť (lemma + tag slovesa + tag času). Remember when you tried commenting out the 'clip' tags in the previous rule example and they disappeared from the transfer, well, thats pretty much what we're doing here. We take in a verb with a full analysis, but only output a partial analysis (lemma + verb tag + tense tag).

Ak teda teraz rekompilujeme, dostaneme: So now, if we recompile that, we get:

$ echo "vidim" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin
^see<vblex><pri>$^@

a:

$ echo "vidim" | lt-proc sh-en.automorf.bin  | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
see\@

Teraz to skúste s 'vidimo' (we see), či dostávame správny výstup. Try it with 'vidimo' (we see) to see if you get the correct output.

Teraz to skúste s "vidim gramofone": Now try it with "vidim gramofone":

$ echo "vidim gramofoni" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
see gramophones\@

But what about personal pronouns?

Ale čo osobné zámená?

To je úžasné, ale stále nám chýba osobné zámeno potrebné v Angličtine. Aby sme ho pridali, musíme najprv pozmeniť anglický morfologický slovník. Well, thats great, but we're still missing the personal pronoun that is necessary in English. In order to add it in, we first need to edit the English morphological dictionary.

Najprv musíme pridať potrebné symboly: As before, the first thing to do is add the necessary symbols:

<sdef n="prn"/>
<sdef n="subj"/>

prn je prísudok, a subj je podmet. Of the two symbols, prn is pronoun, and subj is subject (as in the subject of a sentence).

Pretože tu nie je žiaden koreň, alebo 'lemma' pre osobné zámená, pridáme len nasledovné paradigmy: Because there is no root, or 'lemma' for personal subject pronouns, we just add the pardef as follows:

<pardef n="prsubj__prn">
   <e><p><l>I</l><r>prpers<s n="prn"/><s n="subj"/><s n="p1"/><s n="sg"/></r></p></e>
</pardef>

Kde 'prsubj' je 'osobný podmet'. Zvyšok z nich (You, We atď.) je ponechaný ako cvičenie pre čitateľa. With 'prsubj' being 'personal subject'. The rest of them (You, We etc.) are left as an exercise to the reader.

Môžeme pridať záznam do hlavnej sekcie: We can add an entry to the main section as follows:

<e lm="personal subject pronouns"><i/><par n="prsubj__prn"/></e>

Takže, rekompilujte a testujte, mali by sme dostať niečo ako: So, save, recompile and test, and we should get something like:

$ echo "I" | lt-proc en-sh.automorf.bin
^I/PRPERS<prn><subj><p1><sg>$

Poznámka: Je to veľkými písmenami pretože 'I' je veľkými písmenami. (Note: it's in capitals because 'I' is in capitals).

Teraz potrebujeme doplniť 'verb' pravidlo, aby vracalo osobné zámeno spolu so správnym tvarom slovesa. Now we need to amend the 'verb' rule to output the subject personal pronoun along with the correct verb form.

Najprv, pridáme kategóriu (čo sa už zrejme stáva trochu obyčajné): First, add a category (this must be getting pretty pedestrian by now):

<def-cat n="prpers">
   <cat-item lemma="prpers" tags="prn.*"/>
</def-cat>

Teraz pridáme typy prísudkov ako atribúty. Môžeme aj pridať typ 'obj', hoci ho zatiaľ nebudeme potrebovať: Now add the types of pronoun as attributes, we might as well add the 'obj' type as we're at it, although we won't need to use it for now:

<def-attr n="tipus_prn">
   <attr-item tags="prn.subj"/>
   <attr-item tags="prn.obj"/>
</def-attr>

A teraz vstup pre pravidlo: And now to input the rule:

<rule>
   <pattern>
     <pattern-item n="vrb"/>
   </pattern>
   <action>
     <out>
       <lu>
         <lit v="prpers"/>
         <lit-tag v="prn"/>
         <lit-tag v="subj"/>
         <clip pos="1" side="tl" part="pers"/>
         <clip pos="1" side="tl" part="nbr"/>
       </lu>
       <b/>
       <lu>
         <clip pos="1" side="tl" part="lem"/>
         <clip pos="1" side="tl" part="a_verb"/>
         <clip pos="1" side="tl" part="temps"/>
       </lu>
     </out>
   </action>
</rule>

Toto je prakticky rovnalé pravidlo ako vyššie, spravili sme len zopár malých zmien. This is pretty much the same rule as before, only we made a couple of small changes.

Potrebovali sme výstup: We needed to output:

^prpers<prn><subj><p1><sg>$ ^see<vblex><pri>$

tak aby mohol generátor vybrať správny prísudok a správny tvar slovesa. so that the generator could choose the right pronoun and the right form of the verb.

Takže, rýchly prehlad: So, a quick rundown:

  • <lit>, vypíše reťazec, v tomto prípade "prpers"
  • <lit-tag>, vypíše tag, pretože nemôžeme získať tagy zo slovesa, pridáme teda vlastné, "prn" pre prísudok, a "subj" pre podmet.
  • , vypíše medzeru.
  • <lit>, prints a literal string, in this case "prpers"
  • <lit-tag>, prints a literal tag, because we can't get the tags from the verb, we add these ourself, "prn" for pronoun, and "subj" for subject.
  • , prints a blank, a space.

Všimnite si že sme získali informáciu pre číslo a pád priamo zo slovesa. Note that we retrieved the information for number and tense directly from the verb.

Ak teda rekompilujeme a otestujeme znovu: So, now if we recompile and test that again:

$ echo "vidim gramofone" | lt-proc sh-en.automorf.bin  | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
I see gramophones

Čo, hoci nie je práve oceňované dielo (ako preklad tohoto článku), je cekom presné. Which, while it isn't exactly prize-winning prose (much like this HOWTO), is a fairly accurate translation.

Povedzte mi o svojom digitálnom gramofóne (slovné spojenia)

So tell me about the record player (Multiwords)

Hoci je gramofón anglické slovo, nie je to najpresnejší preklad. Gramofón väčšinou označuje veľmi starý druh prístroja, s ihlou a bez zosilovača. Lepší preklad by bol 'record player'. Je to viacslovné spojenie, no môžeme ho považovať za jedno slovo, ak použijeme konštrukciu multiword. While gramophone is an English word, it isn't the best translation. Gramophone is typically used for the very old kind, you know with the needle instead of the stylus, and no powered amplification. A better translation would be 'record player'. Although this is more than one word, we can treat it as if it is one word by using multiword (multipalabra) constructions.

Nepotrebujeme meniť srbochorvátsky slovník, stačí len anglický a bilingválny. We don't need to touch the Serbo-Croatian dictionary, just the English one and the bilingual one, so open it up.

Plurál 'record player' je 'record players', takže používa rovnakú paradigmu ako gramopnohe (gramophone__n) — len pridávame 's'. Pridáme teda len nový záznam do hlavnej sekcie. The plural of 'record player' is 'record players', so it takes the same paradigm as gramophone (gramophone__n) — in that we just add 's'. All we need to do is add a new element to the main section.

<e lm="record player"><i>record<b/>player</i><par n="gramophone__n"/></e>

Jediný rozdiel je použite tagu , ktorý tiež nie je pre nás úplne nový. The only thing different about this is the use of the tag, although this isn't entirely new as we saw it in use in the rules file.

Takže, znovu rekompilujeme a testujeme: So, recompile and test in the orthodox fashion:

$ echo "vidim gramofone" | lt-proc sh-en.automorf.bin | \
  gawk 'BEGIN{RS="$"; FS="/";}{nf=split($1,COMPONENTS,"^"); for(i = 1; i<nf; i++) printf COMPONENTS[i]; if($2 != "") printf("^%s$",$2);}' | \
  apertium-transfer apertium-sh-en.sh-en.t1x sh-en.t1x.bin sh-en.autobil.bin  | \
  lt-proc -g sh-en.autogen.bin
I see record players

Perfektné. Veľká výhoda používania konštrukcie multiword je preklad idióm bez potreby prekladať jednotlivé slová. Napríklad anglická fráza "at the moment" by bola preložená ako "trenutno" (trenutak = chvíľa, trenutno je odvodená príslovnka) — nebolo by možné preložiť túto anglickú frázu slovo po slove. Perfect. A big benefit of using multiwords is that you can translate idiomatic expressions verbatim, without having to do word-by-word translation. For example the English phrase, "at the moment" would be translated into Serbo-Croatian as "trenutno" (trenutak = moment, trenutno being adverb of that) — it would not be possible to translate this English phrase word-by-word into Serbo-Croatian.

Ako sa vysporiadať s obmenami

Dealing with minor variation

Srbochorváčtina má zopár spôsobov, ako zapísať každé slovo, kvôli nárečovým odchýlkam. Má totiž fonetický systém písania, teda píš ako počuješ. Napríklad, ľudia hovoriaci po Ijekavsky povedia "rječnik", kým ľudia hovoriaci po Ekavsky povedia "rečnik", čo odráža odlišnosti vo výslovnosti protoslovanskej samohlásky yat.

Serbo-Croatian typically has a few ways of writing each word because of dialectal variation. It has a cool phonetic writing system so you write how you speak. For example, people speaking in Ijekavian would say "rječnik", while someone speaking Ekavian would say "rečnik", which reflects the differences in pronunciation of the proto-Slavic vowel yat.

Analýza

Analysis

Mala by byť celkom jednoduchá cesta, ako sa s týmto vysporiadať, a to pomocou paradigiem. Paradigmy niesu pužívané len pre pridávanie gramatických symbolov, ale môžu byť taktiež použité na zámenu znakov za iné. Napríklad, táto paradigma akceptuje aj "e" aj "je" v analýze. Mala by byť jednojazyčnom srbochorvátskom slovíku. There should be a fairly easy way of dealing with this, and there is, using paradigms again. Paradigms aren't only used for adding grammatical symbols, but they can also be used to replace any character/symbol with another. For example, here is a paradigm for accepting both "e" and "je" in the analysis. The paradigm should, as with the others go into the monolingual dictionary for Serbo-Croatian.

  <pardef n="e_je__yat">
    <e>
      <p>
        <l>e</l>
        <r>e</r>
      </p>
    </e>
    <e>
      <p>
        <l>je</l>
        <r>e</r>
      </p>
    </e>
  </pardef>

Potom v hlavnej sekcii: Then in the "main section":

    <e lm="rečnik"><i>r</i><par n="e_je__yat"/><i>čni</i><par n="rečni/k__n"/></e>

Toto nám umožnuje analyzovať obe tvary. Na tvorbu oboch tvarov by bolo potrebné viac práce. This only allows us to analyse both forms however... more work is necessary if we want to generate both forms.

Tvorba

Pozri tiež