Difference between revisions of "Апертиум, как се създава нова езикова двойка"

From Apertium
Jump to navigation Jump to search
Line 736: Line 736:
 
*[[Building dictionaries]]
 
*[[Building dictionaries]]
   
[[Category:Documentation|HOWTO]]
+
[[Category:Documentation]]
  +
[[Category:HOWTO]]

Revision as of 08:57, 10 November 2007

Апертиум, как се създава нова езикова двойка

Този документ има за цел да обясни как се създава нова езикова двойка в Апертиум системата за машинен превод от началото до края.

Не е необходимо никакво знание по лингвистика или по машинен превод над нивото на различаване на съществителни имена от глаголи (представки и други)

Въведение

Както може би вече сте се досетили, Апертиум е система за машинен превод. Всъщност, казано по-точно това е платформа за преводи. Разполага с машина и инструменти, които ви позволяват да създавате ваши собствени системи за превод. Единственото нещо, което трябва да направите е да запишете данните. Основно те се състоят от три речника и няколко правила за преподреждане на думите и други граматични трансформации.

За по конкретна информация как точно работи системата, има някои доста добри ръководства на уеб сайта на проекта apertium.sourceforge.net.

Какво ще ви е необходимо

  • lttoolbox (>= 3.0.0)
  • libxml utils (xmllint etc.)
  • apertium (>= 3.0.0)
  • текстов редактор (или ако предпочитате специализиран XML редактор)

Този документ няма да описва как да инсталирате тези пакети. За повече информация за това прочетете секцията с документацията на уеб сайта на Апертиум.

От какво се състои езиковата двойка?

Системата за машинен превод Апертиум е от повърхностно-трансферен тип, което ще рече, че работи с речници и повърхностни правила за позициониране на думите. Повърхностнното позициониране на думите се различава от "пълното позициониране" с това, че не прави цялостно синтактично парсиране. По принцип правилата са операции върху групи от лексически раздели, и не са операции върху дървовидни структури. Основно съществуват три основни речника:

  1. Морфологичния речник за език ХХ: той съдържа правилата за това как се спрягат думите в език ХХ. В нашия пример този речник ще се нарича: apertium-sh-en.sh.dix
  2. Морфологичния речник за език УУ: той съдържа правилата за това как се спрягат думите в език УУ. В нашия пример този речник ще се нарича: apertium-sh-en.en.dix
  3. Двуезичен речник: съдържа съответстия между думи и символи на двата езика. В нашия пример този речник ще се нарича: apertium-sh-en.sh-en.dix

В двойката за превод и двата езика могат да бъдат или източник или приемник на превода, това са относителни тернини.

Също така има два файла за правила на трансфера. Това са правилата, които управляват как се пренареждат думите в изреченията, пр. chat noir -> cat black -> black cat. Управляват се и родовете, числата и т.н. Правилата могат да бъдат използвани и да се смъкват или изтриват лексически елементи, както ще бъде описано по-късно. Тези файлове са:

  • правила за трансфер на език ХХ към УУ: този файл съдържа правила относно промяната от език ХХ към УУ. В нашия пример това ще бъде: apertium-sh-en.trules-sh-en.xml
  • правила за трансфер на език УУ към ХХ: този файл съдържа правила относно промяната на език УУ към ХХ. В нашия пример това ще бъде: apertium-sh-en.trules-en-sh.xml

Много от езиковите двойки, които са налични в момента имат и друг файлове, но ние няма да ги разясняваме тук. Горните файлове са тези, които са необходими за изграждането на една функционална система.

Езикова двойка

Както може да се предположи от имената на файловете, това ръководство ще използва за обяснение на създаването на основната система примери от сърбо-хърватски на английски. Това не е идеалната двойка, тъй като системата работи по-добре с по-близки езици, но това няма да бъде рпоблем за простите примери, с които ще се сблъскаме тук.

Кратка бележка за термините

Преди да продължим има няколко термини, които трябва да бъдат разяснени.

Първият е лема. Лема е цитирането на дума. Това представлява думата, без никаква граматическа информация. На пример, лемата на думата котки е котка. За английските съществителни това обикновенно е единственото число на въпросната дума. За глаголи, лемата е основната форма. Лемата на глагола бях е съм.

Вторият е символа. В контекста на Апертиум системата, символа означава граматически етикет. Думата котки е множествено число, следователно тя има символа за съществително и символа за многжествено число. На входа и изхода на модулите на Апертиум, горните обикновено се подавата между ъглови скоби, както следва:

  • <n>; за съществителни
  • <pl>; за множествено число

Други примери за символи са <sg>; единствено число, <p1> първо лице, <pri> сегашно изявително наклонение и др. Когато са записани в квадратни скобки символите могат същото така да се приемат като тагове. Важно е да се отбележи, че в много от съществуващите езикови двойки дефинициите на символите са думи, образувани от началните букви на други думи на Каталонски език. На пример, vbhaver - от vb (глагол) и haver ("да имам" на каталонски). Символите са дефинирани в <sdef> тагове и се използват с <s> тагове.

