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

finda_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 _FINDA_CFG
00021 
00022 #define _FINDA_CFG
00023 
00024 #include <string>
00025 
00026 #include "semantic_id.h"
00027 #include "link_map.h"
00028 #include "debug.h"
00029 
00030 
00032 class CAnalogousWeightNode
00033 {
00034         public:
00036                 void SetConcept(CSemanticConcept *a_concept)
00037                 {
00038                         m_concept = a_concept;
00039                 }
00040 
00042                 CSemanticConcept *GetConcept()
00043                 {
00044                         return m_concept;
00045                 }
00046 
00048                 void AddLink(CSemanticLink *a_link)
00049                 {
00050                         m_links.Store(a_link);
00051                 }
00052 
00054                 CSemanticLinkMap_i GetLinkIterator()
00055                 {
00056                         return m_links.GetIterator();
00057                 }
00058 
00060                 CSemanticLink *GetLink(CSemanticLinkMap_i &a_iter)
00061                 {
00062                         return m_links.GetNext(a_iter);
00063                 }
00064 
00066                 u_int GetWeightValue() const
00067                 {
00068                         return m_weight;
00069                 }
00070 
00072                 void AddWeightValue(const u_int a_value)
00073                 {
00074                         m_weight += a_value;
00075                 }
00076 
00078                 CAnalogousWeightNode()
00079                 {
00080                         m_concept = NULL;
00081 
00082                         m_weight = 0;
00083                 }
00084 
00086                 ~CAnalogousWeightNode()
00087                 {
00088                         // NOTE: concept and link list not deallocated because
00089                         // they are deallocated centrally by the main concept
00090                         // and link maps
00091                 }
00092 
00093         private:
00095                 CSemanticConcept *m_concept;
00096 
00098                 CLinkMap          m_links;
00099 
00101                 u_int             m_weight;
00102 };
00103 
00104 
00106 typedef std::map<SemanticID, CAnalogousWeightNode *>
00107                                 CAnalogousWeightNodeMap;
00109 typedef CAnalogousWeightNodeMap::iterator
00110                                 CAnalogousWeightNodeMap_i;
00112 typedef CAnalogousWeightNodeMap::reverse_iterator
00113                                 CAnalogousWeightNodeMap_ri;
00115 typedef CAnalogousWeightNodeMap::const_iterator
00116                                 CAnalogousWeightNodeMap_ci;
00117 
00119 typedef std::pair<CAnalogousWeightNode *, float>
00120                                 CAnalogousWeightPair;
00121 
00123 typedef std::list<CAnalogousWeightPair> CAnalogousWeightNodeList;
00125 typedef CAnalogousWeightNodeList::iterator CAnalogousWeightNodeList_i;
00126 
00127 
00129 class CFindAnalogousConfig
00130 {
00131         public:
00133                 bool AllowVisit()
00134                 {
00135                         if (m_curNodeVisits >= m_maxNodeVisits)
00136                         {
00137                                 return false;
00138                         }
00139 
00140                         return true;
00141                 }
00142 
00144                 void VisitNode()
00145                 {
00146                         m_curNodeVisits++;
00147                 }
00148 
00150                 std::string GetNodeName() const
00151                 {
00152                         return m_nodeName;
00153                 }
00154 
00156                 void SetNodeName(const std::string &a_name)
00157                 {
00158                         m_nodeName = a_name;
00159                 }
00160 
00162                 void StoreWeightedLink(CSemanticLink *a_link)
00163                 {
00164                         CAnalogousWeightNodeMap_i i;
00165 
00166                         i = m_weightedNodeMap.find(a_link->GetSourceID());
00167 
00168                         if (i != m_weightedNodeMap.end())
00169                         {
00170                                 DPRINT("adding link to existing node.\n");
00171 
00172                                 (*i).second->AddLink(a_link);   
00173                         }
00174                         else
00175                         {
00176                                 DPRINT("adding new node.\n");
00177 
00178                                 CAnalogousWeightNode *l_node;
00179 
00180                                 l_node = new CAnalogousWeightNode;
00181 
00182                                 l_node->SetConcept(a_link->GetSource());
00183 
00184                                 l_node->AddLink(a_link);
00185 
00186                                 m_weightedNodeMap[a_link->GetSourceID()] =
00187                                                                         l_node;
00188                         }
00189                 }
00190 
00192                 CAnalogousWeightNodeMap_i GetWeightedIterator()
00193                 {
00194                         DPRINT("get weight iterator size %d\n",
00195                                 m_weightedNodeMap.size());
00196 
00197                         return m_weightedNodeMap.begin();
00198                 }
00199 
00201                 CAnalogousWeightNode *GetWeightedNode(
00202                                             CAnalogousWeightNodeMap_i &a_iter)
00203                 {
00204                         if (m_weightedNodeMap.end() != a_iter)
00205                         {
00206                                 CAnalogousWeightNode *l_node = NULL;
00207 
00208                                 l_node = (*a_iter).second;
00209 
00210                                 ++a_iter;
00211 
00212                                 return l_node;
00213                         }
00214 
00215                         return NULL;
00216                 }
00217 
00219                 bool AddNodeToResults(CAnalogousWeightNode *a_node,
00220                                       const float           a_score)
00221                 {
00222                         CAnalogousWeightPair l_pair;
00223 
00224                         if (m_resultsList.size() >= m_maxNodeResults)
00225                         {
00226                                 return false;
00227                         }
00228 
00229                         l_pair.first  = a_node;
00230                         l_pair.second = a_score;
00231 
00232                         m_resultsList.push_back(l_pair);
00233 
00234                         return true;
00235                 }
00236 
00238                 u_int GetNumResults() const
00239                 {
00240                         return m_resultsList.size();
00241                 }
00242 
00244                 CAnalogousWeightNode *GetResult(const u_int  a_index,
00245                                                   float *a_score)
00246                 {
00247                         u_int l_count = 0;
00248 
00249                         CAnalogousWeightNodeList_i i;
00250 
00251                         for (i = m_resultsList.begin();i != m_resultsList.end();
00252                              ++i)
00253                         {
00254                                 if (a_index == l_count)
00255                                 {
00256                                         if (a_score)
00257                                         {
00258                                                 *a_score = (*i).second;
00259                                         }
00260 
00261                                         return (*i).first;
00262                                 }
00263 
00264                                 l_count++;
00265                         }
00266 
00267                         return NULL;
00268                 }
00269 
00271                 u_int GetNumNodeVisits() const
00272                 {
00273                         return m_curNodeVisits;
00274                 }
00275 
00277                 CFindAnalogousConfig()
00278                 {
00279                         m_maxNodeVisits  = 1000000;
00280                         m_maxNodeResults = 200;
00281 
00282                         m_curNodeVisits = 0;
00283                 }
00284 
00286                 virtual ~CFindAnalogousConfig() {}
00287 
00288         private:
00290                 std::string m_nodeName;
00291 
00293                 CAnalogousWeightNodeMap m_weightedNodeMap;
00294 
00296                 u_int m_maxNodeVisits;
00297 
00299                 u_int m_maxNodeResults;
00300 
00302                 u_int m_curNodeVisits;
00303 
00305                 CAnalogousWeightNodeList m_resultsList;
00306 };
00307 
00308 
00309 #endif
00310 

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