Apertium-apy/Fedora

From Apertium
Jump to navigation Jump to search

This is a quickstart guide to setting up your very own Apertium API server on Fedora.


Why?[edit]

Running your own API server means

  • you get to decide what kinds of crazy half-finished language pairs to serve (or you can just serve a few of the high-quality ones that you like)
  • you can run Apertium within your super-fortified network without your highly confidential translations touching anyone else's computer
  • you don't have to worry about anyone else's API server going down right when you need it the most
  • you have control over how many concurrent apertium processes you run (if your site or program calls plain `apertium` on each request, you can easily overload your server)


Quickstart[edit]

Add the RPM repo:

curl -sS https://apertium.projectjj.com/rpm/install-nightly.sh | sudo bash

Now install APY and the language pairs you want:

sudo dnf clean metadata
sudo dnf upgrade -y
sudo dnf install apertium-apy
sudo dnf install apertium-eng-kaz apertium-sme-nob apertium-hbs-mkd apertium-eo-en apertium-tat-rus # etc.

(Here we're assuming you only want packaged pairs, see Installation on how to install pairs that are only in SVN.)


You can now start APY like this:

sudo systemctl start apertium-apy

and enable it for starting after a reboot like this:

sudo systemctl enable apertium-apy

Test that it works[edit]

You can do

sudo systemctl status apertium-apy

and it should show something like

● apertium-apy.service - Apertium APY service
   Loaded: loaded (/lib/systemd/system/apertium-apy.service; disabled; vendor preset: enabled)
   Active: active (running) since må. 2016-06-13 11:38:10 CEST; 3s ago
     Docs: http://wiki.apertium.org/wiki/Apertium-apy
 Main PID: 14813 (python3)
   CGroup: /system.slice/apertium-apy.service
           └─14813 /usr/bin/python3 servlet.py /usr/share/apertium/modes

juni 13 11:38:10 gamlepadda systemd[1]: Started Apertium APY service.
juni 13 11:38:11 gamlepadda python3[14813]: [W 160613 11:38:11 servlet:865] Unable to import CLD2, continuing using naive method of lang
juni 13 11:38:11 gamlepadda python3[14813]: [I 160613 11:38:11 servlet:792] 7 pair modes found
juni 13 11:38:11 gamlepadda python3[14813]: [I 160613 11:38:11 servlet:792] 0 analyzer modes found
juni 13 11:38:11 gamlepadda python3[14813]: [I 160613 11:38:11 servlet:792] 0 generator modes found
juni 13 11:38:11 gamlepadda python3[14813]: [I 160613 11:38:11 servlet:792] 0 tagger modes found
juni 13 11:38:11 gamlepadda python3[14813]: [I 160613 11:38:11 servlet:898] Serving at http://localhost:2737

if it's started. (Press q to get your terminal back if it put you in less-mode.)


Try checking what language data it found:

curl http://localhost:2737/listPairs

It should contain a list of pairs.


Say the list contains {"sourceLanguage": "sme", "targetLanguage": "nob"}, then we can try translating the sentence "in leat doppe" from sme to nob:

curl 'http://localhost:2737/translate?langpair=sme|nob&q=in+leat+doppe'

That should give something like {"responseData": {"translatedText": "jeg er ikke der borte"}, "responseDetails": null, "responseStatus": 200} .


If everything worked, congrats, you have your own Apertium API server running!

Now open port 2737 in your firewall and point your website or app at it :-)


If you ran into trouble, please ask for help on IRC or the mailing list.

If you don't have/want root[edit]

See Apertium-apy#Running_as_a_--user_unit.

Firewall[edit]

To open ports permanently in a Fedora server running firewalld, do:

sudo firewall-cmd --permanent --new-service=apy
sudo vim /etc/firewalld/services/apy.xml

paste this into the file:

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>APY Apertium MT Server</short>
  <description>APY is an API server for the Apertium Machine Translation Platform, written in Python. See http://wiki.apertium.org/wiki/Apertium-apy or https://github.com/apertium/apertium-apy/ for more information.</description>
  <port protocol="tcp" port="2737"/>
</service>

Then do:

sudo firewall-cmd --permanent --add-service=apy
sudo firewall-cmd --reload

Jorgal[edit]

http://gtweb.uit.no/jorgal runs a fork of APY on Fedora; the systemd unit there is called "apy", not "apertium-apy", see Jorgal.

More info[edit]

See Apertium-apy for other things you can do with Apy and more documentation.