edu.vt.marian.common
Class Weight

java.lang.Object
  |
  +--edu.vt.marian.common.Weight

public class Weight
extends java.lang.Object

The weight of an object in some approximate context (e.g., match to a query).

designer(s): Jianxin Zhao (jxzhao@csgrad.cs.vt.edu)
implementator(s): Jianxin Zhao, Robert France
JDK version: 1.1.5


Field Summary
static Weight bottomWt
           
static int EQUAL
          the methods' return values.
static int HIGHER
           
static int LOWER
           
static int NOT_APPLY
           
static int NULL_STREAM
           
static Weight topWt
          Public versions of the bounds for reasonable values.
 
Constructor Summary
Weight(java.io.BufferedReader br, Debug debug)
          Create a Weight object from an input stream.
Weight(Debug debug)
          Create an invalid Weight object.
Weight(double f, Debug debug)
          Create a Weight object based on a specified value.
Weight(int i, Debug debug)
          Create a Weight object based on a specified value.
Weight(Weight w)
          Create a Weight object based on another Weight object.
 
Method Summary
 void accum(double f)
          "Add" a float between 0..1 to this object.
 void accum(Weight w)
          "Add" one Weight to another.
 int compare(Weight w)
          Return the result of the comparision between this Weight object and the parameter Weight object.
 int getUnderlyingValue()
           
 double getValue()
          Return the value of this Weight object.
 boolean isValid()
          Tell whether or not this Weight object is valid.
 int readPacked(java.io.ByteArrayInputStream bis)
          Read this out of compact storage in a byte array.
 void scale(double f)
          method description: Scale one Weight by a real constant.
 void scale(Weight w)
          Scale one Weight by another.
 void set(Weight w)
           
 int toStream(java.io.PrintWriter pw)
          Print the content of this object to a specified stream.
 int writePacked(java.io.ByteArrayOutputStream bos)
          Pack this into a byte array for compact storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

topWt

public static final Weight topWt
Public versions of the bounds for reasonable values.

bottomWt

public static final Weight bottomWt

EQUAL

public static final int EQUAL
the methods' return values.

HIGHER

public static final int HIGHER

LOWER

public static final int LOWER

NOT_APPLY

public static final int NOT_APPLY

NULL_STREAM

public static final int NULL_STREAM
Constructor Detail

Weight

public Weight(Debug debug)
Create an invalid Weight object.
Parameters:
debug - used for debugging

Weight

public Weight(int i,
              Debug debug)
Create a Weight object based on a specified value.
Parameters:
i - the underlying value for this Weight object
debug - used for debugging

Weight

public Weight(double f,
              Debug debug)
Create a Weight object based on a specified value.
Parameters:
f - the value of this Weight object;
debug - used for debugging

Weight

public Weight(Weight w)
Create a Weight object based on another Weight object.
Parameters:
w - the Weight object to copy.

Weight

public Weight(java.io.BufferedReader br,
              Debug debug)
Create a Weight object from an input stream.
Parameters:
br - the stream to read out this object
debug - used for debugging
Method Detail

isValid

public boolean isValid()
Tell whether or not this Weight object is valid.
Returns:
true / false

compare

public int compare(Weight w)
Return the result of the comparision between this Weight object and the parameter Weight object.
Parameters:
w - the Weight object used to compared with this object
Returns:
EQUAL -- their values are equal
HIGHER -- the value of this object is higher than the parameter object
LOWER -- the value of this object is lower than the parameter object

scale

public void scale(Weight w)
Scale one Weight by another.
Parameters:
w - the Weight object used to scale this object.

NOTE: We are using the integer values lower_limit..upper_limit to mimic the real number interval 0..1. As long as lower_limit == 0) we need only adjust to keep values proportionally under upper_limit, which we treat both as the top value and as multiplicative identity. We achieve this by multiplying the two "value" fields, then shifting the result right by 15 bits (effectively dividing by 2**15).


scale

public void scale(double f)
method description: Scale one Weight by a real constant.
Parameters:
f - the double precision value used to scale this object.

accum

public void accum(Weight w)
"Add" one Weight to another.
Parameters:
w - the Weight object to be accumulated into this object.

accum

public void accum(double f)
"Add" a float between 0..1 to this object.
Parameters:
f - -- the double precision value to be accumulated into this object.

getValue

public double getValue()
Return the value of this Weight object.

getUnderlyingValue

public int getUnderlyingValue()

set

public void set(Weight w)

writePacked

public int writePacked(java.io.ByteArrayOutputStream bos)
Pack this into a byte array for compact storage.
Parameters:
bos - a ByteArrayOutputStream into which to pack this.
Returns:
OK -- all jake.
NULL_STREAM -- could not write.

readPacked

public int readPacked(java.io.ByteArrayInputStream bis)
Read this out of compact storage in a byte array.
Parameters:
bis - a ByteArrayInputStream from which to unpack this.
Returns:
OK -- all jake.
NULL_STREAM -- could not read.

toStream

public int toStream(java.io.PrintWriter pw)
Print the content of this object to a specified stream.
Parameters:
pw - -- the stream to write this object
Returns:
OK -- the object has been written to the stream correctly
NULL_STREAM -- the parameter stream is null