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