[search] Test feature name language selection

This commit is contained in:
tatiana-kondakova 2018-04-18 16:42:07 +03:00 committed by mpimenov
parent 15b65d5fb2
commit e84f61066f
5 changed files with 148 additions and 7 deletions

View file

@ -264,6 +264,39 @@ string TestPOI::ToString() const
return os.str();
}
// TestMultilingualPOI -----------------------------------------------------------------------------
TestMultilingualPOI::TestMultilingualPOI(m2::PointD const & center, string const & defaultName,
map<string, string> const & multilingualNames)
: TestPOI(center, defaultName, "default"), m_multilingualNames(multilingualNames)
{
}
void TestMultilingualPOI::Serialize(FeatureBuilder1 & fb) const
{
TestPOI::Serialize(fb);
for (auto const & kv : m_multilingualNames)
{
CHECK(fb.AddName(kv.first, kv.second),
("Can't set feature name:", kv.second, "(", kv.first, ")"));
}
}
string TestMultilingualPOI::ToString() const
{
ostringstream os;
os << "TestPOI [(" << m_name << ", " << m_lang << "), ";
for (auto const & kv : m_multilingualNames)
os << "( " << kv.second << ", " << kv.first << "), ";
os << DebugPrint(m_center);
if (!m_houseNumber.empty())
os << ", " << m_houseNumber;
if (!m_streetName.empty())
os << ", " << m_streetName;
os << "]";
return os.str();
}
// TestBuilding ------------------------------------------------------------------------------------
TestBuilding::TestBuilding(m2::PointD const & center, string const & name,
string const & houseNumber, string const & lang)

View file

@ -7,6 +7,7 @@
#include "geometry/point2d.hpp"
#include <cstdint>
#include <map>
#include <string>
#include <utility>
#include <vector>
@ -47,12 +48,12 @@ protected:
TestFeature(std::string const & name, std::string const & lang);
TestFeature(m2::PointD const & center, std::string const & name, std::string const & lang);
TestFeature(vector<m2::PointD> const & boundary, std::string const & name,
TestFeature(std::vector<m2::PointD> const & boundary, std::string const & name,
std::string const & lang);
uint64_t const m_id;
m2::PointD const m_center;
vector<m2::PointD> const m_boundary;
std::vector<m2::PointD> const m_boundary;
Type const m_type;
std::string const m_name;
std::string const m_lang;
@ -120,8 +121,10 @@ class TestPOI : public TestFeature
public:
TestPOI(m2::PointD const & center, std::string const & name, std::string const & lang);
static std::pair<TestPOI, FeatureID> AddWithEditor(osm::Editor & editor, MwmSet::MwmId const & mwmId,
std::string const & enName, m2::PointD const & pt);
static std::pair<TestPOI, FeatureID> AddWithEditor(osm::Editor & editor,
MwmSet::MwmId const & mwmId,
std::string const & enName,
m2::PointD const & pt);
// TestFeature overrides:
void Serialize(FeatureBuilder1 & fb) const override;
@ -131,12 +134,25 @@ public:
inline void SetStreet(TestStreet const & street) { m_streetName = street.GetName(); }
inline void SetTypes(std::vector<std::vector<std::string>> const & types) { m_types = types; }
private:
protected:
std::string m_houseNumber;
std::string m_streetName;
std::vector<std::vector<std::string>> m_types;
};
class TestMultilingualPOI : public TestPOI
{
public:
TestMultilingualPOI(m2::PointD const & center, std::string const & defaultName,
std::map<std::string, std::string> const & multilingualNames);
// TestFeature overrides:
void Serialize(FeatureBuilder1 & fb) const override;
std::string ToString() const override;
private:
std::map<std::string, std::string> m_multilingualNames;
};
class TestBuilding : public TestFeature
{
public:

View file

@ -10,6 +10,7 @@
#include "indexer/city_boundary.hpp"
#include "indexer/data_header.hpp"
#include "indexer/feature_data.hpp"
#include "indexer/feature_meta.hpp"
#include "indexer/features_offsets_table.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "indexer/index_builder.hpp"
@ -23,6 +24,29 @@
#include "defines.hpp"
using namespace std;
namespace
{
bool WriteRegionDataForTests(string const & path, vector<string> const & languages)
{
try
{
FilesContainerW writer(path, FileWriter::OP_WRITE_EXISTING);
feature::RegionData regionData;
regionData.SetLanguages(languages);
FileWriter w = writer.GetWriter(REGION_INFO_FILE_TAG);
regionData.Serialize(w);
}
catch (Writer::Exception const & e)
{
LOG(LERROR, ("Error writing file:", e.Msg()));
return false;
}
return true;
}
} // namespace
namespace generator
{
namespace tests_support
@ -80,9 +104,14 @@ bool TestMwmBuilder::Add(FeatureBuilder1 & fb)
return true;
}
void TestMwmBuilder::SetMwmLanguages(vector<string> const & languages)
{
m_languages = languages;
}
void TestMwmBuilder::Finish()
{
std::string const tmpFilePath = m_collector->GetFilePath();
string const tmpFilePath = m_collector->GetFilePath();
CHECK(m_collector, ("Finish() already was called."));
m_collector.reset();
@ -95,7 +124,7 @@ void TestMwmBuilder::Finish()
CHECK(my::DeleteFileX(tmpFilePath), ());
std::string const path = m_file.GetPath(MapOptions::Map);
string const path = m_file.GetPath(MapOptions::Map);
(void)my::DeleteFileX(path + OSM2FEATURE_FILE_EXTENSION);
CHECK(feature::BuildOffsetsTable(path), ("Can't build feature offsets table."));
@ -113,6 +142,9 @@ void TestMwmBuilder::Finish()
CHECK(search::RankTableBuilder::CreateIfNotExists(path), ());
if (!m_languages.empty())
CHECK(WriteRegionDataForTests(path, m_languages), ());
m_file.SyncWithDisk();
}
} // namespace tests_support

