Difference between revisions of "D-Bus service for Apertium"

From Apertium
Jump to navigation Jump to search
m (svn link updated)
 
(31 intermediate revisions by 8 users not shown)
Line 1: Line 1:
  +
{{TOCD}}
 
[http://dbus.freedesktop.org/ D-Bus] is a simple inter-process communication system. We are in the process of developing D-Bus services for Apertium which will make programmatic access to the Apertium tools easier.
 
[http://dbus.freedesktop.org/ D-Bus] is a simple inter-process communication system. We are in the process of developing D-Bus services for Apertium which will make programmatic access to the Apertium tools easier.
  +
We have started developing simple D-Bus bindings for Apertium which allow for:
  +
* discovery of details of the current Apertium installation and,
  +
* translations via a programmatic interface.
   
  +
The D-Bus bindings are needed for some of the tools, such as [[Apertium-view]] and [[Apertium-tolk]].
==D-Bus bus names==
 
D-Bus allows services to be registered under Java style package names (e.g. org.apertium.my_service).
 
   
  +
==Prerequisites==
We envision two services:
 
* org.apertium.info - this will expose objects to query various aspects of the installed apertium system.
 
* org.apertium.translate - this will exposes translation functions.
 
   
  +
* apertium (>= 3.0.0)
Multiple objects can be registered with each service. Objects are given UNIX path names. For example, suppose we have English-Polish (en-pl) and English-Catalan (en-ca) translation modes installed in our system, then org.apertium.translate will expose at least four translation objects:
 
  +
* python
  +
* dbus
  +
* python-dbus
   
  +
==Installing==
* English->Catalan translation object,
 
* Catalan->English translation object,
 
* English->Polish translation object,
 
* Polish->English translation object.
 
   
  +
'''Note:''' After Apertium's migration to GitHub, this tool is '''read-only''' on the SourceForge repository and does not exist on GitHub. If you are interested in migrating this tool to GitHub, see [[Migrating tools to GitHub]].
Given that one invokes these modes from the command line with "apertium en-ca", "apertium ca-en", "apertium en-pl" and "apertium pl-en", a good naming scheme for the objects would be:
 
   
  +
The package is available from [[SVN]] in the <code>apertium-dbus</code> module. The process for installation is the standard:
* /en-ca for the English->Catalan translation object
 
* /ca-en for the Catalan->English translation object
 
* /en-pl for the English->Polish translation object
 
* /pl-en for the Polish->English translation object
 
   
  +
<pre>
These objects will have the full names org.apertium.translate/en-ca, org.apertium.translate/ca-en, org.apertium.translate/en-pl and org.apertium.translate/pl-en.
 
  +
$ svn co https://svn.code.sf.net/p/apertium/svn/trunk/apertium-dbus
  +
</pre>
   
  +
<pre>
===Alternative===
 
  +
$ ./autogen.sh
  +
$ make
  +
$ make install
  +
</pre>
   
  +
The current package is in the process of being ported to Python3, but should work. Do "svn up -r25849" if you want to get the last working Python2 version instead.
Something that just creates the pipeline from the modes.xml file would be good, and then exposes each mode. If people want to change it they can edit the modes file, e.g.:
 
   
  +
===Check that it works===
:<code>org.apertium.info</code>
 
  +
You can check that the bindings work by issuing the command:
  +
:<code>dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes</code>
  +
This should return an array of strings of all the Apertium modes installed on your system. It should look something like
  +
<pre>
  +
$ dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes
  +
method return sender=:1.567 -> dest=:1.599 reply_serial=2
  +
array [
  +
string "en-ca"
  +
string "ca-en"
  +
string "en-af"
  +
string "af-en"
  +
]
  +
</pre>
   
  +
To translate from the command line (assuming apertium-en-ca is installed), try e.g.
Would list information about what modes are installed, and what they correspond to (e.g. human readable language names, metadata that stuff... this could be in a separate "directory" xml file that is updated with each package installed.)
 
  +
<pre>
  +
$ dbus-send --print-reply --dest=org.apertium.mode / org.apertium.Translate.translate string:en-ca dict:string:string:"mark_unknown","true" string:'My hoovercraft is full of eels'
  +
</pre>
   
  +
If the above two commannds don't work, then it's quite possible that a Python error from our side snuck in. Try running info.py directly; that is
:<code>org.apertium.mode/<name></code>
 
  +
:<code>python info.py -p /usr/local</code>
  +
where the prefix for Apertium in the above example is <code>/usr/local</code>. If you get a Python error, please post the error on this page or post a bug report in [http://bugs.apertium.org/cgi-bin/bugzilla/index.cgi our bug tracker]. If the service starts up without errors, try executing
  +
:<code>dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes</code>
  +
again. If there is no output, then open a new terminal and run
  +
:<code>dbus-monitor</code>.
  +
This neat utility shows you the activity on the D-Bus. Now try executing <code>dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes</code> again.
   
Would be an interface to exectute a particular mode on a piece of text. Of course you still have the problem of the other command line options (<code>-u</code>, <code>-f</code>, etc...)
+
If you have no luck, come and talk to us in <code>#apertium</code> at <code>irc.freenode.net</code>
   
  +
==Installing into a prefix==
  +
:''This is unfinished''
  +
  +
*Do: mkdir -p <prefix>/share/dbus-1/services/
  +
  +
*Make a session-local.conf file like it says [http://www.linuxfromscratch.org/blfs/view/svn/general/dbus.html here] under "" Configuration Information"".
  +
**Change the <servicedir> element value to <prefix>/share/dbus-1/services/
  +
* Restart dbus. /etc/init.d/dbus restart
  +
* Log out and log back in again
  +
  +
==Interfaces==
  +
Currently, Apertium offers two D-Bus services:
  +
* <code>org.apertium.info</code> has a single object <code>/</code>, which offers rudimentary information about the Apertium installation.
  +
* <code>org.apertium.translate</code> contains an object for each Apertium mode installed in the system.
  +
  +
==Issues==
  +
If you make a change to any of the D-Bus configuration files, you will need to restart both the system-wide and session D-Bus daemons. The system-wide daemon can be restarted on a Debian/Ubuntu system with:
  +
*<code>/etc/init.d/dbus restart</code>
  +
The only real way to restart your session deamon is to logout and log back in again. You will likely run into strange problems if you attempt to kill the session D-Bus daemon.
  +
  +
==Filesystem layout==
  +
  +
* <code>/usr/share/dbus-1/services/</code> &mdash; DBUS <code>.service</code> files.
  +
* <code>/usr/share/apertium/dbus-1/</code> &mdash; Python code that actually does the service (<code>info.py</code> and <code>mode.py</code>)
  +
  +
==Examples==
  +
  +
There are some simple examples in various languages on the page [[D-Bus examples]].
  +
  +
==External links==
  +
  +
* [http://www.pygtk.org/articles/applets_arturogf/x207.html Autotoolising python]
   
 
[[Category:Development]]
 
[[Category:Development]]
  +
[[Category:Services]]
  +
[[Category:Documentation in English]]

Latest revision as of 19:36, 13 April 2018

D-Bus is a simple inter-process communication system. We are in the process of developing D-Bus services for Apertium which will make programmatic access to the Apertium tools easier. We have started developing simple D-Bus bindings for Apertium which allow for:

  • discovery of details of the current Apertium installation and,
  • translations via a programmatic interface.

The D-Bus bindings are needed for some of the tools, such as Apertium-view and Apertium-tolk.

Prerequisites[edit]

  • apertium (>= 3.0.0)
  • python
  • dbus
  • python-dbus

Installing[edit]

Note: After Apertium's migration to GitHub, this tool is read-only on the SourceForge repository and does not exist on GitHub. If you are interested in migrating this tool to GitHub, see Migrating tools to GitHub.

The package is available from SVN in the apertium-dbus module. The process for installation is the standard:

$ svn co https://svn.code.sf.net/p/apertium/svn/trunk/apertium-dbus
$ ./autogen.sh
$ make 
$ make install

The current package is in the process of being ported to Python3, but should work. Do "svn up -r25849" if you want to get the last working Python2 version instead.

Check that it works[edit]

You can check that the bindings work by issuing the command:

dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes

This should return an array of strings of all the Apertium modes installed on your system. It should look something like

$ dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes 
method return sender=:1.567 -> dest=:1.599 reply_serial=2
   array [
      string "en-ca"
      string "ca-en"
      string "en-af"
      string "af-en"
   ]

To translate from the command line (assuming apertium-en-ca is installed), try e.g.

$ dbus-send --print-reply --dest=org.apertium.mode / org.apertium.Translate.translate string:en-ca dict:string:string:"mark_unknown","true" string:'My hoovercraft is full of eels'

If the above two commannds don't work, then it's quite possible that a Python error from our side snuck in. Try running info.py directly; that is

python info.py -p /usr/local

where the prefix for Apertium in the above example is /usr/local. If you get a Python error, please post the error on this page or post a bug report in our bug tracker. If the service starts up without errors, try executing

dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes

again. If there is no output, then open a new terminal and run

dbus-monitor.

This neat utility shows you the activity on the D-Bus. Now try executing dbus-send --print-reply --dest=org.apertium.info / org.apertium.Info.modes again.

If you have no luck, come and talk to us in #apertium at irc.freenode.net

Installing into a prefix[edit]

This is unfinished
  • Do: mkdir -p <prefix>/share/dbus-1/services/
  • Make a session-local.conf file like it says here under "" Configuration Information"".
    • Change the <servicedir> element value to <prefix>/share/dbus-1/services/
  • Restart dbus. /etc/init.d/dbus restart
  • Log out and log back in again

Interfaces[edit]

Currently, Apertium offers two D-Bus services:

  • org.apertium.info has a single object /, which offers rudimentary information about the Apertium installation.
  • org.apertium.translate contains an object for each Apertium mode installed in the system.

Issues[edit]

If you make a change to any of the D-Bus configuration files, you will need to restart both the system-wide and session D-Bus daemons. The system-wide daemon can be restarted on a Debian/Ubuntu system with:

  • /etc/init.d/dbus restart

The only real way to restart your session deamon is to logout and log back in again. You will likely run into strange problems if you attempt to kill the session D-Bus daemon.

Filesystem layout[edit]

  • /usr/share/dbus-1/services/ — DBUS .service files.
  • /usr/share/apertium/dbus-1/ — Python code that actually does the service (info.py and mode.py)

Examples[edit]

There are some simple examples in various languages on the page D-Bus examples.

External links[edit]