edu.northwestern.at.morphadorner.corpuslinguistics.textsegmenter.struct

## Class ContextVector

- java.lang.Object
- - edu.northwestern.at.morphadorner.corpuslinguistics.textsegmenter.struct.ContextVector

- All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable

      public class ContextVector
      extends java.lang.Object
      implements java.io.Externalizable

  Context vector. Maps string to frequency count.
  Author:
    Freddy Choi, Philip R. Burns. Modified for integration in MorphAdorner.

    Use of this code is free for academic, education, research and other non-profit making uses only.

  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `ContextVector.Frequency` Holds an externalizable frequency (count).

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `sum`
    `protected java.util.Map<java.lang.String,ContextVector.Frequency>` | `table` Labeled frquencies.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ContextVector()` Create ContextVector.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static double` | `cos(ContextVector a, ContextVector b)` Compute the cosine of vector a and b
    `static double` | `cos(ContextVector a, ContextVector b, EntropyVector tf)` Compute the cosine of vector a and b, accounting for term frequency.
    `static int` | `dot(ContextVector a, ContextVector b)` Compute the dot product of vector a and b.
    `static int` | `freq(java.lang.String key, ContextVector vector)` Get the frequency count of key in context vector
    `static int` | `inc(java.lang.String key, int increment, ContextVector vector)` Increment frequency count of key.
    `static java.lang.String[]` | `keys(ContextVector v)` Get the list of context vector keys.
    `void` | `readExternal(java.io.ObjectInput in)` Read ContextVector from object file.
    `static int` | `sum(ContextVector vector)` Get the sum of frequencies
    `void` | `writeExternal(java.io.ObjectOutput out)` Save ContextVector to file as object.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### table

          protected java.util.Map<java.lang.String,ContextVector.Frequency> table

      Labeled frquencies.

    - #### sum

          protected int sum

  - ### Constructor Detail

    - #### ContextVector

          public ContextVector()

      Create ContextVector.

  - ### Method Detail

    - #### cos

          public static double cos(ContextVector a,
                   ContextVector b)

      Compute the cosine of vector a and b
      Parameters:
        `a` - First context vector.
        `b` - Second context vector.
      Returns:
        Cosine of angle between vectors a and b.

    - #### cos

          public static double cos(ContextVector a,
                   ContextVector b,
                   EntropyVector tf)

      Compute the cosine of vector a and b, accounting for term frequency.
      Parameters:
        `a` - First vector.
        `b` - Second vector.
        `tf` - Term frequency vector.
      Returns:
        cosine value.

    - #### dot

          public static int dot(ContextVector a,
                ContextVector b)

      Compute the dot product of vector a and b.
      Parameters:
        `a` - first vector.
        `b` - second vector.
      Returns:
        dot product.

    - #### freq

          public static int freq(java.lang.String key,
                 ContextVector vector)

      Get the frequency count of key in context vector
      Parameters:
        `key` - The key.
        `vector` - The context vector.
      Returns:
        The frequency count.

    - #### inc

          public static int inc(java.lang.String key,
                int increment,
                ContextVector vector)

      Increment frequency count of key.
      Parameters:
        `key` - The key.
        `increment` - The increment value.
        `vector` - The context vector.
      Returns:
        Updated frequency.

    - #### keys

          public static java.lang.String[] keys(ContextVector v)

      Get the list of context vector keys.
      Parameters:
        `v` - The context vector.
      Returns:
        Keys as a string array.

    - #### readExternal

          public final void readExternal(java.io.ObjectInput in)
                                  throws java.io.IOException,
                                         java.lang.ClassNotFoundException

      Read ContextVector from object file.
      Specified by:
        `readExternal` in interface `java.io.Externalizable`
      Parameters:
        `in` - The object input file.
      Throws:
        `java.io.IOException`
        `java.lang.ClassNotFoundException`

    - #### sum

          public static int sum(ContextVector vector)

      Get the sum of frequencies
      Parameters:
        `vector` - The context vector.
      Returns:
        Sum of frequencies in vector.

    - #### writeExternal

          public final void writeExternal(java.io.ObjectOutput out)
                                   throws java.io.IOException

      Save ContextVector to file as object.
      Specified by:
        `writeExternal` in interface `java.io.Externalizable`
      Parameters:
        `out` - The object output file.
      Throws:
        `java.io.IOException`