View file

@ -5,6 +5,8 @@
#include "indexer/data_header.hpp"
#include <memory>
#include <string>
#include <vector>
namespace feature
{
@ -31,12 +33,14 @@ public:
void Add(TestFeature const & feature);
bool Add(FeatureBuilder1 & fb);
void SetMwmLanguages(std::vector<std::string> const & languages);
void Finish();
private:
platform::LocalCountryFile & m_file;
feature::DataHeader::MapType m_type;
std::vector<std::string> m_languages;
std::unique_ptr<feature::FeaturesCollector> m_collector;
TestIdToBoundariesTable m_boundariesTable;
};

View file

@ -1369,5 +1369,61 @@ UNIT_CLASS_TEST(ProcessorTest, PathsThroughLayers)
TEST(ResultsMatch("computing street ", {ruleStreet}), ());
}
}
UNIT_CLASS_TEST(ProcessorTest, SelectProperName)
{
string const countryName = "Wonderland";
auto testLanguage = [&](string language, string expectedRes) {
auto request = MakeRequest("cafe", language);
auto const & results = request->Results();
TEST_EQUAL(results.size(), 1, (results));
TEST_EQUAL(results[0].GetString(), expectedRes, (results));
};
TestMultilingualPOI cafe(
m2::PointD(0.0, 0.0), "Default",
{{"es", "Spanish"}, {"int_name", "International"}, {"fr", "French"}, {"ru", "Russian"}});
cafe.SetTypes({{"amenity", "cafe"}});
auto wonderlandId = BuildCountry(countryName, [&](TestMwmBuilder & builder) {
builder.Add(cafe);
builder.SetMwmLanguages({"it", "fr"});
});
SetViewport(m2::RectD(-1, -1, 1, 1));
// Language priorities:
// - device language
// - input language
// - default if mwm has device or input region
// - english and international
// - default
// Device language is English by default.
// No English(device) or Italian(query) name present but mwm has Italian region.
testLanguage("it", "Default");
// No English(device) name present. Mwm has French region but we should prefer explicit French
// name.
testLanguage("fr", "French");
// No English(device) name present. Use query language.
testLanguage("es", "Spanish");
// No English(device) or German(query) names present. Mwm does not have German region. We should
// use international name.
testLanguage("de", "International");
// Set Russian as device language.
m_engine.SetLocale("ru");
// Device language(Russian) is present and preferred for all queries.
testLanguage("it", "Russian");
testLanguage("fr", "Russian");
testLanguage("es", "Russian");
testLanguage("de", "Russian");
}
} // namespace
} // namespace search