org.ow2.weblab.service.translate.moses
Class MosesTranslator

java.lang.Object
  extended by org.ow2.weblab.service.translate.moses.MosesTranslator
All Implemented Interfaces:
Translator

public class MosesTranslator
extends java.lang.Object
implements Translator

MosesParser hide command line usage. Takes a moses.ini file as parameter and enables direct String translation

Author:
Jérémie Doucy, CASSIDIAN, an EADS company

Field Summary
protected  java.io.BufferedReader br
          Use it to read the translation response
protected  java.io.BufferedWriter bw
          Use it to writes the translation request
static java.lang.String DEFAULT_ESCAPED_REG_EXP
          Default value for escaped regular expression
protected  java.lang.String escapedRegExp
          Escaped regular expression
protected  java.lang.String langCode
          ISO 639-1 code language
protected static org.apache.commons.logging.Log LOGGER
          Logger
protected  java.lang.String mosesIniPath
          Path to the moses.ini file.
 
Constructor Summary
MosesTranslator(java.lang.String mosesIniPath, java.lang.String langCode)
          Creates a MosesParser using a moses.ini file with the default escaped regular expression
MosesTranslator(java.lang.String mosesIniPath, java.lang.String langCode, java.lang.String escapedRegExp)
          Creates a MosesParser using a moses.ini file.
 
Method Summary
protected  java.lang.String cleanString(java.lang.String toBeCleaned)
           
 java.lang.String getLangCode()
          Return the translated language code using ISO 639-1
protected  void launchCommand()
          Launch the moses -f moses.ini command.
 java.lang.String toString()
           
 java.lang.String translate(java.lang.String toBeTranslated)
          Translate into another language using previously defined moses.ini file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

escapedRegExp

protected java.lang.String escapedRegExp
Escaped regular expression


DEFAULT_ESCAPED_REG_EXP

public static final java.lang.String DEFAULT_ESCAPED_REG_EXP
Default value for escaped regular expression

See Also:
Constant Field Values

langCode

protected java.lang.String langCode
ISO 639-1 code language


mosesIniPath

protected java.lang.String mosesIniPath
Path to the moses.ini file. Paths inside the file must be absolute.


br

protected java.io.BufferedReader br
Use it to read the translation response


bw

protected java.io.BufferedWriter bw
Use it to writes the translation request


LOGGER

protected static org.apache.commons.logging.Log LOGGER
Logger

Constructor Detail

MosesTranslator

public MosesTranslator(java.lang.String mosesIniPath,
                       java.lang.String langCode,
                       java.lang.String escapedRegExp)
                throws java.io.IOException
Creates a MosesParser using a moses.ini file.

Parameters:
mosesIniPath - path to moses.ini file
langCode - destination language code
escapedRegExp - regular expression used to escape some char not well used by moses
Throws:
java.io.IOException - Something is wrong in the moses configuration file

MosesTranslator

public MosesTranslator(java.lang.String mosesIniPath,
                       java.lang.String langCode)
                throws java.io.IOException
Creates a MosesParser using a moses.ini file with the default escaped regular expression

Parameters:
mosesIniPath - path to moses.ini file
langCode - destination language code
Throws:
java.io.IOException - Something is wrong in the moses configuration file
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

launchCommand

protected void launchCommand()
                      throws java.io.IOException
Launch the moses -f moses.ini command. Initialize in writer and out reader.

Throws:
java.io.IOException - something wring when trying to invoke the command line

translate

public java.lang.String translate(java.lang.String toBeTranslated)
                           throws java.io.IOException
Translate into another language using previously defined moses.ini file.

Specified by:
translate in interface Translator
Parameters:
toBeTranslated - the String to be translated in
Returns:
the translated String
Throws:
java.io.IOException - something wrong during the translation

cleanString

protected java.lang.String cleanString(java.lang.String toBeCleaned)

getLangCode

public java.lang.String getLangCode()
Return the translated language code using ISO 639-1

Specified by:
getLangCode in interface Translator
Returns:
the translated language


Copyright © 2004-2011. All Rights Reserved.