OpenTREP Logo  0.07.4
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pyopentrep.cpp
Go to the documentation of this file.
1 // Python
2 #include <boost/python.hpp>
3 // STL
4 #include <cassert>
5 #include <stdexcept>
6 #include <fstream>
7 #include <sstream>
8 #include <string>
9 #include <list>
10 #include <vector>
11 // Boost Python
12 #include <boost/filesystem.hpp>
13 // OpenTREP
16 #include <opentrep/Location.hpp>
17 #include <opentrep/CityDetails.hpp>
20 
21 namespace OPENTREP {
22 
28  public:
29 
37  std::string getPaths() {
38  return getPathsImpl();
39  }
40 
44  std::string index() {
45  return indexImpl();
46  }
47 
51  std::string generate (const std::string& iOutputFormatString,
52  const NbOfMatches_T& iNbOfDraws) {
53  const OutputFormat lOutputFormat (iOutputFormatString);
54  const OutputFormat::EN_OutputFormat& lOutputFormatEnum =
55  lOutputFormat.getFormat();
56  return generateImpl (iNbOfDraws, lOutputFormatEnum);
57  }
58 
62  std::string search (const std::string& iOutputFormatString,
63  const std::string& iTravelQuery) {
64  const OutputFormat lOutputFormat (iOutputFormatString);
65  const OutputFormat::EN_OutputFormat& lOutputFormatEnum =
66  lOutputFormat.getFormat();
67  return searchImpl (iTravelQuery, lOutputFormatEnum);
68  }
69 
70  private:
74  std::string getPathsImpl() {
75  std::ostringstream oPythonLogStr;
76 
77  // Sanity check
78  if (_logOutputStream == NULL) {
79  oPythonLogStr << "The log filepath is not valid." << std::endl;
80  return oPythonLogStr.str();
81  }
82  assert (_logOutputStream != NULL);
83 
84  try {
85 
86  // DEBUG
87  *_logOutputStream << "Get the file-path details" << std::endl;
88 
89  if (_opentrepService == NULL) {
90  oPythonLogStr << "The OpenTREP service has not been initialised, "
91  << "i.e., the init() method has not been called "
92  << "correctly on the OpenTrepSearcher object. Please "
93  << "check that all the parameters are not empty and "
94  << "point to actual files.";
95  *_logOutputStream << oPythonLogStr.str();
96  return oPythonLogStr.str();
97  }
98  assert (_opentrepService != NULL);
99 
100  // Retrieve the underlying file-path details
101  const OPENTREP_Service::FilePathSet_T& lFilePathSet =
102  _opentrepService->getFilePaths();
103  const PORFilePath_T& lPORFilePath = lFilePathSet.first;
104  const OPENTREP_Service::DBFilePathPair_T& lDBFilePathPair =
105  lFilePathSet.second;
106  const TravelDBFilePath_T& lTravelDBFilePath = lDBFilePathPair.first;
107  const SQLDBConnectionString_T& lSQLDBConnStr = lDBFilePathPair.second;
108 
109  // Dump the results into the output string
110  oPythonLogStr << lPORFilePath << ";" << lTravelDBFilePath
111  << ";" << lSQLDBConnStr;
112 
113  // DEBUG
114  *_logOutputStream << "OPTD-maintained list of POR: '" << lPORFilePath
115  << "'" << std::endl;
116  *_logOutputStream << "Xapian travel database/index: '"
117  << lTravelDBFilePath << "'" << std::endl;
118  *_logOutputStream << "SQL database connection string: '"
119  << lSQLDBConnStr << "'" << std::endl;
120 
121  } catch (const RootException& eOpenTrepError) {
122  *_logOutputStream << "OpenTrep error: " << eOpenTrepError.what()
123  << std::endl;
124 
125  } catch (const std::exception& eStdError) {
126  *_logOutputStream << "Error: " << eStdError.what() << std::endl;
127 
128  } catch (...) {
129  *_logOutputStream << "Unknown error" << std::endl;
130  }
131 
132  //
133  return oPythonLogStr.str();
134  }
135 
139  std::string indexImpl() {
140  std::ostringstream oPythonLogStr;
141 
142  // Sanity check
143  if (_logOutputStream == NULL) {
144  oPythonLogStr << "The log filepath is not valid." << std::endl;
145  return oPythonLogStr.str();
146  }
147  assert (_logOutputStream != NULL);
148 
149  try {
150 
151  // DEBUG
152  *_logOutputStream << "Indexation by Xapian" << std::endl;
153 
154  if (_opentrepService == NULL) {
155  oPythonLogStr << "The OpenTREP service has not been initialised, "
156  << "i.e., the init() method has not been called "
157  << "correctly on the OpenTrepSearcher object. Please "
158  << "check that all the parameters are not empty and "
159  << "point to actual files.";
160  *_logOutputStream << oPythonLogStr.str();
161  return oPythonLogStr.str();
162  }
163  assert (_opentrepService != NULL);
164 
165  // Retrieve the underlying file-path details
166  const OPENTREP_Service::FilePathSet_T& lFilePathSet =
167  _opentrepService->getFilePaths();
168  const PORFilePath_T& lPORFilePath = lFilePathSet.first;
169  const OPENTREP_Service::DBFilePathPair_T& lDBFilePathPair =
170  lFilePathSet.second;
171  const TravelDBFilePath_T& lTravelDBFilePath = lDBFilePathPair.first;
172  const SQLDBConnectionString_T& lSQLDBConnStr = lDBFilePathPair.second;
173 
174  // DEBUG
175  *_logOutputStream << "OPTD-maintained list of POR: '" << lPORFilePath
176  << "'" << std::endl;
177  *_logOutputStream << "Xapian travel database/index: '"
178  << lTravelDBFilePath << "'" << std::endl;
179  *_logOutputStream << "SQL database connection string: '"
180  << lSQLDBConnStr << "'" << std::endl;
181 
182  // Launch the indexation by Xapian of the OPTD-maintained list of POR
183  const NbOfDBEntries_T lNbOfEntries= _opentrepService->insertIntoDBAndXapian();
184 
185  // Dump the results into the output string
186  oPythonLogStr << lNbOfEntries;
187 
188  // DEBUG
189  *_logOutputStream << "Xapian indexation yielded " << lNbOfEntries
190  << " POR (points of reference) entries." << std::endl;
191 
192  } catch (const RootException& eOpenTrepError) {
193  *_logOutputStream << "OpenTrep error: " << eOpenTrepError.what()
194  << std::endl;
195 
196  } catch (const std::exception& eStdError) {
197  *_logOutputStream << "Error: " << eStdError.what() << std::endl;
198 
199  } catch (...) {
200  *_logOutputStream << "Unknown error" << std::endl;
201  }
202 
203  //
204  return oPythonLogStr.str();
205  }
206 
210  std::string searchImpl(const std::string& iTravelQuery,
211  const OutputFormat::EN_OutputFormat& iOutputFormat) {
212  const std::string oEmptyStr ("");
213  std::ostringstream oNoDetailedStr;
214  std::ostringstream oDetailedStr;
215  std::ostringstream oJSONStr;
216  std::ostringstream oProtobufStr;
217 
218  // Sanity check
219  if (_logOutputStream == NULL) {
220  oNoDetailedStr << "The log filepath is not valid." << std::endl;
221  return oNoDetailedStr.str();
222  }
223  assert (_logOutputStream != NULL);
224 
225  try {
226 
227  // DEBUG
228  *_logOutputStream << "Travel query ('" << iTravelQuery << "'"
229  << "') search" << std::endl;
230 
231  if (_opentrepService == NULL) {
232  oNoDetailedStr << "The OpenTREP service has not been initialised, "
233  << "i.e., the init() method has not been called "
234  << "correctly on the OpenTrepSearcher object. Please "
235  << "check that all the parameters are not empty and "
236  << "point to actual files.";
237  *_logOutputStream << oNoDetailedStr.str();
238  return oNoDetailedStr.str();
239  }
240  assert (_opentrepService != NULL);
241 
242  // Retrieve the underlying file-path details
243  const OPENTREP_Service::FilePathSet_T& lFilePathSet =
244  _opentrepService->getFilePaths();
245  const PORFilePath_T& lPORFilePath = lFilePathSet.first;
246  const OPENTREP_Service::DBFilePathPair_T& lDBFilePathPair =
247  lFilePathSet.second;
248  const TravelDBFilePath_T& lTravelDBFilePath = lDBFilePathPair.first;
249  const SQLDBConnectionString_T& lSQLDBConnStr = lDBFilePathPair.second;
250 
251  // DEBUG
252  *_logOutputStream << "Xapian travel database/index: '"
253  << lTravelDBFilePath
254  << "' - SQL database connection string: '"
255  << lSQLDBConnStr
256  << "' - OPTD-maintained list of POR: '"
257  << lPORFilePath << "'" << std::endl;
258 
259  // Query the Xapian database (index)
260  WordList_T lNonMatchedWordList;
261  LocationList_T lLocationList;
262  const NbOfMatches_T nbOfMatches =
263  _opentrepService->interpretTravelRequest (iTravelQuery, lLocationList,
264  lNonMatchedWordList);
265 
266  // DEBUG
267  *_logOutputStream << "Python search for '" << iTravelQuery << "' gave "
268  << nbOfMatches << " matches." << std::endl;
269 
270  if (nbOfMatches != 0) {
271  NbOfMatches_T idx = 0;
272 
273  for(LocationList_T::const_iterator itLocation = lLocationList.begin();
274  itLocation != lLocationList.end(); ++itLocation, ++idx) {
275  const Location& lLocation = *itLocation;
276 
277  if (idx != 0) {
278  oNoDetailedStr << ",";
279  }
280 
281  //
282  oNoDetailedStr << lLocation.getIataCode();
283  oDetailedStr << idx+1 << ". " << lLocation.toSingleLocationString()
284  << std::endl;
285 
286  // List of extra matching locations (those with the same
287  // matching weight/percentage)
288  const LocationList_T& lExtraLocationList =
289  lLocation.getExtraLocationList();
290  if (lExtraLocationList.empty() == false) {
291  oDetailedStr << " Extra matches: " << std::endl;
292 
293  NbOfMatches_T idxExtra = 0;
294  for (LocationList_T::const_iterator itLoc =
295  lExtraLocationList.begin();
296  itLoc != lExtraLocationList.end(); ++itLoc, ++idxExtra) {
297  oNoDetailedStr << ":";
298  oDetailedStr << " " << idx+1 << "." << idxExtra+1 << ". ";
299 
300  const Location& lExtraLocation = *itLoc;
301  oNoDetailedStr << lExtraLocation.getIataCode();
302  oDetailedStr << lExtraLocation << std::endl;
303  }
304  }
305 
306  // The matching weight/percentage is the same for the main
307  // and the extra matching locations
308  oNoDetailedStr << "/" << lLocation.getPercentage();
309 
310  // List of alternate matching locations (those with a lower
311  // matching weight/percentage)
312  const LocationList_T& lAlternateLocationList =
313  lLocation.getAlternateLocationList();
314  if (lAlternateLocationList.empty() == false) {
315  oDetailedStr << " Alternate matches: " << std::endl;
316 
317  NbOfMatches_T idxAlter = 0;
318  for (LocationList_T::const_iterator itLoc =
319  lAlternateLocationList.begin();
320  itLoc != lAlternateLocationList.end(); ++itLoc, ++idxAlter) {
321  oNoDetailedStr << "-";
322  oDetailedStr << " " << idx+1 << "." << idxAlter+1 << ". ";
323 
324  const Location& lAlternateLocation = *itLoc;
325  oNoDetailedStr << lAlternateLocation.getIataCode()
326  << "/" << lAlternateLocation.getPercentage();
327  oDetailedStr << lAlternateLocation << std::endl;
328  }
329  }
330  }
331  }
332 
333  if (lNonMatchedWordList.empty() == false) {
334  oNoDetailedStr << ";";
335  oDetailedStr << "Not recognised words:" << std::endl;
336  NbOfMatches_T idx = 0;
337  for (WordList_T::const_iterator itWord = lNonMatchedWordList.begin();
338  itWord != lNonMatchedWordList.end(); ++itWord, ++idx) {
339  const Word_T& lWord = *itWord;
340  if (idx != 0) {
341  oNoDetailedStr << ",";
342  oDetailedStr << idx+1 << "." << std::endl;
343  }
344  oNoDetailedStr << lWord;
345  oDetailedStr << lWord;
346  }
347  }
348 
349  // DEBUG
350  *_logOutputStream << "Python search for '" << iTravelQuery
351  << "' yielded:" << std::endl;
352 
353  // Export the list of Location objects into a JSON-formatted string
354  BomJSONExport::jsonExportLocationList (oJSONStr, lLocationList);
355 
356  // Export the list of Location objects into a Protobuf-formatted string
357  LocationExchange::exportLocationList (oProtobufStr, lLocationList,
358  lNonMatchedWordList);
359 
360  // DEBUG
361  *_logOutputStream << "Short version: "
362  << oNoDetailedStr.str() << std::endl;
363  *_logOutputStream << "Long version: "
364  << oDetailedStr.str() << std::endl;
365  *_logOutputStream << "JSON version: "
366  << oJSONStr.str() << std::endl;
367  *_logOutputStream << "Protobuf version: "
368  << oProtobufStr.str() << std::endl;
369 
370  } catch (const RootException& eOpenTrepError) {
371  *_logOutputStream << "OpenTrep error: " << eOpenTrepError.what()
372  << std::endl;
373 
374  } catch (const std::exception& eStdError) {
375  *_logOutputStream << "Error: " << eStdError.what() << std::endl;
376 
377  } catch (...) {
378  *_logOutputStream << "Unknown error" << std::endl;
379  }
380 
381  // Return the string corresponding to the request (either with
382  // or without details).
383  switch (iOutputFormat) {
384  case OutputFormat::SHORT: {
385  return oNoDetailedStr.str();
386  }
387 
388  case OutputFormat::FULL: {
389  return oDetailedStr.str();
390  }
391 
392  case OutputFormat::JSON: {
393  return oJSONStr.str();
394  }
395 
396  case OutputFormat::PROTOBUF: {
397  return oProtobufStr.str();
398  }
399 
400  default: {
401  // If the output format is not known, an exception is thrown by
402  // the call to the OutputFormat() constructor above.
403  assert (false);
404  }
405  }
406 
407  // That line cannot be reached, but some compilers fail if no final return
408  return oEmptyStr;
409  }
410 
414  std::string generateImpl(const NbOfMatches_T& iNbOfDraws,
415  const OutputFormat::EN_OutputFormat& iOutputFormat){
416  const std::string oEmptyStr ("");
417  std::ostringstream oNoDetailedStr;
418  std::ostringstream oDetailedStr;
419  std::ostringstream oJSONStr;
420  std::ostringstream oProtobufStr;
421 
422  // Sanity check
423  if (_logOutputStream == NULL) {
424  oNoDetailedStr << "The log filepath is not valid." << std::endl;
425  return oNoDetailedStr.str();
426  }
427  assert (_logOutputStream != NULL);
428 
429  try {
430 
431  // DEBUG
432  *_logOutputStream << "Number of random draws: " << iNbOfDraws
433  << std::endl;
434 
435  if (_opentrepService == NULL) {
436  oNoDetailedStr << "The OpenTREP service has not been initialised, "
437  << "i.e., the init() method has not been called "
438  << "correctly on the OpenTrepSearcher object. Please "
439  << "check that all the parameters are not empty and "
440  << "point to actual files.";
441  *_logOutputStream << oNoDetailedStr.str();
442  return oNoDetailedStr.str();
443  }
444  assert (_opentrepService != NULL);
445 
446  // Retrieve the underlying file-path details
447  const OPENTREP_Service::FilePathSet_T& lFilePathSet =
448  _opentrepService->getFilePaths();
449  const PORFilePath_T& lPORFilePath = lFilePathSet.first;
450  const OPENTREP_Service::DBFilePathPair_T& lDBFilePathPair =
451  lFilePathSet.second;
452  const TravelDBFilePath_T& lTravelDBFilePath = lDBFilePathPair.first;
453  const SQLDBConnectionString_T& lSQLDBConnStr = lDBFilePathPair.second;
454 
455  // DEBUG
456  *_logOutputStream << "Xapian travel database/index: '"
457  << lTravelDBFilePath
458  << "' - SQL database connection string: '"
459  << lSQLDBConnStr
460  << "' - OPTD-maintained list of POR: '"
461  << lPORFilePath << "'" << std::endl;
462 
463  // Query the Xapian database (index)
464  LocationList_T lLocationList;
465  const NbOfMatches_T nbOfMatches =
466  _opentrepService->drawRandomLocations (iNbOfDraws, lLocationList);
467 
468  // DEBUG
469  *_logOutputStream << "Python generation of " << iNbOfDraws << " gave "
470  << nbOfMatches << " documents." << std::endl;
471 
472  if (nbOfMatches != 0) {
473  NbOfMatches_T idx = 0;
474 
475  for(LocationList_T::const_iterator itLocation = lLocationList.begin();
476  itLocation != lLocationList.end(); ++itLocation, ++idx) {
477  const Location& lLocation = *itLocation;
478 
479  if (idx != 0) {
480  oNoDetailedStr << ",";
481  }
482 
483  //
484  oNoDetailedStr << lLocation.getIataCode();
485  oDetailedStr << idx+1 << ". " << lLocation.toSingleLocationString()
486  << std::endl;
487 
488  // List of extra matching locations (those with the same
489  // matching weight/percentage)
490  const LocationList_T& lExtraLocationList =
491  lLocation.getExtraLocationList();
492  if (lExtraLocationList.empty() == false) {
493  oDetailedStr << " Extra matches: " << std::endl;
494 
495  NbOfMatches_T idxExtra = 0;
496  for (LocationList_T::const_iterator itLoc =
497  lExtraLocationList.begin();
498  itLoc != lExtraLocationList.end(); ++itLoc, ++idxExtra) {
499  oNoDetailedStr << ":";
500  oDetailedStr << " " << idx+1 << "." << idxExtra+1 << ". ";
501 
502  const Location& lExtraLocation = *itLoc;
503  oNoDetailedStr << lExtraLocation.getIataCode();
504  oDetailedStr << lExtraLocation << std::endl;
505  }
506  }
507 
508  // The matching weight/percentage is the same for the main
509  // and the extra matching locations
510  oNoDetailedStr << "/" << lLocation.getPercentage();
511 
512  // List of alternate matching locations (those with a lower
513  // matching weight/percentage)
514  const LocationList_T& lAlternateLocationList =
515  lLocation.getAlternateLocationList();
516  if (lAlternateLocationList.empty() == false) {
517  oDetailedStr << " Alternate matches: " << std::endl;
518 
519  NbOfMatches_T idxAlter = 0;
520  for (LocationList_T::const_iterator itLoc =
521  lAlternateLocationList.begin();
522  itLoc != lAlternateLocationList.end(); ++itLoc, ++idxAlter) {
523  oNoDetailedStr << "-";
524  oDetailedStr << " " << idx+1 << "." << idxAlter+1 << ". ";
525 
526  const Location& lAlternateLocation = *itLoc;
527  oNoDetailedStr << lAlternateLocation.getIataCode()
528  << "/" << lAlternateLocation.getPercentage();
529  oDetailedStr << lAlternateLocation << std::endl;
530  }
531  }
532  }
533  }
534 
535  // DEBUG
536  *_logOutputStream << "Python generation of " << iNbOfDraws
537  << " yielded:" << std::endl;
538 
539  // Export the list of Location objects into a JSON-formatted string
540  BomJSONExport::jsonExportLocationList (oJSONStr, lLocationList);
541 
542  // Export the list of Location objects into a Protobuf-formatted string
543  WordList_T lNonMatchedWordList;
544  LocationExchange::exportLocationList (oProtobufStr, lLocationList,
545  lNonMatchedWordList);
546 
547  // DEBUG
548  *_logOutputStream << "Short version: "
549  << oNoDetailedStr.str() << std::endl;
550  *_logOutputStream << "Long version: "
551  << oDetailedStr.str() << std::endl;
552  *_logOutputStream << "JSON version: "
553  << oJSONStr.str() << std::endl;
554  *_logOutputStream << "Protobuf version: "
555  << oProtobufStr.str() << std::endl;
556 
557  } catch (const RootException& eOpenTrepError) {
558  *_logOutputStream << "OpenTrep error: " << eOpenTrepError.what()
559  << std::endl;
560 
561  } catch (const std::exception& eStdError) {
562  *_logOutputStream << "Error: " << eStdError.what() << std::endl;
563 
564  } catch (...) {
565  *_logOutputStream << "Unknown error" << std::endl;
566  }
567 
568  // Return the string corresponding to the request (either with
569  // or without details).
570  switch (iOutputFormat) {
571  case OutputFormat::SHORT: {
572  return oNoDetailedStr.str();
573  }
574 
575  case OutputFormat::FULL: {
576  return oDetailedStr.str();
577  }
578 
579  case OutputFormat::JSON: {
580  return oJSONStr.str();
581  }
582 
583  case OutputFormat::PROTOBUF: {
584  return oProtobufStr.str();
585  }
586 
587  default: {
588  // If the output format is not known, an exception is thrown by
589  // the call to the OutputFormat() constructor above.
590  assert (false);
591  }
592  }
593 
594  // That line cannot be reached, but some compilers fail if no final return
595  return oEmptyStr;
596  }
597 
598  public:
602  OpenTrepSearcher() : _opentrepService (NULL), _logOutputStream (NULL) {
603  }
604 
608  OpenTrepSearcher (const OpenTrepSearcher& iOpenTrepSearcher)
609  : _opentrepService (iOpenTrepSearcher._opentrepService),
610  _logOutputStream (iOpenTrepSearcher._logOutputStream) {
611  }
612 
617  _opentrepService = NULL;
618  _logOutputStream = NULL;
619  }
620 
624  bool init (const std::string& iTravelDBFilePath,
625  const std::string& iSQLDBTypeStr,
626  const std::string& iSQLDBConnStr,
627  const DeploymentNumber_T& iDeploymentNumber,
628  const std::string& iLogFilePath) {
629  bool isEverythingOK = true;
630 
631  try {
632 
633  // Add the deployment number/version to the Xapian file-path
634  std::ostringstream oXFP;
635  oXFP << iTravelDBFilePath << iDeploymentNumber;
636  const std::string lXapianFP = oXFP.str();
637 
638  // Check that the file-path exist and are accessible
639  boost::filesystem::path lXapianFilePath (lXapianFP.begin(),
640  lXapianFP.end());
641  if (!(boost::filesystem::exists (lXapianFilePath)
642  && boost::filesystem::is_directory (lXapianFilePath))) {
643  isEverythingOK = false;
644  return isEverythingOK;
645  }
646 
647  // Set the log parameters
648  _logOutputStream = new std::ofstream;
649  assert (_logOutputStream != NULL);
650 
651  // Open and clean the log outputfile
652  _logOutputStream->open (iLogFilePath.c_str());
653  _logOutputStream->clear();
654 
655  // DEBUG
656  *_logOutputStream << "Python wrapper initialisation" << std::endl;
657 
658  // Initialise the context
659  const OPENTREP::TravelDBFilePath_T lTravelDBFilePath (iTravelDBFilePath);
660  const OPENTREP::DBType lSQLDBType (iSQLDBTypeStr);
661  const OPENTREP::SQLDBConnectionString_T lSQLDBConnStr (iSQLDBConnStr);
662  const OPENTREP::DeploymentNumber_T lDeploymentNumber (iDeploymentNumber);
663 
664  _opentrepService = new OPENTREP_Service (*_logOutputStream,
665  lTravelDBFilePath,
666  lSQLDBType, lSQLDBConnStr,
667  lDeploymentNumber);
668 
669  // DEBUG
670  *_logOutputStream << "Python wrapper initialised" << std::endl;
671 
672  } catch (const RootException& eOpenTrepError) {
673  *_logOutputStream << "OpenTrep error: " << eOpenTrepError.what()
674  << std::endl;
675 
676  } catch (const std::exception& eStdError) {
677  *_logOutputStream << "Error: " << eStdError.what() << std::endl;
678 
679  } catch (...) {
680  *_logOutputStream << "Unknown error" << std::endl;
681  }
682 
683  return isEverythingOK;
684  }
685 
689  bool finalize () {
690  bool isEverythingOK = true;
691 
692  try {
693 
694  // Finalize the context
695  if (_opentrepService != NULL) {
696  delete _opentrepService; _opentrepService = NULL;
697  }
698 
699  // Close the output stream
700  if (_logOutputStream != NULL) {
701  // DEBUG
702  *_logOutputStream << "Python wrapper finalization" << std::endl;
703  _logOutputStream->close();
704  delete _logOutputStream; _logOutputStream = NULL;
705  }
706 
707  } catch (...) {
708  }
709 
710  return isEverythingOK;
711  }
712 
713  private:
717  OPENTREP_Service* _opentrepService;
718  std::ofstream* _logOutputStream;
719  };
720 
721 }
722 
723 // /////////////////////////////////////////////////////////////
724 BOOST_PYTHON_MODULE(pyopentrep) {
725  boost::python::class_<OPENTREP::OpenTrepSearcher> ("OpenTrepSearcher")
726  .def ("index", &OPENTREP::OpenTrepSearcher::index)
727  .def ("search", &OPENTREP::OpenTrepSearcher::search)
728  .def ("generate", &OPENTREP::OpenTrepSearcher::generate)
729  .def ("getPaths", &OPENTREP::OpenTrepSearcher::getPaths)
730  .def ("init", &OPENTREP::OpenTrepSearcher::init)
731  .def ("finalize", &OPENTREP::OpenTrepSearcher::finalize);
732 }
unsigned short NbOfMatches_T
std::string Word_T
OpenTrepSearcher(const OpenTrepSearcher &iOpenTrepSearcher)
Definition: pyopentrep.cpp:608
NbOfDBEntries_T insertIntoDBAndXapian()
bool init(const std::string &iTravelDBFilePath, const std::string &iSQLDBTypeStr, const std::string &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber, const std::string &iLogFilePath)
Definition: pyopentrep.cpp:624
unsigned int NbOfDBEntries_T
Interface for the OPENTREP Services.
std::vector< std::string > WordList_T
NbOfMatches_T drawRandomLocations(const NbOfMatches_T &iNbOfDraws, LocationList_T &)
Enumeration of database types.
Definition: DBType.hpp:17
Root of the OpenTREP exceptions.
Enumeration of output formats.
std::string search(const std::string &iOutputFormatString, const std::string &iTravelQuery)
Definition: pyopentrep.cpp:62
API wrapper around the OpenTREP C++ API, so that Python scripts can use it seamlessly.
Definition: pyopentrep.cpp:27
std::list< Location > LocationList_T
NbOfMatches_T interpretTravelRequest(const std::string &iTravelQuery, LocationList_T &, WordList_T &)
std::pair< const PORFilePath_T, const DBFilePathPair_T > FilePathSet_T
static EN_OutputFormat getFormat(const char)
BOOST_PYTHON_MODULE(pyopentrep)
Definition: pyopentrep.cpp:724
FilePathSet_T getFilePaths() const
static void jsonExportLocationList(std::ostream &, const LocationList_T &)
static void exportLocationList(std::ostream &, const LocationList_T &, const WordList_T &iNonMatchedWordList)
std::string generate(const std::string &iOutputFormatString, const NbOfMatches_T &iNbOfDraws)
Definition: pyopentrep.cpp:51
unsigned short DeploymentNumber_T
const char * what() const
std::pair< const TravelDBFilePath_T, const SQLDBConnectionString_T > DBFilePathPair_T