Commit 7663a6dc authored by Volker Krause's avatar Volker Krause

Resolve abbreviations used in airport names

parent 4f770b45
......@@ -28,6 +28,14 @@
using namespace KItinerary;
namespace KItinerary { namespace KnowledgeDb {
char *toString(const IataCode &code)
{
using QTest::toString;
return toString(code.toString());
}
}}
class AirportDbTest : public QObject
{
Q_OBJECT
......@@ -164,6 +172,12 @@ private Q_SLOTS:
// multiple unique hits / unique hit on valid (but wrong) IATA code
// TODO should actually be GMP
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("SEOUL KR GIMPO INTERNATIONAL TERMINAL I - SKY CITY INTERNATIONAL TERMINAL")), KnowledgeDb::IataCode{});
// Amadeus/BCD airport names containing city/country data too, and using "INTL" abbrevation
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("SAN FRANCISCO CA SAN FRANCISCO INTL")), KnowledgeDb::IataCode{"SFO"});
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("BEIJING CN CAPITAL INTL")), KnowledgeDb::IataCode{"PEK"});
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("FRANKFURT DE - FRANKFURT INTL")), KnowledgeDb::IataCode{}); // ambigious with Frankfurt Hahn
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("SEATTLE US - SEATTLE TACOMA INTL")), KnowledgeDb::IataCode{"SEA"});
}
void countryDataTest()
......
......@@ -74,6 +74,13 @@ static void stripAirportAllLanguages(QStringList &s)
s.removeAll(QStringLiteral("terminal"));
}
static void normalizeAbbreviations(QStringList &l)
{
for (auto &s : l) {
if (s == QLatin1String("intl")) { s = QStringLiteral("international"); }
}
}
void AirportDbGenerator::merge(Airport &lhs, const Airport &rhs)
{
if (lhs.iataCode != rhs.iataCode) {
......@@ -233,6 +240,7 @@ void KItinerary::Generator::AirportDbGenerator::indexNames()
std::for_each(l.begin(), l.end(), [](QString &s) {
s = s.toCaseFolded();
});
normalizeAbbreviations(l);
std::sort(l.begin(), l.end());
l.removeAll(it.value().iataCode.toCaseFolded());
l.removeAll(it.value().icaoCode.toCaseFolded());
......
......@@ -125,6 +125,15 @@ KnowledgeDb::CountryId countryForAirport(IataCode iataCode)
return (*it).country;
}
static QString normalizeFragment(const QString &s)
{
auto res = StringUtil::normalize(s);
// resolve abbreviations
if (res == QLatin1String("intl")) return QStringLiteral("international");
return res;
}
static void applyTransliterations(QStringList &fragments)
{
// note that the output has the corresponding diacritic markers already stripped,
......@@ -228,7 +237,7 @@ static IataCode iataCodeForIataCodeFragment(const QStringList &fragments)
code = searchCode;
}
// check that this is only a IATA code, not also a (conflicting) name fragment
const auto uniqueFragmentCode = iataCodeForUniqueFragment(StringUtil::normalize(s));
const auto uniqueFragmentCode = iataCodeForUniqueFragment(normalizeFragment(s));
if (uniqueFragmentCode.isValid() && code.isValid() && uniqueFragmentCode != code) {
return {};
}
......@@ -250,7 +259,7 @@ IataCode iataCodeFromName(const QString &name)
const auto fragments = name.split(QRegularExpression(QStringLiteral("[ 0-9/'\"\\(\\)&\\,.–„-]")), QString::SkipEmptyParts);
QStringList normalizedFragments;
normalizedFragments.reserve(fragments.size());
std::transform(fragments.begin(), fragments.end(), std::back_inserter(normalizedFragments), [](const auto &s) { return StringUtil::normalize(s); });
std::transform(fragments.begin(), fragments.end(), std::back_inserter(normalizedFragments), [](const auto &s) { return normalizeFragment(s); });
IataCode code = iataCodeForNameFragments(normalizedFragments);
if (code.isValid()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment