hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SnowballPlugin.cpp
Go to the documentation of this file.
1 
4 #include <iostream>
5 #include <Poco/UTF8String.h>
6 
7 #include "SnowballPlugin.hpp"
8 
9 namespace HCE
10 {
11 
12 namespace component
13 {
14 
15 
17 {
21  ProcessInfo processInfo;
23  _exported.push_back( processInfo );
24 }
25 
26 
28 {
29  for ( _it=_mapStemmer.begin(); _it!=_mapStemmer.end(); ++_it )
30  sb_stemmer_delete(_it->second);
31 }
32 
33 
35 {
36  std::map<WORD_CONTENT_OFFSET, SSTRING>::const_iterator it;
37  std::string stemmerString;
38  SSTRING iso639_1;
39  sb_stemmer* stemmer = NULL;
40  for ( it=lCData._mapTokens.begin(); it!=lCData._mapTokens.end(); ++it )
41  {
42  iso639_1 = lCData._mapLanguages[ it->first ];
43  stemmer = getStemmer( iso639_1 );
44  if(lCData._normalizationId == DEFAULT_NORMALIZATION_WITH && stemmer)
45  {
46  stemmerString = Poco::UTF8::toLower(it->second);
47  const sb_symbol * stemmed = sb_stemmer_stem( stemmer, (const sb_symbol*)stemmerString.c_str(), stemmerString.size() );
48  lCData._mapNormalizedForms[ it->first ] = SSTRING( (const char*)stemmed );
49  }
50  else
51  {
52  lCData._mapNormalizedForms[ it->first ] = SSTRING( it->second );
53  }
54  }
55 #ifdef _DEBUG_
56  std::cout << std::endl << "SnowballPlugin normalize" << std::endl << std::endl;
60  std::map<WORD_CONTENT_OFFSET, WORD_LENGTH>::const_iterator it1;
61  std::cout << "token \t norm" << std::endl;
62  std::cout << "----- \t ----" << std::endl;
63  for( it1=lCData._mapOffsets.begin(); it1!=lCData._mapOffsets.end(); ++it1)
64  {
65  std::cout << lCData._mapTokens[it1->first] << '\t'
66  << lCData._mapNormalizedForms[it1->first] << std::endl;
67  }
68  std::cout << "Tokens count " << lCData._mapOffsets.size() << std::endl << std::endl;
69 #endif
70 }
71 
72 
73 sb_stemmer* SnowballPlugin::getStemmer( const SSTRING& iso639_1 )
74 {
75  _it=_mapStemmer.find( iso639_1 );
76  if ( _it==_mapStemmer.end() )
77  {
78  _stemmer = sb_stemmer_new((char*)iso639_1.c_str(), NULL);
79  _mapStemmer[ iso639_1 ] = _stemmer;
80  }
81  else
82  {
83  _stemmer = _it->second;
84  }
85  return _stemmer;
86 }
87 
88 
89 } /* namespace component */
90 
91 } /* namespace HCE */