use of edu.stanford.nlp.sequences.Clique in project CoreNLP by stanfordnlp.
the class CRFBiasedClassifier method makeDatum.
@Override
public CRFDatum<List<String>, CRFLabel> makeDatum(List<IN> info, int loc, List<FeatureFactory<IN>> featureFactories) {
pad.set(CoreAnnotations.AnswerAnnotation.class, flags.backgroundSymbol);
PaddedList<IN> pInfo = new PaddedList<>(info, pad);
List<List<String>> features = new ArrayList<>();
Collection<Clique> done = Generics.newHashSet();
for (int i = 0; i < windowSize; i++) {
List<String> featuresC = new ArrayList<>();
List<Clique> windowCliques = FeatureFactory.getCliques(i, 0);
windowCliques.removeAll(done);
done.addAll(windowCliques);
for (Clique c : windowCliques) {
for (FeatureFactory<IN> featureFactory : featureFactories) {
featuresC.addAll(featureFactory.getCliqueFeatures(pInfo, loc, c));
}
if (testTime && i == 0)
// this feature is only present at test time and only appears
// in cliques of size 1 (i.e., cliques with window=0)
featuresC.add(BIAS);
}
features.add(featuresC);
}
int[] labels = new int[windowSize];
for (int i = 0; i < windowSize; i++) {
String answer = pInfo.get(loc + i - windowSize + 1).get(CoreAnnotations.AnswerAnnotation.class);
labels[i] = classIndex.indexOf(answer);
}
return new CRFDatum<>(features, new CRFLabel(labels), null);
}
use of edu.stanford.nlp.sequences.Clique in project CoreNLP by stanfordnlp.
the class CMMClassifier method makeDatum.
/** Make an individual Datum out of the data list info, focused at position loc.
*
* @param info A List of IN objects
* @param loc The position in the info list to focus feature creation on
* @param featureFactories The factory that constructs features out of the item
* @return A Datum (BasicDatum) representing this data instance
*/
public Datum<String, String> makeDatum(List<IN> info, int loc, List<FeatureFactory<IN>> featureFactories) {
PaddedList<IN> pInfo = new PaddedList<>(info, pad);
Collection<String> features = new ArrayList<>();
for (FeatureFactory<IN> featureFactory : featureFactories) {
List<Clique> cliques = featureFactory.getCliques();
for (Clique c : cliques) {
Collection<String> feats = featureFactory.getCliqueFeatures(pInfo, loc, c);
feats = addOtherClasses(feats, pInfo, loc, c);
features.addAll(feats);
}
}
printFeatures(pInfo.get(loc), features);
CoreLabel c = info.get(loc);
return new BasicDatum<>(features, c.get(CoreAnnotations.AnswerAnnotation.class));
}
Aggregations