package OT; import java.util.*; /** * Constraint penalizing floating features. * @version 1999-03-31 * @author Andrea Heiberg, University of Arizona */ public class NoFloat extends Constraint { public NoFloat(FeatureType featureType1) { super(featureType1, null, null, false); } //end constructor /** Returns the number of times that candidate violates this constraint. For each floating feature of featureType1, increment the violation count. **/ public Integer evaluate(Representation rep, Representation nullRep) { int violations = 0; for (Enumeration e = rep.floatingFeatures.elements(); e.hasMoreElements();) { Feature f = (Feature)e.nextElement(); if (featureType1.equals(f.featureType)) { violations++; } //end if } //end for return new Integer(violations); } //end evaluate /** Removes all InsertFeature operations on featureType1 from gen. **/ public Gen cullGen(Gen gen) { Gen newGen = new Gen(gen.input, gen.languageFeatureTypeSet, gen.debug); StringBuffer sb = new StringBuffer(); for (Enumeration e = gen.elements(); e.hasMoreElements();) { boolean match = false; Operation op = (Operation)e.nextElement(); if (op instanceof InsertFeature) { if (op.featureType.toString().equals(featureType1.toString())) { match = true; sb.append(this.toString() + ": culled " + op + "\n"); } //end if } //end if if (!match) { newGen.addElement(op); } //end if } //end for gen.debug.write(sb.toString()); sb = null; newGen.trimToSize(); return newGen; } //end cullGen public String toString() { return ("*Float(" + featureType1 + ")"); } //end toString }