

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object hu.birot.OTKit.dataType.violation.Violation
public abstract class Violation
Realizes a violation instance: the level at which a certain candidate violates a certain constraint (none, once, more times..., and variations of this theme).
This class is abstract. Its most frequently used implementations
are IntegerViolation
(corresponding to the "number of stars"
in a tableau), and FloatViolation
(allowing any real number of
"stars").
In general, a constraint is a function mapping candidates unto violations.
The range of such a function is the set of objects that are constructed using a
particular implementation of the abstract class Violation
.
For instance, most constraints in linguistics map onto the set of nonnegative
integers, for which the class IntegerViolation
can be used (although
the latter also allows negative integers). Yet, the range of constraint HNuc
in the analysis of Imdlawn Tashlhiyt Berber syllabification by Prince and Smolensky
(1993/2002/2004) is a phoneme. What matters is that the range be ordered: two stars
is better than four stars, and [l] is more sonorous than [t].
A number of methods are abstract:
value()
returns the value of the violation: in general,
an Object
.betterEqual(Violation v)
defines the
order relation on the range of the constraint. For integer or real (float) values, this
relation is simply the arithmetic "less than or equal to" relation. In an implementation
of the Berber syllabification, one needs to implement here the sonority scale. In
general, this method allows using ordinal scales as the range of the constraints.difference(Violation v)
defines the difference thisv
on pairs of violation as real numbers (doubles). It is used, for instance, in simulated annealing
and in comparing candidates in Harmonic Grammars. This method allows generalizing these inherently
"floating pointbased" models to constraints with "affinelike" ranges (corresponding to an
"interval scale" in statistics). It is expected that v1.betterEqual(v2)
if and
only if v1.difference(v2) <= 0
; that is informally, v1
is a violation
better than or equivalent to violation v2
, if and only if "v1  v2" <= 0
.equals(Object o)
overrides the general equals
method.
Not necessarily, but usually, violations v1
and v2
are equal for this method
(v1.equals(v2)
), if and only if v1.betterEqual(v2) && v2.betterEqual(v1)
,
that is, if and only if Violation.isEqual(v1, v2) == true
.
clone()
overrides the general clone()
method. For practical
reasons, its implementation is required.
toString()
overrides the general toString()
method. For practical
reasons, its implementation is required.
An important convention is that although the value
method of the class
Constraint returns a Violation
object in general,
nevertheless a specific constraint must always return instances of the same
subclass of Violation (for instance, always IntegerViolation
, or always
FloatViolation
). As explained above, the range of a constraint is the set
defined by a specific implementation of the abstract class Violation
.
Consequently, when implementing the abstract methods betterEqual(Violation v)
and difference(Violation v)
, you can suppose that v
belongs
to the same subclass. In theory, violations assigned by two different constraints are
never compared, and their difference should be never used.
Biro (2006:76) requires that the set of
violations assigned by a constraint to the elements
of a candidate set be a wellordered set (a
totally ordered set in which any subset has a lower
bound contained by that subset). Note that the subclasses IntegerViolation
and FloatViolation
correspond to the set of integer numbers and (vaguely speaking)
real numbers, respectively, which are not wellordered. Yet, constraints usually employ only
a subset of these sets: for instance, the nonnegative integers only.
In Harmonic Grammar, it is usually supposed that the violations must be real numbers. Yet, for comparing two candidates (and hence, to define the best candidate in a wellordered set), it is enough to have violation with an "interval scale". In other words, each constraint C must have an "affinelike" range: the violations need not be real numbers, but the difference of two violations (assigned by the same constraint to any candidate) must be a real number. Namely, the comparison of two candidates depends only on the sign of the weighted sum of these differences.
Here is an example of how to implement this class:
public class BooleanViolation extends Violation {
private boolean b;
public BooleanViolation(boolean v) {
b = v;
}
public Boolean value() {
return b;
}
public BooleanViolation clone() {
return new BooleanViolation(this.b);
}
public boolean betterEqual(Violation v) {
if (!(v instanceof BooleanViolation)) return false;
return this.b  !((Boolean) v.value());
}
public double difference(Violation v) {
boolean b2 = (Boolean) v.value() ;
if (this.b == b2) return 0;
else if (this.b && !b2) return 1; // that is, this.b == true && b2 == false
else return 1; // !this.b && b2; that is, this.b == false && b2 == true
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
else if (o!= null && (o instanceof BooleanViolation) ) {
return ((BooleanViolation) o).b == this.b;
}
else {
return false;
}
}
public String toString() {
return ""+this.b;
}
}
FloatViolation
,
IntegerViolation
,
BooleanViolation
,
Constraint
Field Summary  

protected java.lang.Class<? extends Violation> 
thisclass

Constructor Summary  

Violation()

Method Summary  

