NGramBuffer API

来源:互联网 发布:局域网视频网站源码 编辑:程序博客网 时间:2024/06/05 07:54
<span style="font-size:24px;">class NGramBuffer实现了一个保护NGrams的缓存。它假定每一个n-gram项的前两个字节是n-gram的id。本类的属性:private final byte[] buffer;ngrams的字节数组,存储ngrams的缓存。private final int numberNGrams;N-Gram的个数即数目。private int position;private final boolean bigEndian;大端字节存储。private final boolean is32bits;缓存是32位还是16位。private final int n;缓存的阶(长度)private boolean used;private int firstNGramEntry;第一个NGram项。本类的构造方法:public NGramBuffer(byte[] buffer, int numberNGrams, boolean bigEndian, boolean is32bits, int n, int firstNGramEntry);给定属性创建对象。本类的方法:public byte[] getBuffer();获得n-grams的字节数组。即buffer属性。public int getFirstNGramEntry();获得第一个Ngram项。即FirstNGramEntry属性.public int getSize();获得的是缓存字节数组的长度,以字节为单位,即buffer的长度。  public int getNumberNGrams();获得在此缓存中ngrams的个数,即数目。即NumberNGrams属性。protected int getPosition();获得buffer的位置position即position属性。protected int getN();获得n属性。protected void setPosition(int position);设置position属性值即缓存位置值。public final int getWordID(int nthFollower);返回第N个跟随者字的id,假定NGram项的id是首前2个字节。输入参数:int nthPosition = nthFollower * (buffer.length / numberNGrams);public final boolean isBigEndian();返回ngrambuffer是否是大端存储。public final boolean is32bits();ngrambuffer是否是32,是为true,false表示是16位的。public final int readBytesAsInt();以整数的形式从buffer字节数组中的字节,读取的字节数为2,或4。返回的是读取到的字节数的字节的整数表示。public boolean getUsed();如果此buffer在最后utterance被使用过则返回为true。public void setUsed(boolean used);设置此buffer在最后utterance中是否被被使用过。被使用过为true。其它为false。public int findProbabilityID(int nthWordID);给定在一个NGram中的给定位置的字的id,来获得NGram的概率id。返回的是给定字的概率id。本方法是通过二分查找实现的。返回的是给定字的ngram概率id。public int getProbabilityID(int nthFollower);返回的是第n个跟随者的ngram概率。输入参数:nthFollower表示哪个跟随者。public NGramProbability findNGram(int nthWordID);查找在一个ngram中的特定位置字的ngram概率。二分查找实现。public int findNGramIndex(int nthWordID) ;查找在一个ngram中的特定位置字的ngram索引。返回的是给定位置字的索引。二分查找实现。public NGramProbability getNGramProbability(int nthFollower);返回的是第n个跟随者的ngram概率即返回的是NGramProbability对象。</span>

0 0
原创粉丝点击