Commit 86da9772 authored by Volker Krause's avatar Volker Krause

Take the most specific candidate subset, not just the first one

parent db79da93
......@@ -171,7 +171,7 @@ private Q_SLOTS:
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("Frankfurt FRA")), KnowledgeDb::IataCode{"FRA"});
// multiple unique hits / unique hit on valid (but wrong) IATA code
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("SEOUL KR GIMPO INTERNATIONAL TERMINAL I - SKY CITY INTERNATIONAL TERMINAL")), KnowledgeDb::IataCode{"GMP"});
QCOMPARE(KnowledgeDb::iataCodeFromName(QStringLiteral("GIMPO INTERNATIONAL TERMINAL I - SKY CITY INTERNATIONAL TERMINAL")), KnowledgeDb::IataCode{"GMP"});
// 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"});
......@@ -189,6 +189,9 @@ private Q_SLOTS:
QCOMPARE(KnowledgeDb::iataCodesFromName(QStringLiteral("Stuttgart")), (std::vector<IataCode>{IataCode{"SGT"}, IataCode{"STR"}}));
QCOMPARE(KnowledgeDb::iataCodesFromName(QStringLiteral("Frankfurt")), (std::vector<IataCode>{IataCode{"FRA"}, IataCode{"HHN"}}));
QCOMPARE(KnowledgeDb::iataCodesFromName(QStringLiteral("Brussels")), (std::vector<IataCode>{IataCode{"BRU"}, IataCode{"CRL"}}));
// multiple unique hits / unique hit on valid (but wrong) IATA code
QCOMPARE(KnowledgeDb::iataCodesFromName(QStringLiteral("SEOUL KR GIMPO INTERNATIONAL TERMINAL I - SKY CITY INTERNATIONAL TERMINAL")), (std::vector<IataCode>{IataCode{"GMP"}, IataCode{"ICN"}}));
}
void countryDataTest()
......
......@@ -211,17 +211,14 @@ std::vector<KnowledgeDb::IataCode> KnowledgeDb::iataCodesFromName(const QString
normalizedFragments.reserve(fragments.size());
std::transform(fragments.begin(), fragments.end(), std::back_inserter(normalizedFragments), [](const auto &s) { return normalizeFragment(s); });
std::vector<IataCode> codes;
std::vector<IataCode> codes, candidates;
iataCodeForNameFragments(normalizedFragments, codes);
if (!codes.empty()) {
return codes;
}
// try again, with alternative translitarations of e.g. umlauts replaced
applyTransliterations(normalizedFragments);
iataCodeForNameFragments(normalizedFragments, codes);
if (!codes.empty()) {
return codes;
iataCodeForNameFragments(normalizedFragments, candidates);
if (!candidates.empty() && (codes.empty() || candidates.size() < codes.size())) {
codes = std::move(candidates);
}
// check if the name contained the IATA code as disambiguation already
......@@ -234,7 +231,11 @@ std::vector<KnowledgeDb::IataCode> KnowledgeDb::iataCodesFromName(const QString
auto it = std::find(normalizedFragments.begin(), normalizedFragments.end(), QStringLiteral("terminal"));
if (it != normalizedFragments.end()) {
normalizedFragments.erase(it, normalizedFragments.end());
iataCodeForNameFragments(normalizedFragments, codes);
candidates.clear();
iataCodeForNameFragments(normalizedFragments, candidates);
if (!candidates.empty() && (codes.empty() || candidates.size() < codes.size())) {
codes = std::move(candidates);
}
}
return codes;
}
......
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