abstract boolean 
betterEqual(Violation v)
This method compares the present Violation to Violation v , and returns true if and only if
this violation is better than or equal to v . 
abstract Violation 
clone()
Creates a clone of the Violation: construct a new violation with the same value. 
abstract double 
difference(Violation v)
This method returns the difference of this Violation and of Violation v (in this order: " thisv "). 
boolean 
equals(java.lang.Object o)
This method overrides java.lang.Object.equals. 
int 
hashCode()
A hash code corresponding to the Violation. 
static boolean 
isBetter(Violation v1,
Violation v2)
Returns true if and only if v1 is better than v2. 
static boolean 
isEqual(Violation v1,
Violation v2)
Returns true if and only if v1 is equal to v2. 
static boolean 
notComparable(Violation v1,
Violation v2)
Returns true if and only if v1 and v2 are not comparable. 
abstract java.lang.String 
toString()
Transforms a Violation into a String, overriding the method java.lang.Object.toString. 
abstract java.lang.Object 
value()
Return the value of the violation. 
Methods inherited from class java.lang.Object 

finalize, getClass, notify, notifyAll, wait, wait, wait 
Field Detail 

protected final java.lang.Class<? extends Violation> thisclass
Constructor Detail 

public Violation()
Method Detail 

public abstract java.lang.Object value()
Return the value of the violation. In general, that is an Object
.
For specific subclasses, the return value is usually something more concrete, for instance
Integer
(for the implementation IntegerViolation
) or
Double
(for the implementation FloatViolation
).
IntegerViolation.value()
,
FloatViolation.value()
public abstract boolean betterEqual(Violation v)
This method compares the present Violation to Violation
v
, and returns true
if and only if
this violation is better than or equal to v
.
Value false
must be returned, whenever v
belongs
to a different subclass of Violation
.
In the case of realvalued violations, "better than" means "less than". In the case of nonreal valued violations, "equals to" can be replaced by "equivalent to" (which allows for different but equivalent values).
All the other comparison methods are derived from this method:
isEqual (v1, v2) = v1.betterEqual(v2) && v2.betterEqual(v1)
isBetter (v1, v2) = v1.betterEqual(v2) && !v2.betterEqual(v1)
notComparable (v1, v2) = !( v1.betterEqual(v2)  v2.betterEqual(v1) )
v
 : the second violation.
public static boolean isBetter(Violation v1, Violation v2)
true
if and only if v1 is better than v2.
isBetter (v1, v2) = v1.betterEqual(v2) && !v2.betterEqual(v1)
v1
 First violation to be compared.v2
 Second violation to be compared
v1
is better than v2
, as a function of the
betterEqual(Violation)
method of the two violations.betterEqual(Violation)
public static boolean isEqual(Violation v1, Violation v2)
Returns true
if and only if v1 is equal to v2.
If v1 == v2
, then returns true
, to
speed up the computations. (That is why one is encouraged to use
the static method v(value)
defined in the subclasses of
the Violation
class.)
Otherwise, the implementation of the abstract method
betterEqual(Violation)
is used in the following way:
isEqual (v1, v2) = v1.betterEqual(v2) && v2.betterEqual(v1)
v1
 First violation to be compared.v2
 Second violation to be compared
v1
is equal to v2
, as a function of the
betterEqual(Violation)
method of the two violations. Always
true
if the two parameters refer to the same object.betterEqual(Violation)
public static boolean notComparable(Violation v1, Violation v2)
true
if and only if v1 and v2 are not comparable.
notComparable (v1, v2) = !( v1.betterEqual(v2)  v2.betterEqual(v1) )
v1
 First violation to be compared.v2
 Second violation to be compared
v1
cannot be compared to v2
, as a function of the
betterEqual(Violation)
method of the two violations.betterEqual(Violation)
public abstract double difference(Violation v)
This method returns the difference of this Violation
and of Violation v (in this order: "thisv
").
In the case of IntegerViolations of FloatViolations, the difference is simply
this.value()  v.value()
, on condition that they belong to the
same subclass of Violation
.
Usually, v1.difference(v2) < 0
if and only if
isBetter(v1,v2)
. Similarly, v1.difference(v2) == 0
often means
isEqual(v1,v2)
. For more explanation, see the introduction to the class
Violation
.
The static method difference(v1,v2)
is defined as
v1.difference(v2)
.
v
 The subtrahend violation.
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public abstract Violation clone()
clone
in class java.lang.Object
public abstract java.lang.String toString()
Transforms a Violation into a String, overriding the method java.lang.Object.toString.
toString
in class java.lang.Object
public int hashCode()
A hash code corresponding to the Violation. It is simply the hash code calculated from the output of the toString() method.
If you use this method frequently, you may want to override it. For instance, if the value is always an integer, you may simply return the value.
hashCode
in class java.lang.Object


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 