/** * A helper method for {@link #getFeatureKey(Lexicon,boolean,int)}, this method computes the * feature keys corresponding to the arguments of the conjunction. Here, we lookup the arguments * to the conjunction in the lexicon so that their counts are never less than the conjunction's, * and we return the actual feature object that's already a key in the lexicon. * * @param f The argument feature for which a key will be computed. * @param lexicon The lexicon into which this feature will be indexed. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature object appropriate for use as the key of a map. **/ protected DiscreteFeature getArgumentKey(Feature f, Lexicon lexicon, int label) { if (!f.isPrimitive()) f = f.getFeatureKey(lexicon, true, label); return (DiscreteFeature) lexicon.getChildFeature(f, label); }
/** * Return the feature that should be used to index this feature into a lexicon. Specifically, we * return this feature with a value of 0 so that the same features with different real values * will map to the same object. * * @param lexicon The lexicon into which this feature will be indexed. * @param training Whether or not the learner is currently training. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature object appropriate for use as the key of a map. **/ public Feature getFeatureKey(Lexicon lexicon, boolean training, int label) { RealFeature f = (RealFeature) referent.getFeatureKey(lexicon, training, label); if (training) f = (RealFeature) lexicon.getChildFeature(f, label); return new RealReferringFeature(containingPackage, generatingClassifier, identifier, f); }
/** * Return the feature that should be used to index this feature into a lexicon. Specifically, we * return this feature with a value of 0 so that the same features with different real values * will map to the same object. * * @param lexicon The lexicon into which this feature will be indexed. * @param training Whether or not the learner is currently training. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature object appropriate for use as the key of a map. **/ public Feature getFeatureKey(Lexicon lexicon, boolean training, int label) { RealFeature f = (RealFeature) referent.getFeatureKey(lexicon, training, label); if (training) f = (RealFeature) lexicon.getChildFeature(f, label); return new RealReferringStringFeature(containingPackage, generatingClassifier, identifier, f); }
/** * Return the feature that should be used to index this feature into a lexicon. If it is a * binary feature, we return the feature with an empty value so that the feature will be mapped * to the same weight whether it is active or not. If the feature can take multiple values, then * simply return the feature object as-is. * * @param lexicon The lexicon into which this feature will be indexed. * @param training Whether or not the learner is currently training. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature object appropriate for use as the key of a map. **/ public Feature getFeatureKey(Lexicon lexicon, boolean training, int label) { DiscreteFeature f = (DiscreteFeature) referent.getFeatureKey(lexicon, training, label); if (training) f = (DiscreteFeature) lexicon.getChildFeature(f, label); else if (f == referent) return this; return new DiscreteReferringFeature(containingPackage, generatingClassifier, identifier, f, valueIndex, totalValues); }
/** * Return the feature that should be used to index this feature into a lexicon. If it is a * binary feature, we return the feature with an empty value so that the feature will be mapped * to the same weight whether it is active or not. If the feature can take multiple values, then * simply return the feature object as-is. * * @param lexicon The lexicon into which this feature will be indexed. * @param training Whether or not the learner is currently training. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature object appropriate for use as the key of a map. **/ public Feature getFeatureKey(Lexicon lexicon, boolean training, int label) { DiscreteFeature f = (DiscreteFeature) referent.getFeatureKey(lexicon, training, label); if (training) f = (DiscreteFeature) lexicon.getChildFeature(f, label); else if (f == referent) return this; return new DiscreteReferringStringFeature(containingPackage, generatingClassifier, identifier, f, valueIndex, totalValues); }
/** * A helper method for {@link #getFeatureKey(Lexicon,boolean,int)}, this method computes the * feature keys corresponding to the arguments of the conjunction. Here, we lookup the arguments * to the conjunction in the lexicon so that their counts are never less than the conjunction's, * and we return the actual feature object that's already a key in the lexicon. * * @param f The argument feature for which a key will be computed. * @param lexicon The lexicon into which this feature will be indexed. * @param training Whether or not the learner is currently training. * @param label The label of the example containing this feature, or -1 if we aren't doing per * class feature counting. * @return A feature object appropriate for use as the key of a map. **/ protected Feature getArgumentKey(Feature f, Lexicon lexicon, boolean training, int label) { if (f.isDiscrete()) { if (!training) return f; if (!f.isPrimitive()) f = f.getFeatureKey(lexicon, true, label); } else { f = f.getFeatureKey(lexicon, training, label); if (!training) return f; } return lexicon.getChildFeature(f, label); }