NGramBuffer API

<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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值