00001 /*========================================================================== 00002 * Copyright (c) 2001 Carnegie Mellon University. All Rights Reserved. 00003 * 00004 * Use of the Lemur Toolkit for Language Modeling and Information Retrieval 00005 * is subject to the terms of the software license set forth in the LICENSE 00006 * file included with this software, and also available at 00007 * http://www.lemurproject.org/license.html 00008 * 00009 *========================================================================== 00010 */ 00011 00012 00013 #ifndef _ONESTEPMARKOVCHAIN_HPP 00014 #define _ONESTEPMARKOVCHAIN_HPP 00015 00016 00017 #include "Index.hpp" 00018 #include "WeightedIDSet.hpp" 00019 namespace lemur 00020 { 00021 namespace langmod 00022 { 00023 00025 00029 class OneStepMarkovChain { 00030 public: 00032 OneStepMarkovChain(const lemur::utility::WeightedIDSet &docSet, const lemur::api::Index &homeIndex, double *wdNorm, double stopProbAlpha); 00033 ~OneStepMarkovChain(); 00034 00036 00042 00043 void startFromWordIteration(lemur::api::TERMID_T toWord) const; 00044 bool hasMoreFromWord() const { 00045 while (itPos <= ind.termCountUnique() && fromWordPr[itPos]==0) 00046 itPos++; 00047 return (itPos<= ind.termCountUnique()); 00048 } 00050 void nextFromWordProb(lemur::api::TERMID_T &fromWord, double &prob) const ; 00052 00053 private: 00054 void computeFromWordProb(lemur::api::TERMID_T toWord) const; 00055 const lemur::api::Index &ind; 00056 double alpha; 00057 int *dSet; 00058 double *norm; 00059 mutable double *fromWordPr; 00060 mutable lemur::api::TERMID_T itPos; 00061 mutable lemur::api::TERMID_T curToWord; 00062 }; 00063 } 00064 } 00065 00066 00067 #endif /* _ONESTEPMARKOVCHAIN_HPP */