com.penguinwerks.jodene.data
Class KClassTranslator
java.lang.Object
com.penguinwerks.jodene.data.Translator
com.penguinwerks.jodene.data.KClassTranslator
- All Implemented Interfaces:
- java.io.Serializable
- public class KClassTranslator
- extends Translator
- implements java.io.Serializable
This translates one of a set of strings into an array of values,
such that there is a member for each possible string. In the order
in which the strings are defined, a 0.0 appears for all values, except
the one recieved.
An example: if { "dog", "cat", "gold-fish" } are the three possible
strings (in order), then the following map applies
- "dog" -> 1.0, 0.0, 0.0
- "cat" -> 0.0, 1.0, 0.0
- "gold-fish" -> 0.0, 0.0, 1.0
A non-defined string throws a translator exception.
- Author:
- Paul Hoehne
- See Also:
- Serialized Form
|
Method Summary |
int |
getOutputSize()
Indicates the size of K. |
double[] |
translate(java.lang.String values)
Translates a string value to a series of double values. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
KClassTranslator
public KClassTranslator()
translate
public double[] translate(java.lang.String values)
throws TranslatorException
- Translates a string value to a series of double values. For each
expected string value there is a corresponding value. So, if there
are K strings { k1, k2, ... kn } The resulting array of double is size
K. For example, { "car", "plane", "boat", "train" } is a set of
4 doubles where { 1.0, 0.0, 0.0, 0.0 } for "car", { 0.0, 1.0, 0.0, 0.0 }
for plane, etc. If an unexpected string is sent in "rocket", in our
example, then an exception is thrown.
- Specified by:
translate in class Translator
- Parameters:
values - The raw string value.
- Returns:
- An array of doubles which represent the string value.
- Throws:
TranslatorException - An exception if the string is not a known class.
getOutputSize
public int getOutputSize()
- Indicates the size of K. Indicates how many elements in K.
- Specified by:
getOutputSize in class Translator
- Returns:
- Size of K