OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WordHolder.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // C
5 #include <cassert>
6 // Boost
7 #include <boost/tokenizer.hpp>
8 // OpenTREP
10 
11 namespace OPENTREP {
12 
13  // Define the separators
14  static const boost::char_separator<char> AllSepatorList (" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\"");
15  static const boost::char_separator<char> DocSepatorList (" ,-%");
16 
17  // //////////////////////////////////////////////////////////////////////
18  void baseTokeniseStringIntoWordList (const std::string& iPhrase,
19  WordList_T& ioWordList,
20  const boost::char_separator<char>& iSepatorList) {
21  // Empty the word list
22  ioWordList.clear();
23 
24  // Boost Tokeniser
25  typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
26 
27  // Initialise the phrase to be tokenised
28  Tokeniser_T lTokens (iPhrase, iSepatorList);
29  for (Tokeniser_T::const_iterator tok_iter = lTokens.begin();
30  tok_iter != lTokens.end(); ++tok_iter) {
31  const std::string& lTerm = *tok_iter;
32  ioWordList.push_back (lTerm);
33  }
34  }
35 
36  // //////////////////////////////////////////////////////////////////////
37  void WordHolder::tokeniseStringIntoWordList (const std::string& iPhrase,
38  WordList_T& ioWordList) {
39  OPENTREP::baseTokeniseStringIntoWordList (iPhrase, ioWordList,
41  }
42 
43  // //////////////////////////////////////////////////////////////////////
44  void WordHolder::tokeniseDocIntoWordList (const std::string& iPhrase,
45  WordList_T& ioWordList) {
46  OPENTREP::baseTokeniseStringIntoWordList (iPhrase, ioWordList,
48  }
49 
50  // //////////////////////////////////////////////////////////////////////
51  std::string WordHolder::
53  std::ostringstream oStr;
54 
55  unsigned short idx = iWordList.size();
56  for (WordList_T::const_iterator itWord = iWordList.begin();
57  itWord != iWordList.end(); ++itWord, --idx) {
58  const std::string& lWord = *itWord;
59  oStr << lWord;
60  if (idx > 1) {
61  oStr << " ";
62  }
63  }
64 
65  return oStr.str();
66  }
67 
68 }
void baseTokeniseStringIntoWordList(const std::string &iPhrase, WordList_T &ioWordList, const boost::char_separator< char > &iSepatorList)
Definition: WordHolder.cpp:18
static std::string createStringFromWordList(const WordList_T &iWordList)
Definition: WordHolder.cpp:52
std::list< Word_T > WordList_T
static void tokeniseStringIntoWordList(const TravelQuery_T &, WordList_T &)
Definition: WordHolder.cpp:37
static void tokeniseDocIntoWordList(const TravelQuery_T &, WordList_T &)
Definition: WordHolder.cpp:44
static const boost::char_separator< char > AllSepatorList(" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\"")
static const boost::char_separator< char > DocSepatorList(" ,-%")