Третата дума е парадигма. В контекста на Апертиум системата, парадигмата се отнася примерно как се спряга цяла група от думи. В морфологичния речник, лемите (виж по-горе) се свързват с парадигмите, което ни дава възможност да опишем как всяка лема може да бъде спрегната без да се налага да описваме всички наставки.

Примерно, ако искаме да съхраним две прилагателни happy и lazy, вместо да запазваме две еднакви наствки:

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

Можем просто да съхраним едната и после да кажем, че "lazy, се спряга като happy", или "shy се спряга като happy","naughty се спряга като happy", "friendly се спряга като happy" и така нататък. В този пример, happy ще е парадигмата, модела за това как всички останали се спрягат. Точното описание на как точно се дефинира това ще бъде обяснено скоро. Парадигмите се дефинират в <pardef> тагове и се използват в <par> тагове.

Начало

Многоезини речници

Нека да започнем като направим нашия първи езиков речник. Речника представлява XML файл. Пуснете си вашия текстов редактор и напишете следното:

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

</dictionary>

Така, файла дефинира за сега, че искаме да направим речник. За да бъде полезен този файл трябва да добавим още няколко реда, първия от които е азбука. Тя дефинира поредицата от букви, които мога да се използват в речника за Сърбо-Хърватски. Ще изглежда по следния начин и ще съдържа всички букви от Сърбо-Хърватската азбука:

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

Поставете азбуката под тага <dictionary>.

След това трябва да дефинираме някои символи. Да започнем с нещо по-елементарно, съществително (n) в единствено число (pl) и множествено число (pl).

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

Символните имена не трябва да бъдат толкова кратки, всъщност те биха могли дори да бъдат написани пълно, но тъй като ще се налага да ги пишем често, има логика да използваме съкращения.

За нещастие, не е толкова лесно, съществителните в Сърбо-Хърватския се спрягат не само по число, а също така и по род и наклонение. Обаче, за този пример ще приемем, че съществителното е в мъжки род и в именителен падеж ( цялостен пример може да бъде намерен в края на този документ )

Следва да дефинираме секция за парадигмите,

<pardefs>

</pardefs>

и секция за речника:

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

</section>

Има два вида секции, първия е стандартна секция, която съдържа думи, енклитика и други. Втория вид е неусловна секция, която най-често съдържа препинателни знаци и други. Тук нямаме такава неусловна секция, но тя ще бъде описана по-късно.

Така, файла ни трябва да изглежда по следния начин:

<?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>

Сега имаме структурата, можем да започнем с добавянето на съществително. За пример ще използваме "gramofon", който означава "грамофон" или "устройство, което свири плочи".

Първото нещо, което трябва да направим, тъй като нямаме предишни парадигми е да дефинираме парадигма.

Запомнете, че приемаме мъжки род и именителен падеж. Единственото число на съществителното е "gramofon", и множественото число е "gramofoni". Така:

<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>

Забележка: '<l/>' (еквивалент на <l></l>) означава, че няма допълнителен материял да бъде добавян в основата на думата в единствено число.

Това може да изглежда като доста подробен начин за описването му, но има причини за това и скоро се свиква с него. Вие сигурно се чудите какво означават <e>,

, <l> и <r>. Така,

  • e - запис.
  • p - двойка.
  • l - ляво.
  • r - дясно.

Защо ляво и дясно? Ами морфологичните речници по-късно ще бъдат компилирани в крайни автомати. Компилирането им отляво надясно създава анализ от думи и от дясно наляво думи от анализи. Например:

* gramofoni (отляво надясно) gramofon<n><pl> (анализ)
* gramofon<n><pl> (отдясно наляво) gramofoni (генерация)

Сега дефинирахме парадигма, трябва да я свържем с нейната лема, gramofon. Поставяме я в секцията, която дефинирахме.ed.

Записа, който ще сложим в </dictionary>

Сега е необходимо да добавим запис за превод между двете думи. Нещо като:

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

Тъй като има много такива записи, те се пишат обикновено на един и същи ред за да се улесни четенето на файла. Отново с 'l' и 'r'? Компилираме го от ляво надясно за да се създаде сърбо-хърватски → английски речник, и отдясно наляво за създаването на английски → сърбо-хърватски речник.

И така, когато сме готови стартираме следните команди:

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

$ lt-comp lr apertium-sh-en.en.dix en-sh.automorf.bin
$ lt-comp rl apertium-sh-en.en.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

Така се генерират морфологичните анализатори (automorf), морфологичните генератори (autogen) и се проверяват думите (autobil), думата bil означава двуезичен.

Правила за трансфер

Така, имаме два морфологични речника и двуезичен речник. Това от което се нуждаем сега е правило за трансфер за съществителни. Оравилата за трансфер имат собствени DTD фаилове(transfer.dtd), които могат да бъдат открити в пакета Apertium. Ако трябва да създадете ново правило е желателно да погледнете във файловете с правила на други езикови двойки първо. Много правила могат да бъдат използвани многократно от различните езици. Например правилото описано по-долу ще е полезно за всеки език, който използва падежи за определяне на личните местоимения(аз, ти, той, ние, вие, те) и те могат да се изпускат.

