Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

findc_cfg.h

Go to the documentation of this file.
00001 /*  This file is part of OMCSNetCPP
00002 
00003     OMCSNetCPP is free software; you can redistribute it and/or modify
00004     it under the terms of the GNU Lesser General Public License as published by
00005     the Free Software Foundation; either version 2.1 of the License, or
00006     (at your option) any later version.
00007 
00008     OMCSNetCPP is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011     GNU Lesser General Public License for more details.
00012 
00013     You should have received a copy of the GNU Lesser General Public License
00014     along with OMCSNetCPP; if not, write to the Free Software
00015     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016  */
00017 
00020 #ifndef _FINDC_CFG
00021 
00022 #define _FINDC_CFG
00023 
00024 #include "concept_map.h"
00025 #include "link_list.h"
00026 #include "debug.h"
00027 
00028 class CSemanticConcept;
00029 
00031 typedef std::pair<CSemanticConcept *, float>
00032                                 CSemanticConceptPair;
00033 
00035 typedef std::list<CSemanticConceptPair>      CResultsList;
00037 typedef CResultsList::iterator               CResultsList_i;
00039 typedef CResultsList::const_iterator         CResultsList_ci;
00040 
00042 class CFindContextConfig
00043 {
00044         public:
00046                 bool AllowVisit()
00047                 {
00048                         if (m_curNodeVisits >= m_maxNodeVisits)
00049                         {
00050                                 return false;
00051                         }
00052 
00053                         return true;
00054                 }
00055 
00057                 void VisitNode()
00058                 {
00059                         m_curNodeVisits++;
00060                 }
00061 
00063                 float GetDiscountFactor() const
00064                 {
00065                         return 0.5;
00066                 }
00067 
00069                 bool AddNodeToResults(CSemanticConcept *a_concept,
00070                                       const float       a_score)
00071                 {
00072                         CSemanticConceptPair l_pair;
00073 
00074                         if (m_resultsList.size() >= m_maxNodeResults)
00075                         {
00076                                 return false;
00077                         }
00078 
00079                         l_pair.first  = a_concept;
00080                         l_pair.second = a_score;
00081 
00082                         m_resultsList.push_back(l_pair);
00083 
00084                         return true;
00085                 }
00086 
00088                 u_int GetNumResults() const
00089                 {
00090                         return m_resultsList.size();
00091                 }
00092 
00094                 CSemanticConcept *GetResult(const u_int  a_index,
00095                                                   float *a_score)
00096                 {
00097                         u_int l_count = 0;
00098 
00099                         CResultsList_ci i;
00100 
00101                         for (i = m_resultsList.begin();i != m_resultsList.end();
00102                              ++i)
00103                         {
00104                                 if (a_index == l_count)
00105                                 {
00106                                         if (a_score)
00107                                         {
00108                                                 *a_score = (*i).second;
00109                                         }
00110 
00111                                         return (*i).first;
00112                                 }
00113 
00114                                 l_count++;
00115                         }
00116 
00117                         return NULL;
00118                 }
00119 
00121                 u_int GetNumNodeVisits() const
00122                 {
00123                         return m_curNodeVisits;
00124                 }
00125 
00127                 CResultsList_i GetScoreIterator()
00128                 {
00129                         DPRINT("get score iterator size %d\n",
00130                                 m_scoreQueue.size());
00131 
00132                         return m_scoreQueue.begin();
00133                 }
00134 
00136                 CSemanticConcept *GetScoreQueue(CResultsList_i &a_iter,
00137                                                 float          *a_score)
00138                 {
00139                         if (m_scoreQueue.end() != a_iter)
00140                         {
00141                                 CSemanticConcept *l_concept;
00142 
00143                                 l_concept = (*a_iter).first;
00144 
00145                                 if (a_score)
00146                                 {
00147                                         *a_score = (*a_iter).second;
00148                                 }
00149 
00150                                 a_iter++;
00151 
00152                                 return l_concept;
00153                         }
00154 
00155                         return NULL;
00156                 }
00157 
00159                 CSemanticConcept *GetScoreQueue(float *a_score)
00160                 {
00161                         CResultsList_i i;
00162 
00163                         i = m_scoreQueue.begin();
00164 
00165                         if (m_scoreQueue.end() != i)
00166                         {
00167                                 CSemanticConcept *l_concept;
00168 
00169                                 l_concept = (*i).first;
00170 
00171                                 if (a_score)
00172                                 {
00173                                         *a_score = (*i).second;
00174                                 }
00175 
00176                                 m_scoreQueue.pop_front();
00177 
00178                                 return l_concept;
00179                         }
00180 
00181                         return NULL;
00182                 }
00183 
00185                 void QueueScore(      CSemanticConcept *a_concept,
00186                                 const float             a_score)
00187                 {
00188                         CSemanticConceptPair l_pair;
00189 
00190                         l_pair.first  = a_concept;
00191                         l_pair.second = a_score;
00192 
00193                         m_scoreQueue.push_back(l_pair);
00194                 }
00195 
00197                 CFindContextConfig()
00198                 {
00199                         m_maxNodeVisits  = 1000;
00200                         m_maxNodeResults = 200;
00201 
00202                         m_curNodeVisits = 0;
00203                 }
00204 
00206                 virtual ~CFindContextConfig() {}
00207 
00208         private:
00210                 u_int m_maxNodeVisits;
00212                 u_int m_maxNodeResults;
00213 
00215                 u_int m_curNodeVisits;
00216 
00218                 CResultsList m_resultsList;
00219 
00221                 CResultsList m_scoreQueue;
00222 };
00223 
00224 #endif
00225 

Generated on Tue Sep 16 09:43:50 2003 for OMCSNetCPP by doxygen 1.3.3