Beginner's Constraint Grammar HOWTO

From Apertium
Revision as of 15:14, 30 January 2011 by Unhammer (talk | contribs) (→‎Download)
Jump to navigation Jump to search

Download

Apertium

How to download Apertium for Ubuntu. First open your terminal and copy/paste

   sudo apt-get install subversion build-essential g++ pkg-config libxml2 \
   libxml2-dev libxml2-utils xsltproc flex automake autoconf libtool libpcre3-dev

Then the terminal will ask for your password like this:

   [sudo] password for user

When write it, press Enter.

If you have already prerequisites, it will show you X upgraded, X newly installed, X to remove and X not upgraded. If you don't have it, you have to wait until terminal shows you user@ubuntu:~$. This means the process is ready and the terminal waits for your next step, which is to copy/paste this code:

   svn co http://apertium.svn.sourceforge.net/svnroot/apertium/trunk apertium

This will download apertium from SVN. The process will take a few minutes. When the downloading ends we are ready to install apertium.


Constraint grammar

To use CG we must have lttoolbox (we have it), apertium (we have it too) and ICU (we have to install it now).

How to install ICU for Ubunto. Open terminal and copy/paste this code:

   apt-get install libicu-dev

Now we can install apertium, lttoolbox and CG.

Install

Apertium

Before installing apertium we have to install lttoolbox(which has been downloaded whit apertium at same time).To do that you have to copy/paste this code:

cd apertium

cd lttoolbox/

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./autogen.sh

make

sudo make install

sudo ldconfig


Terminal will ask us for password again [sudo] password for user: When you write it press Enter. Wait to show you terminal user@ubuntu:~/apertium/lttoolbox$ then copy/paste this code:

cd ..

cd apertium/

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./autogen.sh

make

sudo make install

sudo ldconfig

This will start installing apertium.You have to wait a few minutes.When shows you

vasil@ubuntu:~/apertium/apertium$ sudo ldconfig

vasil@ubuntu:~/apertium/apertium$

the process is ready.


Constraint grammar


How to install CG.Open terminal and copy/paste this code:

$ svn co --username anonymous --password anonymous http://beta.visl.sdu.dk/svn/visl/tools/vislcg3/trunk vislcg3

$ cd vislcg3

$ sh autogen.sh --prefix=<prefix>

$ make

$ make install

It will ask you for password [sudo] password for user: . When you write it press Enter.

We are ready.

Usage

For the examples below, we use the language pair apertium-es-ca, but the principles should be applicable to any language pair. First we have to compile this pair. Go into the directory from where you checked out the apertium SVN, then

   cd apertium/apertium-es-ca
   sh autogen.sh
   make

Let's try that what we installed is working. First copy/paste this code:

   echo "vino a la playa" | lt-proc es-ca.automorf.bin

This should give you:

   ^vino/vino<n><m><sg>/venir<vblex><ifi><p3><sg>$ ^a/a<pr>$ ^la/el<det><def><f><sg>/lo<prn><pro><p3><f><sg>$ ^playa/playa<n><f><sg>$

Here we have ambiguities,one between a noun and a verb and other between a determiner and a pronoun.We can write some rules which can impose categorization between two ambiguities.First we define our categories, these can be tags, wordforms or lemmas. It might help to think of them as "coarse tags", which may involve a set of fine tags or lemmas. So, create a file grammar.txt, and add the following text:

   DELIMITERS = "<$.>" ;
   LIST NOUN = n;
   LIST VERB = vblex;
   LIST DET = det;
   LIST PRN = prn;
   LIST PREP = pr;
   SECTION

So first rule is states "When the current lexical unit can be a pronoun or a determiner, and it is followed on the right by a lexical unit which could be a noun, choose the determiner". We have to add this rule to the file, and compile using cg-comp:

rule:


   # 1
   SELECT DET IF
           (0 DET)
           (0 PRN)
           (1 NOUN) ;

compile with:

   $ ./cg-comp grammar.txt grammar.bin
   Sections: 1, Rules: 1, Sets: 6, Tags: 7

To try what we have done copy/paste this code:

   $ echo "vino a la playa" | lt-proc es-ca.automorf.bin |  cg-proc grammar.bin
   ^vino/vino<n><m><sg>/venir<vblex><ifi><p3><sg>$ ^a/a<pr>$ ^la/el<det><def><f><sg>$ ^playa/playa<n><f><sg>$


Second rule is states "When the current lexical unit can be a noun or a verb, if the subsequent two units to the right are preposition and determiner, remove the noun reading." Now we have to add this rule:


rule:

   # 2
   REMOVE NOUN IF
           (0 NOUN)
           (0 VERB)
           (1 PREP)
           (2 DET) ;

re-compile the grammar and test:

   $ echo "vino a la playa" | lt-proc es-ca.automorf.bin |  cg-proc grammar.bin
   ^vino/venir<vblex><ifi><p3><sg>$ ^a/a<pr>$ ^la/el<det><def><f><sg>$ ^playa/playa<n><f><sg>$

Third rule states "Remove interjection if the preceeding word is a modal verb."