OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Place.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // OpenTrep
11 #include <opentrep/bom/Place.hpp>
13 
14 namespace OPENTREP {
15 
16  // //////////////////////////////////////////////////////////////////////
17  Place::Place() :
18  _world (NULL), _placeHolder (NULL), _mainPlace (NULL),
19  _location (IATACode_T (""), IATAType::LAST_VALUE, 0,
20  ICAOCode_T (""), FAACode_T (""),
21  CommonName_T (""), ASCIIName_T (""), 0,
22  Date_T (1970, 01, 01), Date_T (2999, 12, 31), Comment_T (""),
23  CityCode_T (""), CityUTFName_T (""), CityASCIIName_T (""), 0,
24  StateCode_T (""),
25  CountryCode_T (""), AltCountryCode_T (""), CountryName_T (""),
26  ContinentName_T (""),
27  0.0, 0.0,
28  FeatureClass_T (""), FeatureCode_T (""),
29  Admin1Code_T (""), Admin1UTFName_T (""), Admin1ASCIIName_T (""),
30  Admin2Code_T (""), Admin2UTFName_T (""), Admin2ASCIIName_T (""),
31  Admin3Code_T (""), Admin4Code_T (""),
32  0, 0, 0, TimeZone_T (""), 0, 0, 0,
33  Date_T (2000, 01, 01), TvlPORListString_T (""),
34  WikiLink_T (""), K_DEFAULT_PAGE_RANK, "", "", 0, 0, 0,
35  RawDataString_T ("")),
36  _docID (0) {
37  }
38 
39  // //////////////////////////////////////////////////////////////////////
40  Place::Place (const LocationKey& iKey) :
41  _world (NULL), _placeHolder (NULL), _mainPlace (NULL),
42  _location (iKey.getIataCode(), iKey.getIataType(), iKey.getGeonamesID(),
43  ICAOCode_T (""), FAACode_T (""),
44  CommonName_T (""), ASCIIName_T (""), 0,
45  Date_T (1970, 01, 01), Date_T (2999, 12, 31), Comment_T (""),
46  CityCode_T (""), CityUTFName_T (""), CityASCIIName_T (""), 0,
47  StateCode_T (""),
48  CountryCode_T (""), AltCountryCode_T (""), CountryName_T (""),
49  ContinentName_T (""),
50  0.0, 0.0,
51  FeatureClass_T (""), FeatureCode_T (""),
52  Admin1Code_T (""), Admin1UTFName_T (""), Admin1ASCIIName_T (""),
53  Admin2Code_T (""), Admin2UTFName_T (""), Admin2ASCIIName_T (""),
54  Admin3Code_T (""), Admin4Code_T (""),
55  0, 0, 0, TimeZone_T (""), 0, 0, 0,
56  Date_T (2000, 01, 01), TvlPORListString_T (""),
57  WikiLink_T (""), K_DEFAULT_PAGE_RANK, "", "", 0, 0, 0,
58  RawDataString_T ("")),
59  _docID (0) {
60  }
61 
62  // //////////////////////////////////////////////////////////////////////
63  Place::Place (const Location& iLocation) :
64  _world (NULL), _placeHolder (NULL), _mainPlace (NULL),
65  _location (iLocation), _docID (0) {
66  }
67 
68  // //////////////////////////////////////////////////////////////////////
69  Place::Place (const Place& iPlace) :
70  _world (iPlace._world), _placeHolder (iPlace._placeHolder),
71  _mainPlace (iPlace._mainPlace),
72  _location (iPlace._location),
73  _docID (iPlace._docID),
74  _termSetMap (iPlace._termSetMap), _spellingSet (iPlace._spellingSet),
75  _stemmingSet (iPlace._stemmingSet), _synonymSet (iPlace._synonymSet) {
76  }
77 
78  // //////////////////////////////////////////////////////////////////////
79  Place::~Place() {
80  }
81 
82  // //////////////////////////////////////////////////////////////////////
83  std::string Place::toString() const {
84  std::ostringstream oStr;
85  oStr << _location.toString();
86  oStr << ", " << _docID
87  << ". ";
88 
89  if (_extraPlaceList.empty() == false) {
90  oStr << "; Extra matches: {";
91  unsigned short idx = 0;
92  for (PlaceOrderedList_T::const_iterator itLoc = _extraPlaceList.begin();
93  itLoc != _extraPlaceList.end(); ++itLoc, ++idx) {
94  if (idx != 0) {
95  oStr << "; ";
96  }
97  const Place* lExtraPlace_ptr = *itLoc;
98  assert (lExtraPlace_ptr != NULL);
99  oStr << lExtraPlace_ptr->toShortString();
100  }
101  oStr << "}";
102  }
103 
104  if (_alternatePlaceList.empty() == false) {
105  oStr << "; Alternate matches: {";
106  unsigned short idx = 0;
107  for (PlaceOrderedList_T::const_iterator itLoc =
108  _alternatePlaceList.begin();
109  itLoc != _alternatePlaceList.end(); ++itLoc, ++idx) {
110  if (idx != 0) {
111  oStr << "; ";
112  }
113  const Place* lAlternatePlace_ptr = *itLoc;
114  assert (lAlternatePlace_ptr != NULL);
115  oStr << lAlternatePlace_ptr->toShortString();
116  }
117  oStr << "}";
118  }
119 
120  return oStr.str();
121  }
122 
123  // //////////////////////////////////////////////////////////////////////
124  std::string Place::toShortString() const {
130  std::ostringstream oStr;
131  oStr << _location.toShortString();
132  oStr << ", " << _docID;
133 
134  if (_extraPlaceList.empty() == false) {
135  oStr << " " << _extraPlaceList.size() << " extra match(es)";
136  }
137 
138  if (_alternatePlaceList.empty() == false) {
139  oStr << " " << _alternatePlaceList.size() << " alternate match(es)";
140  }
141 
142  return oStr.str();
143  }
144 
145  // //////////////////////////////////////////////////////////////////////
146  void Place::toStream (std::ostream& ioOut) const {
147  ioOut << toString();
148  }
149 
150  // //////////////////////////////////////////////////////////////////////
151  void Place::fromStream (std::istream& ioIn) {
152  }
153 
154  // //////////////////////////////////////////////////////////////////////
155  std::string Place::describeSets() const {
156  std::ostringstream oStr;
157 
158  // Xapian index for the current place/POR (point of reference)
159  oStr << "[index] ";
160  short idx_map = 0;
161  for (TermSetMap_T::const_iterator itStringSet = _termSetMap.begin();
162  itStringSet != _termSetMap.end(); ++itStringSet, ++idx_map) {
163  if (idx_map != 0) {
164  oStr << " - ";
165  }
166  // Retrieve the weight and display it
167  const Weight_T& lWeight = itStringSet->first;
168  oStr << "[" << lWeight << "] ";
169 
170  // Retrieve and browse the set of strings for that weight
171  const StringSet_T& lStringSet = itStringSet->second;
172  short idx_set = 0;
173  for (StringSet_T::const_iterator itString = lStringSet.begin();
174  itString != lStringSet.end(); ++itString, ++idx_set) {
175  if (idx_set != 0) {
176  oStr << ", ";
177  }
178  const std::string& lString = *itString;
179  oStr << lString;
180  }
181  }
182 
183  // Xapian spelling dictionary
184  oStr << "; [spelling] ";
185  short idx = 0;
186  for (StringSet_T::const_iterator itTerm = _spellingSet.begin();
187  itTerm != _spellingSet.end(); ++itTerm, ++idx) {
188  if (idx != 0) {
189  oStr << ", ";
190  }
191  const std::string& lTerm = *itTerm;
192  oStr << lTerm;
193  }
194  oStr << ";";
195 
196  return oStr.str();
197  }
198 
199  // //////////////////////////////////////////////////////////////////////
200  std::string Place::shortDisplay() const {
201  /* When the city code is empty, it means that the place is a city and
202  not an airport. The city code is thus the same as the place code
203  itself. */
204  std::ostringstream oStr;
205  oStr << _location.toBasicString();
206  oStr << ", " << _docID;
207  return oStr.str();
208  }
209 
210  // //////////////////////////////////////////////////////////////////////
211  std::string Place::display() const {
212  std::ostringstream oStr;
213  oStr << shortDisplay() << std::endl;
214  return oStr.str();
215  }
216 
217  // //////////////////////////////////////////////////////////////////////
219  _termSetMap.clear();
220  _spellingSet.clear();
221  _stemmingSet.clear();
222  _synonymSet.clear();
223  }
224 
225  // //////////////////////////////////////////////////////////////////////
227  // Initialise an empty string set
228  StringSet_T oTermSet;
229 
230  // If existing, retrieve the string set for that weight.
231  TermSetMap_T::const_iterator itTermSet = _termSetMap.find (iWeight);
232  if (itTermSet != _termSetMap.end()) {
233  oTermSet = itTermSet->second;
234  }
235 
236  return oTermSet;
237  }
238 
239  // //////////////////////////////////////////////////////////////////////
240  bool Place::addTermSet (const Weight_T& iWeight, const StringSet_T& iTermSet) {
241  bool hasInsertBeenSuccessful = true;
242 
243  // If existing, retrieve the string set for that weight.
244  TermSetMap_T::iterator itTermSet = _termSetMap.find (iWeight);
245 
246  if (itTermSet == _termSetMap.end()) {
247  // If there was no string set for that weight yet, insert it
248  hasInsertBeenSuccessful =
249  _termSetMap.insert (TermSetMap_T::value_type (iWeight, iTermSet)).second;
250 
251  // Sanity check
252  assert (hasInsertBeenSuccessful == true);
253 
254  } else {
255  // Otherwise, add the given string set, string by string,
256  // to the existing one
257  StringSet_T& lStringSet = itTermSet->second;
258  for (StringSet_T::const_iterator itString = iTermSet.begin();
259  itString != iTermSet.end(); ++itString) {
260  const std::string& lString = *itString;
261  lStringSet.insert (lString);
262  }
263  }
264 
265  return hasInsertBeenSuccessful;
266  }
267 
268  // //////////////////////////////////////////////////////////////////////
269  void Place::addNameToXapianSets (const Weight_T& iWeight,
270  const std::string& iBaseName,
271  const FeatureCode_T& iFeatureCode) {
272  // Retrieve the string set for the given weight, if existing
273  // (empty otherwise)
274  StringSet_T lTermSet = getTermSet (iWeight);
275 
282  const FeatureNameList_T& lFeatureNameList =
283  Location::getFeatureList (iFeatureCode);
284  for (FeatureNameList_T::const_iterator itFeatName = lFeatureNameList.begin();
285  itFeatName != lFeatureNameList.end(); ++itFeatName) {
286  const FeatureName_T& lFeatureName = *itFeatName;
287 
288  lTermSet.insert (iBaseName + " " + lFeatureName);
289  }
290 
291  // Insert (or replace) the newly created (or just altered) string set
292  addTermSet (iWeight, lTermSet);
293  }
294 
295  // //////////////////////////////////////////////////////////////////////
296  void Place::addNameToXapianSets (const Weight_T& iWeight,
297  const LocationName_T& iLocationName,
298  const FeatureCode_T& iFeatureCode,
299  const CityUTFName_T& iCityUtfName,
300  const CityASCIIName_T& iCityAsciiName,
301  const Admin1UTFName_T& iAdm1UtfName,
302  const Admin1ASCIIName_T& iAdm1AsciiName,
303  const Admin2UTFName_T& iAdm2UtfName,
304  const Admin2ASCIIName_T& iAdm2AsciiName,
305  const StateCode_T& iStateCode,
306  const CountryCode_T& iCountryCode,
307  const CountryName_T& iCountryName,
308  const ContinentName_T& iContinentName,
309  const OTransliterator& iTransliterator) {
310  // Retrieve the string set for the given weight, if existing
311  // (empty otherwise)
312  StringSet_T lTermSet = getTermSet (iWeight);
313 
314  // Tokenise the name. Some of the names contain punctuation characters.
315  // For instance, "Paris/FR/Gare" is transformed into "Paris FR Gare".
316  WordList_T lWordList;
317  tokeniseStringIntoWordList (iLocationName, lWordList);
318  const std::string lTokenisedName = createStringFromWordList (lWordList);
319 
320  // Add the tokenised name to the Xapian index
321  lTermSet.insert (lTokenisedName);
322 
323  // Add the (tokenised name, feature name) pair to the Xapian index
324  addNameToXapianSets (iWeight, lTokenisedName, iFeatureCode);
325 
326  // Add the (tokenised name, UTF8 city name) pair to the Xapian index
327  if (iCityUtfName.empty() == false) {
328  lTermSet.insert (lTokenisedName + " " + iCityUtfName);
329  }
330 
331  // Add the (tokenised name, ASCII city name) pair to the Xapian index
332  if (iCityAsciiName.empty() == false) {
333  lTermSet.insert (lTokenisedName + " " + iCityAsciiName);
334  }
335 
336  // Add the (tokenised name, UTF8 admin level 1 name) pair to the Xapian index
337  if (iAdm1UtfName.empty() == false) {
338  lTermSet.insert (lTokenisedName + " " + iAdm1UtfName);
339  }
340 
341  // Add the (tokenised name, ASCII adm level 1 name) pair to the Xapian index
342  if (iAdm1AsciiName.empty() == false) {
343  lTermSet.insert (lTokenisedName + " " + iAdm1AsciiName);
344  }
345 
346  // Add the (tokenised name, UTF8 admin level 2 name) pair to the Xapian index
347  if (iAdm2UtfName.empty() == false) {
348  lTermSet.insert (lTokenisedName + " " + iAdm2UtfName);
349  }
350 
351  // Add the (tokenised name, ASCII adm level 2 name) pair to the Xapian index
352  if (iAdm2AsciiName.empty() == false) {
353  lTermSet.insert (lTokenisedName + " " + iAdm2AsciiName);
354  }
355 
356  // Add the (tokenised name, state code) pair to the Xapian index
357  lTermSet.insert (lTokenisedName + " " + iStateCode);
358 
359  // Add the (tokenised name, country code) pair to the Xapian index
360  lTermSet.insert (lTokenisedName + " " + iCountryCode);
361 
362  // Add the (tokenised name, country name) pair to the Xapian index
363  lTermSet.insert (lTokenisedName + " " + iCountryName);
364 
365  // Add the (tokenised name, continent name) pair to the Xapian index
366  lTermSet.insert (lTokenisedName + " " + iContinentName);
367 
368  // Add the tokenised name to the Xapian spelling dictionary
369  _spellingSet.insert (lTokenisedName);
370 
371  // Normalise, according to the Unicode standard, the given name.
372  // Note that it is important to normalise after the tokenisation process,
373  // as the punctuation is eliminated (and not replaced by space)
374  // by that latter.
375  const std::string& lNormalisedCommonName =
376  iTransliterator.normalise (lTokenisedName);
377 
378  // Add the tokenised and normalised name to the Xapian index
379  lTermSet.insert (lNormalisedCommonName);
380 
381  // Add the (tokenised and normalised name, feature name) pair
382  // to the Xapian index
383  addNameToXapianSets (iWeight, lNormalisedCommonName, iFeatureCode);
384 
385  // Add the (tokenised and normalised name, UTF8 city name) pair
386  // to the Xapian index
387  if (iCityUtfName.empty() == false) {
388  lTermSet.insert (lNormalisedCommonName + " " + iCityUtfName);
389  }
390 
391  // Add the (tokenised and normalised name, ASCII city name) pair
392  // to the Xapian index
393  if (iCityAsciiName.empty() == false) {
394  lTermSet.insert (lNormalisedCommonName + " " + iCityAsciiName);
395  }
396 
397  // Add the (tokenised and normalised name, UTF8 admin level 1 name) pair
398  // to the Xapian index
399  if (iAdm1UtfName.empty() == false) {
400  lTermSet.insert (lNormalisedCommonName + " " + iAdm1UtfName);
401  }
402 
403  // Add the (tokenised and normalised name, ASCII adm level 1 name) pair
404  // to the Xapian index
405  if (iAdm1AsciiName.empty() == false) {
406  lTermSet.insert (lNormalisedCommonName + " " + iAdm1AsciiName);
407  }
408 
409  // Add the (tokenised and normalised name, UTF8 admin level 2 name) pair
410  // to the Xapian index
411  if (iAdm2UtfName.empty() == false) {
412  lTermSet.insert (lNormalisedCommonName + " " + iAdm2UtfName);
413  }
414 
415  // Add the (tokenised and normalised name, ASCII adm level 2 name) pair
416  // to the Xapian index
417  if (iAdm2AsciiName.empty() == false) {
418  lTermSet.insert (lNormalisedCommonName + " " + iAdm2AsciiName);
419  }
420 
421  // Add the (tokenised and normalised name, state code) pair to the
422  // Xapian index
423  lTermSet.insert (lNormalisedCommonName + " " + iStateCode);
424 
425  // Add the (tokenised and normalised name, country code) pair to the
426  // Xapian index
427  lTermSet.insert (lNormalisedCommonName + " " + iCountryCode);
428 
429  // Add the (tokenised and normalised name, country name) pair to the
430  // Xapian index
431  lTermSet.insert (lNormalisedCommonName + " " + iCountryName);
432 
433  // Add the (tokenised and normalised name, continent name) pair to the
434  // Xapian index
435  lTermSet.insert (lNormalisedCommonName + " " + iContinentName);
436 
437  // Add the tokenised and normalised name to the Xapian spelling dictionary
438  _spellingSet.insert (lNormalisedCommonName);
439 
440  // Insert (or replace) the newly created (or just altered) string set
441  addTermSet (iWeight, lTermSet);
442  }
443 
444  // //////////////////////////////////////////////////////////////////////
445  void Place::buildIndexSets (const OTransliterator& iTransliterator) {
446 
457  // Retrieve the PageRank
458  const PageRank_T& lPageRankDouble = _location.getPageRank();
459  //const Weight_T lPageRank =
460  // (lPageRankDouble == K_DEFAULT_PAGE_RANK)?
461  // K_DEFAULT_INDEXING_EXTRA_WEIGHT:
462  // static_cast<const Weight_T> (lPageRankDouble);
463  const Weight_T lPageRank = K_DEFAULT_INDEXING_EXTRA_WEIGHT
464  + static_cast<const Weight_T> (lPageRankDouble / 5.0);
465 
466  // Retrieve the string set for the given weight, if existing
467  // (empty otherwise)
468  StringSet_T lWeightedTermSet = getTermSet (lPageRank);
469 
470  // Retrieve the string set for the given weight, if existing
471  // (empty otherwise)
473 
474  // Retrieve the feature code
475  const FeatureCode_T& lFeatureCode = _location.getFeatureCode();
476 
477  // Add the IATA code
478  const std::string& lIataCode = _location.getIataCode();
479  if (lIataCode.empty() == false) {
480  lWeightedTermSet.insert (lIataCode);
481  _spellingSet.insert (lIataCode);
482 
483  // Add the (IATA code, feature name) to the Xapian index, where the
484  // feature name is derived from the feature code.
485  addNameToXapianSets (lPageRank, lIataCode, lFeatureCode);
486  }
487 
488  // Add the ICAO code
489  const std::string& lIcaoCode = _location.getIcaoCode();
490  if (lIcaoCode.empty() == false) {
491  lWeightedTermSet.insert (lIcaoCode);
492  _spellingSet.insert (lIcaoCode);
493 
494  // Add the (ICAO code, feature name) to the Xapian index, where the
495  // feature name is derived from the feature code.
496  addNameToXapianSets (lPageRank, lIcaoCode, lFeatureCode);
497  }
498 
499  // Add the FAA code
500  const std::string& lFaaCode = _location.getFaaCode();
501  if (lFaaCode.empty() == false) {
502  lWeightedTermSet.insert (lFaaCode);
503  _spellingSet.insert (lFaaCode);
504 
505  // Add the (FAA code, feature name) to the Xapian index, where the
506  // feature name is derived from the feature code.
507  addNameToXapianSets (lPageRank, lFaaCode, lFeatureCode);
508  }
509 
510  // Add the Geonames ID
511  const GeonamesID_T& lGeonamesID = _location.getGeonamesID();
512  if (lGeonamesID != 0) {
513  std::stringstream oStr;
514  oStr << lGeonamesID;
515  const std::string lGeonamesIDStr = oStr.str();
516  lStdTermSet.insert (lGeonamesIDStr);
517  _spellingSet.insert (lGeonamesIDStr);
518  }
519 
520  // Add the feature code
521  if (lFeatureCode.empty() == false) {
522  lWeightedTermSet.insert (lFeatureCode);
523  _spellingSet.insert (lFeatureCode);
524  }
525 
526  // Add the city IATA code
527  const std::string& lCityCode = _location.getCityCode();
528  if (lCityCode.empty() == false && lCityCode != lIataCode) {
529  lWeightedTermSet.insert (lCityCode);
530  _spellingSet.insert (lCityCode);
531  }
532 
533  // Add the city UTF8 name
534  const std::string& lCityUtfName = _location.getCityUtfName();
535  if (lCityUtfName.empty() == false) {
536  lWeightedTermSet.insert (lCityUtfName);
537  _spellingSet.insert (lCityUtfName);
538  }
539 
540  // Add the city ASCII name
541  const std::string& lCityAsciiName = _location.getCityAsciiName();
542  if (lCityAsciiName.empty() == false) {
543  lWeightedTermSet.insert (lCityAsciiName);
544  _spellingSet.insert (lCityAsciiName);
545  }
546 
547  // Add the state code
548  const std::string& lStateCode = _location.getStateCode();
549  if (lStateCode.empty() == false) {
550  lWeightedTermSet.insert (lStateCode);
551  _spellingSet.insert (lStateCode);
552  }
553 
554  // Add the country code
555  const std::string& lCountryCode = _location.getCountryCode();
556  lWeightedTermSet.insert (lCountryCode);
557 
558  // Add the country name
559  const std::string& lCountryName = _location.getCountryName();
560  if (lCountryName.empty() == false) {
561  lWeightedTermSet.insert (lCountryName);
562  _spellingSet.insert (lCountryName);
563  }
564 
565  // Add the administrative level 1 code
566  const std::string& lAdm1Code = _location.getAdmin1Code();
567  if (lAdm1Code.empty() == false) {
568  lWeightedTermSet.insert (lAdm1Code);
569  }
570 
571  // Add the administrative level 1 UTF8 name
572  const std::string& lAdm1UtfName = _location.getAdmin1UtfName();
573  if (lAdm1UtfName.empty() == false) {
574  lWeightedTermSet.insert (lAdm1UtfName);
575  _spellingSet.insert (lAdm1UtfName);
576  }
577 
578  // Add the administrative level 1 ASCII name
579  const std::string& lAdm1AsciiName = _location.getAdmin1AsciiName();
580  if (lAdm1AsciiName.empty() == false) {
581  lWeightedTermSet.insert (lAdm1AsciiName);
582  _spellingSet.insert (lAdm1AsciiName);
583  }
584 
585  // Add the administrative level 2 code
586  const std::string& lAdm2Code = _location.getAdmin1Code();
587  if (lAdm2Code.empty() == false) {
588  lWeightedTermSet.insert (lAdm2Code);
589  }
590 
591  // Add the administrative level 2 UTF8 name
592  const std::string& lAdm2UtfName = _location.getAdmin2UtfName();
593  if (lAdm2UtfName.empty() == false) {
594  lWeightedTermSet.insert (lAdm2UtfName);
595  _spellingSet.insert (lAdm2UtfName);
596  }
597 
598  // Add the administrative level 2 ASCII name
599  const std::string& lAdm2AsciiName = _location.getAdmin2AsciiName();
600  if (lAdm2AsciiName.empty() == false) {
601  lWeightedTermSet.insert (lAdm2AsciiName);
602  _spellingSet.insert (lAdm2AsciiName);
603  }
604 
605  // Add the continent name
606  const std::string& lContinentName = _location.getContinentName();
607  lWeightedTermSet.insert (lContinentName);
608 
609  // Add the common name (usually in American English, but not necessarily
610  // in ASCII).
611  const std::string& lCommonName = _location.getCommonName();
612  if (lCommonName.empty() == false) {
614  LocationName_T (lCommonName),
615  FeatureCode_T (lFeatureCode),
616  CityUTFName_T (lCityUtfName),
617  CityASCIIName_T (lCityAsciiName),
618  Admin1UTFName_T (lAdm1UtfName),
619  Admin1ASCIIName_T (lAdm1AsciiName),
620  Admin2UTFName_T (lAdm2UtfName),
621  Admin2ASCIIName_T (lAdm2AsciiName),
622  StateCode_T (lStateCode),
623  CountryCode_T (lCountryCode),
624  CountryName_T (lCountryName),
625  ContinentName_T (lContinentName), iTransliterator);
626  }
627 
628  // Add the ASCII name (not necessarily in English).
629  const std::string& lASCIIName = _location.getAsciiName();
630  if (lASCIIName.empty() == false) {
632  LocationName_T (lASCIIName),
633  FeatureCode_T (lFeatureCode),
634  CityUTFName_T (lCityUtfName),
635  CityASCIIName_T (lCityAsciiName),
636  Admin1UTFName_T (lAdm1UtfName),
637  Admin1ASCIIName_T (lAdm1AsciiName),
638  Admin2UTFName_T (lAdm2UtfName),
639  Admin2ASCIIName_T (lAdm2AsciiName),
640  StateCode_T (lStateCode),
641  CountryCode_T (lCountryCode),
642  CountryName_T (lCountryName),
643  ContinentName_T (lContinentName), iTransliterator);
644  }
645 
646  // Retrieve the place names in all the available languages
647  const NameMatrix& lNameMatrixFull = _location.getNameMatrix();
648  const NameMatrix_T& lNameMatrix = lNameMatrixFull.getNameMatrix();
649  for (NameMatrix_T::const_iterator itNameList = lNameMatrix.begin();
650  itNameList != lNameMatrix.end(); ++itNameList) {
651  // Retrieve the language code and locale
652  // const LanguageCode_T& lLanguage = itNameList->first;
653  const Names& lNames = itNameList->second;
654 
655  // For a given language, retrieve the list of place names
656  const NameList_T& lNameList = lNames.getNameList();
657 
658  for (NameList_T::const_iterator itName = lNameList.begin();
659  itName != lNameList.end(); ++itName) {
660  const std::string& lName = *itName;
661 
662  // Add the alternate name, which can be made of several words
663  // (e.g., 'san francisco').
664  if (lName.empty() == false) {
665  // Create a list made of all the word combinations of the
666  // initial string
667  WordCombinationHolder lWordCombinationHolder (lName);
668 
669  // Browse the list of unique strings (word combinations)
670  const WordCombinationHolder::StringList_T& lStringList =
671  lWordCombinationHolder._list;
672  for (WordCombinationHolder::StringList_T::const_iterator itString =
673  lStringList.begin();
674  itString != lStringList.end(); ++itString) {
675  const std::string& lWordCombination = *itString;
676  const std::string& lNormalisedWordCombination =
677  iTransliterator.normalise (lWordCombination);
678 
679  // Add that combination of words into the set of terms
680  lStdTermSet.insert (lWordCombination);
681  _spellingSet.insert (lWordCombination);
682 
683  // Add the normalised combination of words into the set of terms
684  lStdTermSet.insert (lNormalisedWordCombination);
685  _spellingSet.insert (lNormalisedWordCombination);
686  }
687  }
688  }
689  }
690 
691  // Insert (or replace) the newly created (or just altered) string set
692  addTermSet (lPageRank, lWeightedTermSet);
693 
694  // Insert (or replace) the newly created (or just altered) string set
696  }
697 
698  // //////////////////////////////////////////////////////////////////////
700 
701  NameList_T lNameList;
702  LanguageCode_T K_DEFAULT_LANGUAGE_CODE ("en_US");
703  const bool hasFoundNameList = getNameList (K_DEFAULT_LANGUAGE_CODE,
704  lNameList);
705 
706  if (hasFoundNameList == false) {
707  //
708  std::ostringstream errorStr;
709  errorStr << "No list of names in (American) English ("
710  << K_DEFAULT_LANGUAGE_CODE
711  << " locale) can be found for the following place: "
712  << toShortString();
713  OPENTREP_LOG_ERROR (errorStr.str());
714  // throw LanguageCodeNotDefinedInNameTableException (errorStr.str());
715  }
716  // assert (hasFoundNameList == true);
717 
718  // Add extra matching locations, whenever they exist
719  if (_extraPlaceList.empty() == false) {
720  for (PlaceOrderedList_T::const_iterator itLoc = _extraPlaceList.begin();
721  itLoc != _extraPlaceList.end(); ++itLoc) {
722  const Place* lExtraPlace_ptr = *itLoc;
723  assert (lExtraPlace_ptr != NULL);
724 
725  // Add the extra matching location
726  const Location& lExtraLocation = lExtraPlace_ptr->getLocation();
727  _location.addExtraLocation (lExtraLocation);
728  }
729  }
730 
731  // Add alternate matching locations, whenever they exist
732  if (_alternatePlaceList.empty() == false) {
733  for (PlaceOrderedList_T::const_iterator itLoc =
734  _alternatePlaceList.begin();
735  itLoc != _alternatePlaceList.end(); ++itLoc) {
736  const Place* lAlternatePlace_ptr = *itLoc;
737  assert (lAlternatePlace_ptr != NULL);
738 
739  // Add the alternate matching location
740  const Location& lAlternateLocation = lAlternatePlace_ptr->getLocation();
741  _location.addAlternateLocation (lAlternateLocation);
742  }
743  }
744 
745  return _location;
746  }
747 }
const Percentage_T K_DEFAULT_PAGE_RANK
const Admin1Code_T & getAdmin1Code() const
Definition: Location.hpp:262
const CountryCode_T & getCountryCode() const
Definition: Location.hpp:171
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:23
const Location & getLocation() const
Definition: Place.hpp:51
std::set< std::string > StringSet_T
Definition: Place.hpp:39
void addExtraLocation(const Location &iExtraLocation)
Definition: Location.hpp:818
void addNameToXapianSets(const Weight_T &, const LocationName_T &, const FeatureCode_T &, const CityUTFName_T &, const CityASCIIName_T &, const Admin1UTFName_T &, const Admin1ASCIIName_T &, const Admin2UTFName_T &, const Admin2ASCIIName_T &, const StateCode_T &, const CountryCode_T &, const CountryName_T &, const ContinentName_T &, const OTransliterator &)
Definition: Place.cpp:296
std::string createStringFromWordList(const WordList_T &iWordList, const unsigned short iSplitIdx, const bool iFromBeginningFlag)
Definition: Utilities.cpp:38
Structure modelling a (geographical) location.
Definition: Location.hpp:24
double PageRank_T
const Admin1ASCIIName_T & getAdmin1AsciiName() const
Definition: Location.hpp:276
const FeatureCode_T & getFeatureCode() const
Definition: Location.hpp:255
bool addTermSet(const Weight_T &, const StringSet_T &)
Definition: Place.cpp:240
unsigned short Weight_T
const CityASCIIName_T & getCityAsciiName() const
Definition: Location.hpp:150
const FAACode_T & getFaaCode() const
Definition: Location.hpp:72
const ContinentName_T & getContinentName() const
Definition: Location.hpp:199
const NameMatrix_T & getNameMatrix() const
Definition: NameMatrix.hpp:44
std::string shortDisplay() const
Definition: Place.cpp:200
std::string toShortString() const
Definition: Location.cpp:245
const Admin1UTFName_T & getAdmin1UtfName() const
Definition: Location.hpp:269
static FeatureNameList_T getFeatureList(const FeatureCode_T &)
Definition: Location.cpp:349
std::list< FeatureName_T > FeatureNameList_T
boost::gregorian::date Date_T
std::list< Word_T > WordList_T
std::list< std::string > NameList_T
Definition: Names.hpp:20
void toStream(std::ostream &) const
Definition: Place.cpp:146
const NameMatrix & getNameMatrix() const
Definition: Location.hpp:360
const Admin2UTFName_T & getAdmin2UtfName() const
Definition: Location.hpp:290
const Location & completeLocation()
Definition: Place.cpp:699
bool getNameList(const LanguageCode_T &iLanguageCode, NameList_T &ioNameList) const
Definition: Place.hpp:394
const PageRank_T & getPageRank() const
Definition: Location.hpp:339
const GeonamesID_T & getGeonamesID() const
Definition: Location.hpp:51
const ICAOCode_T & getIcaoCode() const
Definition: Location.hpp:65
const CommonName_T & getCommonName() const
Definition: Location.hpp:80
const CityUTFName_T & getCityUtfName() const
Definition: Location.hpp:143
Class modelling a place/POR (point of reference).
Definition: Place.hpp:28
void buildIndexSets(const OTransliterator &)
Definition: Place.cpp:445
std::list< std::string > StringList_T
std::string toString() const
Definition: Location.cpp:269
std::string toBasicString() const
Definition: Location.cpp:209
const IATACode_T & getIataCode() const
Definition: Location.hpp:37
std::string display() const
Definition: Place.cpp:211
const NameList_T & getNameList() const
Definition: Names.hpp:60
void fromStream(std::istream &)
Definition: Place.cpp:151
const Weight_T K_DEFAULT_INDEXING_STD_WEIGHT
StringSet_T getTermSet(const Weight_T &) const
Definition: Place.cpp:226
const Admin2ASCIIName_T & getAdmin2AsciiName() const
Definition: Location.hpp:297
void tokeniseStringIntoWordList(const std::string &iPhrase, WordList_T &ioWordList)
Definition: Utilities.cpp:16
const CityCode_T & getCityCode() const
Definition: Location.hpp:136
std::map< LanguageCode_T, Names > NameMatrix_T
Definition: Names.hpp:149
void addAlternateLocation(const Location &iAlternateLocation)
Definition: Location.hpp:825
std::string toString() const
Definition: Place.cpp:83
std::string toShortString() const
Definition: Place.cpp:124
void resetIndexSets()
Definition: Place.cpp:218
const StateCode_T & getStateCode() const
Definition: Location.hpp:164
std::string normalise(const std::string &iString) const
const CountryName_T & getCountryName() const
Definition: Location.hpp:185
const ASCIIName_T & getAsciiName() const
Definition: Location.hpp:87
std::string describeSets() const
Definition: Place.cpp:155
const Weight_T K_DEFAULT_INDEXING_EXTRA_WEIGHT