FirteX-高性能全文索引和检索平台

API Documentation


首页 | 名字空间列表 | 类继承关系 | 组合类型列表 | $(BL\录(B | 文件列表 | 名字空间成员 | 组合类型成员 | 文件成员

Similarity.h

浏览该文件的文档。
00001 //
00002 // Copyright(C) 2005--2006 Institute of Computing Tech, Chinese Academy of Sciences. 
00003 // All rights reserved.
00004 // This file is part of FirteX (www.firtex.org)
00005 //
00006 // Use of the FirteX is subject to the terms of the software license set forth in 
00007 // the LICENSE file included with this software, and also available at
00008 // http://www.firtex.org/license.html
00009 //
00010 // Author       : 郭瑞杰(GuoRuijie)
00011 // Email        : ruijieguo@software.ict.ac.cn,ruijieguo@gmail.com
00012 // Created      : 2006/3/9
00013 //
00014 #ifndef _SIMILARITY_H
00015 #define _SIMILARITY_H
00016 
00017 #include "../utility/StdHeader.h"
00018 #include "../index/Term.h"
00019 #include "../utility/SmallFloat.h"
00020 
00021 using namespace firtex::index;
00022 
00023 namespace firtex
00024 {
00025         namespace search
00026         {
00027                 class CSearcher;
00028                 class CSimilarity
00029                 {
00030                 public:
00031 
00032                         CSimilarity(void);                      
00033                         virtual ~CSimilarity(void);
00034                 public:
00040                         virtual float tf(int freq)
00041                         {
00042                                 return tf((float)freq);
00043                         }
00044 
00050                         virtual float tf(float freq) = 0;
00051 
00052 
00059                         virtual float idf(CTerm* term,CSearcher* searcher);
00060 
00067                         virtual float idf(freq_t docFreq, count_t numDocs) = 0;
00068 
00082                         virtual float sloppyFreq(int distance) = 0;
00083                         
00084                         virtual float lengthNorm(count_t numTerms) = 0;
00085                         virtual float queryNorm(float sumOfSquaredWeights) = 0;
00086 
00099                         virtual float coord(int overlap, int maxOverlap) = 0;
00100 
00101                         static CSimilarity* getDefault();
00102                         static void                     setDefault(CSimilarity* pDefault);
00103 
00108                         static float decodeNorm(byte b) 
00109                         {
00110                                 if(m_bNormTableInited == false)
00111                                 {
00112                                         initNormTable();
00113                                         m_bNormTableInited = true;
00114                                 }
00115                                 return NORM_TABLE[b & 0xFF];  // & 0xFF maps negative bytes to positive above 127
00116                         }
00117                         
00118                         static byte encodeNorm(float f) 
00119                         {
00120                                 return CSmallFloat::floatToByte315(f);
00121                         };                                      
00122                 protected:
00123                         static void     initNormTable();
00124                 protected:
00126                         static float NORM_TABLE[256];
00127                         static bool m_bNormTableInited;
00128                 private:
00129                         static CSimilarity*     m_pDefaultSimilarity;
00130                 };
00131         }
00132 }
00133 
00134 #endif

http://www.firtex.org http://www.sourceforge.net/projects/firtex