Package net.sf.okapi.connectors.kantan
Class KantanMTv21Connector
- java.lang.Object
-
- net.sf.okapi.lib.translation.BaseConnector
-
- net.sf.okapi.connectors.kantan.KantanMTv21Connector
-
- All Implemented Interfaces:
AutoCloseable
,Iterator<QueryResult>
,IQuery
public class KantanMTv21Connector extends BaseConnector
Connector for the KantanMT API v2.1. The engine must be started separately (through the KantanMT web interface, or via API) and is assumed to be running by this connector. As the engine initialization process takes several minutes, the connector does not perform initialization on its own in theopen()
method.- See Also:
- http://docs.kantanmt.apiary.io Note: KantanMT uses TLS 1.2, which is supported by default by Java 8 (but not Java 7)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
KantanMTv21Connector.RequestInfo
Wrapper to hold the original fragment along with its extracted codes, so that we can reinsert them into the translated target.
-
Field Summary
Fields Modifier and Type Field Description static String
STATE_INITIALISING
static String
STATE_OFFLINE
static String
STATE_RUNNING
static String
STATE_TERMINATING
-
Constructor Summary
Constructors Constructor Description KantanMTv21Connector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<List<QueryResult>>
batchQuery(List<TextFragment> fragments)
Slow default implementation using query!! Override to take advantage of servers batch APIvoid
close()
Closes this connector.String
getEngines()
Gets the information about the available engines.String
getEngineStatus(String engine)
Get the status of an engine.String
getName()
Gets the name of the connector.KantanMTv21ConnectorParameters
getParameters()
Gets the current parameters of this connector.String
getSettingsDisplay()
Gets a display representation of the current settings for this connector.boolean
hasNext()
Indicates of there is a hit available.QueryResult
next()
Gets the next hit for the last query.void
open()
Opens this query engine.int
query(String plainText)
Starts a query for a give plain text.int
query(TextFragment tf)
Starts a query for a given text.String
startEngine(String engine)
Starts an engine (do nothing if it's already started).String
stopEngine(String engine)
Stops an engine (do nothing if it's already stopped).protected String
toInternalCode(LocaleId locId)
Converts a locale identifier to the internal string value for a language/locale code for this connector.-
Methods inherited from class net.sf.okapi.lib.translation.BaseConnector
batchLeverage, batchLeverageUsingBatchQuery, batchQueryText, clearAttributes, getNoQueryThreshold, getSourceLanguage, getTargetLanguage, getWeight, leverage, leverageUsingBatchQuery, removeAttribute, setAttribute, setLanguages, setNoQueryThreshold, setParameters, setRootDirectory, setWeight
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Field Detail
-
STATE_OFFLINE
public static final String STATE_OFFLINE
- See Also:
- Constant Field Values
-
STATE_RUNNING
public static final String STATE_RUNNING
- See Also:
- Constant Field Values
-
STATE_INITIALISING
public static final String STATE_INITIALISING
- See Also:
- Constant Field Values
-
STATE_TERMINATING
public static final String STATE_TERMINATING
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:IQuery
Gets the name of the connector.- Returns:
- the name of the connector.
-
getSettingsDisplay
public String getSettingsDisplay()
Description copied from interface:IQuery
Gets a display representation of the current settings for this connector. This can be a display of some of the parameters for example, or some explanations about default non-modifiable settings.- Returns:
- a display representation of the current settings.
-
open
public void open()
Description copied from interface:IQuery
Opens this query engine.
-
close
public void close()
Description copied from interface:IQuery
Closes this connector.
-
getParameters
public KantanMTv21ConnectorParameters getParameters()
Description copied from interface:IQuery
Gets the current parameters of this connector.- Specified by:
getParameters
in interfaceIQuery
- Overrides:
getParameters
in classBaseConnector
- Returns:
- the current parameters of this connector or null if no parameters are used.
-
toInternalCode
protected String toInternalCode(LocaleId locId)
Description copied from class:BaseConnector
Converts a locale identifier to the internal string value for a language/locale code for this connector. By default, this simply returns the string of the given LocaleId.- Overrides:
toInternalCode
in classBaseConnector
- Parameters:
locId
- the locale identifier to convert.- Returns:
- the internal string code for language/locale code for this connector.
-
query
public int query(String plainText)
Description copied from interface:IQuery
Starts a query for a give plain text.- Parameters:
plainText
- text to query.- Returns:
- The number of hits for the given query.
-
query
public int query(TextFragment tf)
Description copied from interface:IQuery
Starts a query for a given text.- Parameters:
tf
- The text to query.- Returns:
- The number of hits for the given query.
-
hasNext
public boolean hasNext()
Description copied from interface:IQuery
Indicates of there is a hit available.- Specified by:
hasNext
in interfaceIQuery
- Specified by:
hasNext
in interfaceIterator<QueryResult>
- Overrides:
hasNext
in classBaseConnector
- Returns:
- True if a hit is available, false if not.
-
next
public QueryResult next()
Description copied from interface:IQuery
Gets the next hit for the last query.- Specified by:
next
in interfaceIQuery
- Specified by:
next
in interfaceIterator<QueryResult>
- Overrides:
next
in classBaseConnector
- Returns:
- A QueryResult object that holds the source and target text of the hit, or null if there is no more hit.
-
batchQuery
public List<List<QueryResult>> batchQuery(List<TextFragment> fragments)
Description copied from class:BaseConnector
Slow default implementation using query!! Override to take advantage of servers batch API- Specified by:
batchQuery
in interfaceIQuery
- Overrides:
batchQuery
in classBaseConnector
- Parameters:
fragments
- list of the text fragments to translate.- Returns:
- a list of lists of query result. Each list corresponds to a source text (in the same order)
-
getEngines
public String getEngines()
Gets the information about the available engines.- Returns:
- A JSON string with the engine information.
-
getEngineStatus
public String getEngineStatus(String engine)
Get the status of an engine.- Parameters:
engine
- the name of the engine to check.- Returns:
- the status information ('running' for when it is online and ready, etc.)
-
startEngine
public String startEngine(String engine)
Starts an engine (do nothing if it's already started).- Parameters:
engine
- the name of the engine to start.- Returns:
- the status of the engine after the call (e.g. 'running' if it is running already).
-
-