/** * Converts an example object into an array of arrays representing the example including its * labels. The first array contains the integer keys of the example's features, as indexed in * the lexicon. The second array gives the double values corresponding to the strengths of the * features in the first array. The third and fourth arrays play the same roles as the first and * second arrays respectively, except they describe the labels. * * @param example The example object. * @return The converted example array. **/ public Object[] getExampleArray(Object example) { return getExampleArray(example, true); }
/** * Returns the classification of the given example object as a single feature instead of a * {@link FeatureVector}. * * @param example The object to classify. * @return The classification of <code>example</code> as a feature. **/ public Feature featureValue(Object example) { Object[] exampleArray = getExampleArray(example, false); return featureValue((int[]) exampleArray[0], (double[]) exampleArray[1]); }
/** * This method makes one or more decisions about a single object, returning those decisions as * {@link Feature}s in a vector. * * @param example The object to make decisions about. * @return A vector of {@link Feature}s about the input object. **/ public FeatureVector classify(Object example) { Object[] exampleArray = getExampleArray(example, false); return classify((int[]) exampleArray[0], (double[]) exampleArray[1]); }
/** * Returns the value of the discrete prediction that this learner would make, given an example. * * @param example The example object. * @return The discrete value. **/ public String discreteValue(Object example) { Object[] exampleArray = getExampleArray(example, false); return discreteValue((int[]) exampleArray[0], (double[]) exampleArray[1]); }
/** * Trains the learning algorithm given an object as an example. By default, this simply converts * the example object into arrays and passes it to {@link #learn(int[],double[],int[],double[])} * . * * @param example An example of the desired learned classifier's behavior. **/ public void learn(Object example) { Object[] exampleArray = getExampleArray(example); learn((int[]) exampleArray[0], (double[]) exampleArray[1], (int[]) exampleArray[2], (double[]) exampleArray[3]); }
/** * Returns the value of the real prediction that this learner would make, given an example. * * @param example The example object. * @return The real value. **/ public double realValue(Object example) { Object[] exampleArray = getExampleArray(example, false); return realValue((int[]) exampleArray[0], (double[]) exampleArray[1]); }
/** * Produces a set of scores indicating the degree to which each possible discrete classification * value is associated with the given example object. Learners that return a <code>real</code> * feature or more than one feature may implement this method by simply returning * <code>null</code>. * * @param example The object to make decisions about. * @return A set of scores indicating the degree to which each possible discrete classification * value is associated with the given example object. **/ public ScoreSet scores(Object example) { Object[] exampleArray = getExampleArray(example, false); ScoreSet resultS = scores((int[]) exampleArray[0], (double[]) exampleArray[1]); if (!lossFlag) return resultS; else return scoresAugmented(example, resultS); }
Object[] exampleArray = alreadyExtracted ? (Object[]) example : preExtractLearner .getExampleArray(example);