Започнете като всички други с основна структура:

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

</transfer>

Тъй като в момента игнорираме падежа трябва само да направим правило, което да взема граматичните символи на входа и да ги извежда отново.

Първо трябва да се дефинират категории и атрибути. Категориите и атрибутите позволяват да групираме граматични символи. Категориите позволяват да групуираме символи за съвпадение, например 'n.*' за всички съществителни(nouns). Атрибутите позволяват да се групират символи, от които може да се избира. Например 'sg' и 'pl' могат да се групират в атрибута число (number).

Нека да добавим необходимите раздели:

<section-def-cats>

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

</section-def-attrs>

Тъй като само спрягаме съществителните в единствено и множествено число трябва да добавим категория за съществителни и атрибут за число. Нещо като следващото ще бъде достатъчно:

В section-def-cats се добавя:

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

Това прихваща всички съществителни (леми след които има <n> и след това каквото и да е друг) и се отнася към тях като с "nom"(ще демонстрираме използването му по-късно).

В секцията section section-def-attrs се добавя:

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

и след това

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

Първото дефинира атрибута nbr(номер), който може да бъде и в единствено(sg) и в множествено число(pl).

Второто дефинира атрибута a_nom (атрибут съществително).

Следва да добавим секция за глобални променливи:

<section-def-vars>

</section-def-vars>

Тези променливи се използват за съхранение или трансфер на атрибути между правила. Необходимо ни е само едно за сега:

<def-var n="number"/>

Накрая добавяме правило, което да приеме съществителното и да го генерира в правилната форма. Ще ни трябва секция с правила...

<section-rules>

</section-rules>

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>

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.

For each pattern, there is an associated action, which produces an associated output, out. The output, is a lexical unit (lu).

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.

Let's compile it and test it. Transfer rules are compiled with:

$ apertium-preprocess-transfer apertium-sh-en.trules-sh-en.xml trules-sh-en.bin

Which will generate a trules-sh-en.bin file.

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:

First, lets analyse a word, gramofoni:

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

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>$

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin

It will output:

^gramophone<n><pl>$^@
  • '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.

Try commenting out one of these clip statements, recompiling and seeing what happens.

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin

gramophones\@

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.

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.

Bring on the verbs

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

Note: <p1> denotes first person

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. The 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 morpohlogical dictionary. We'll go through both of these.

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.

There are two forms of you see, one is plural and formal singular (vidite) and the other is singular and informal (vidiš).

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.

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.

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 aswell. 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"/>

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

The '/' is used to demarcate where the stems (the parts between the <l> </l> tags) are added to.

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>

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'.

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>

Note: the content of <i> </i> is the root, not the lemma.

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>$

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

The paradigm is:

<pardef n="s/ee__vblex">

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>

and as always, an entry in the main section:

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

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>$

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>

(again, don't forget to add the sdefs from earlier)

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

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin 

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

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
#see\@

This '#' means that the generator cannot generate the correct lexical form because it does not contain it. Why is this?

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.

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.trules-sh-en.xml in case you forgot).

We need to add a new category for 'verb'.

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

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>

We should also add an attribute for verbs.

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

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>

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

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin
^see<vblex><pri>$^@

and:

$ 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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
see\@

Try it with 'vidimo' (we see) to see if you get the correct output.

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
see gramophones\@

But what about personal pronouns?

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.

As before, the first thing to do is add the necessary symbols:

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

Of the two symbols, prn is pronoun, and subj is subject (as in the subject of a sentence).

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>

With 'prsubj' being 'personal subject'. The rest of them (You, We etc.) are left as an exercise to the reader.

We can add an entry to the main section as follows:

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

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>$

(Note: its in capitals because 'I' is in capitals).

Now we need to amend the 'verb' rule to output the subject personal pronoun along with the correct verb form.

First, add a category (this must be getting pretty pedestrian by now):

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

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>

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>

This is pretty much the same rule as before, only we made a couple of small changes.

We needed to output:

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

so that the generator could choose the right pronoun and the right form of the verb.

So, a quick rundown:

  • <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.

Note that we retrieved the information for number and tense directly from the verb.

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin | \
  lt-proc -g sh-en.autogen.bin
I see gramophones

Which, while it isn't exactly prize-winning prose (much like this HOWTO), is a fairly accurate translation.

So tell me about the record player (Multiwords)

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

We don't need to touch the Serbo-Croatian dictionary, just the English one and the bilingual one this, so open it up.

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>

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.

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.trules-sh-en.xml trules-sh-en.bin sh-en.autobil.bin  | \
  lt-proc -g sh-en.autogen.bin
I see record players

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.

Dealing with minor variation

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.

Analysis

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>

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>

This only allows us to analyse both forms however... more work is necessary if we want to generate both forms.

Generation

See also