## org.apache.mahout.vectorizer.collocations.llr
Class Gram

    java.lang.Object
      org.apache.hadoop.io.BinaryComparable
          org.apache.mahout.vectorizer.collocations.llr.Gram

All Implemented Interfaces:
  Comparable<org.apache.hadoop.io.BinaryComparable>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<org.apache.hadoop.io.BinaryComparable>

    public class Gram

extends org.apache.hadoop.io.BinaryComparable
implements org.apache.hadoop.io.WritableComparable<org.apache.hadoop.io.BinaryComparable>

Writable for holding data generated from the collocation discovery jobs. Depending on the job configuration gram may be one or more words. In some contexts this is used to hold a complete ngram, while in others it holds a part of an existing ngram (subgram). Tracks the frequency of the gram and its position in the ngram in which is was found.

Nested Class Summary
`static class` `Gram.Type`

Constructor Summary
`Gram()`
`Gram(Gram other)` Copy constructor
`Gram(String ngram, Gram.Type type)` Create an gram with a frequency of 1
`Gram(String ngram, int frequency, Gram.Type type)` Create a gram with the specified frequency.

Method Summary
`static Gram.Type` `decodeType(byte[] buf, int offset)`
`static void` `encodeType(Gram.Type type, byte[] buf, int offset)`
`byte[]` `getBytes()`
`int` `getFrequency()`
`int` `getLength()`
`String` `getString()`
`Gram.Type` `getType()`
`void` `incrementFrequency(int i)`
`void` `readFields(DataInput in)`
`void` `setFrequency(int frequency)`
`String` `toString()`
`void` `write(DataOutput out)`

Methods inherited from class org.apache.hadoop.io.BinaryComparable
`compareTo, compareTo, equals, hashCode`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.lang.Comparable
`compareTo`

Constructor Detail

### Gram

    public Gram()

### Gram

    public Gram(Gram other)

  Copy constructor

### Gram

    public Gram(String ngram,
                Gram.Type type)

  Create an gram with a frequency of 1

  Parameters:
    `ngram` - the gram string
    `type` - whether the gram is at the head or tail of its text unit or it is a unigram

### Gram

    public Gram(String ngram,
                int frequency,
                Gram.Type type)

  Create a gram with the specified frequency.

  Parameters:
    `ngram` - the gram string
    `frequency` - the gram frequency
    `type` - whether the gram is at the head of its text unit or tail or unigram

Method Detail

### getBytes

    public byte[] getBytes()

  Specified by:
    `getBytes` in class `org.apache.hadoop.io.BinaryComparable`

### getLength

    public int getLength()

  Specified by:
    `getLength` in class `org.apache.hadoop.io.BinaryComparable`

### getType

    public Gram.Type getType()

  Returns:
    the gram is at the head of its text unit or tail or unigram.

### getString

    public String getString()

  Returns:
    gram term string

### getFrequency

    public int getFrequency()

  Returns:
    gram frequency

### setFrequency

    public void setFrequency(int frequency)

  Parameters:
    `frequency` - gram's frequency

### incrementFrequency

    public void incrementFrequency(int i)

### readFields

    public void readFields(DataInput in)
                    throws IOException

  Specified by:
    `readFields` in interface `org.apache.hadoop.io.Writable`
  Throws:
    `IOException`

### write

    public void write(DataOutput out)
               throws IOException

  Specified by:
    `write` in interface `org.apache.hadoop.io.Writable`
  Throws:
    `IOException`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### encodeType

    public static void encodeType(Gram.Type type,
                                  byte[] buf,
                                  int offset)

### decodeType

    public static Gram.Type decodeType(byte[] buf,
                                       int offset)

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.