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 classKantanMTv21Connector.RequestInfoWrapper 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 StringSTATE_INITIALISINGstatic StringSTATE_OFFLINEstatic StringSTATE_RUNNINGstatic StringSTATE_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 APIvoidclose()Closes this connector.StringgetEngines()Gets the information about the available engines.StringgetEngineStatus(String engine)Get the status of an engine.StringgetName()Gets the name of the connector.KantanMTv21ConnectorParametersgetParameters()Gets the current parameters of this connector.StringgetSettingsDisplay()Gets a display representation of the current settings for this connector.booleanhasNext()Indicates of there is a hit available.QueryResultnext()Gets the next hit for the last query.voidopen()Opens this query engine.intquery(String plainText)Starts a query for a give plain text.intquery(TextFragment tf)Starts a query for a given text.StringstartEngine(String engine)Starts an engine (do nothing if it's already started).StringstopEngine(String engine)Stops an engine (do nothing if it's already stopped).protected StringtoInternalCode(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:IQueryGets the name of the connector.- Returns:
- the name of the connector.
-
getSettingsDisplay
public String getSettingsDisplay()
Description copied from interface:IQueryGets 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:IQueryOpens this query engine.
-
close
public void close()
Description copied from interface:IQueryCloses this connector.
-
getParameters
public KantanMTv21ConnectorParameters getParameters()
Description copied from interface:IQueryGets the current parameters of this connector.- Specified by:
getParametersin interfaceIQuery- Overrides:
getParametersin 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:BaseConnectorConverts 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:
toInternalCodein 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:IQueryStarts 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:IQueryStarts 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:IQueryIndicates of there is a hit available.- Specified by:
hasNextin interfaceIQuery- Specified by:
hasNextin interfaceIterator<QueryResult>- Overrides:
hasNextin classBaseConnector- Returns:
- True if a hit is available, false if not.
-
next
public QueryResult next()
Description copied from interface:IQueryGets the next hit for the last query.- Specified by:
nextin interfaceIQuery- Specified by:
nextin interfaceIterator<QueryResult>- Overrides:
nextin 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:BaseConnectorSlow default implementation using query!! Override to take advantage of servers batch API- Specified by:
batchQueryin interfaceIQuery- Overrides:
batchQueryin 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).
-
-