forked from organicmaps/organicmaps
[classificator] Process synonym tags for needed types (atm=yes).
This commit is contained in:
parent
e64a982065
commit
1c4c8f43de
2 changed files with 98 additions and 6 deletions
|
@ -236,3 +236,66 @@ UNIT_TEST(OsmType_AlabamaRiver)
|
|||
TEST(params.IsTypeExist(GetType(arrT)), ());
|
||||
TEST_EQUAL(params.m_Types.size(), 1, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(OsmType_Synonims)
|
||||
{
|
||||
// Smoke test.
|
||||
{
|
||||
char const * arr[][2] = {
|
||||
{ "building", "yes" },
|
||||
{ "shop", "yes" },
|
||||
{ "atm", "yes" }
|
||||
};
|
||||
|
||||
XMLElement e;
|
||||
FillXmlElement(arr, ARRAY_SIZE(arr), &e);
|
||||
|
||||
FeatureParams params;
|
||||
ftype::GetNameAndType(&e, params);
|
||||
|
||||
char const * arrT1[] = { "building" };
|
||||
char const * arrT2[] = { "amenity", "atm" };
|
||||
char const * arrT3[] = { "shop" };
|
||||
TEST_EQUAL(params.m_Types.size(), 3, ());
|
||||
TEST(params.IsTypeExist(GetType(arrT1)), ());
|
||||
TEST(params.IsTypeExist(GetType(arrT2)), ());
|
||||
TEST(params.IsTypeExist(GetType(arrT3)), ());
|
||||
}
|
||||
|
||||
// Duplicating test.
|
||||
{
|
||||
char const * arr[][2] = {
|
||||
{ "amenity", "atm" },
|
||||
{ "atm", "yes" }
|
||||
};
|
||||
|
||||
XMLElement e;
|
||||
FillXmlElement(arr, ARRAY_SIZE(arr), &e);
|
||||
|
||||
FeatureParams params;
|
||||
ftype::GetNameAndType(&e, params);
|
||||
|
||||
char const * arrT[] = { "amenity", "atm" };
|
||||
TEST_EQUAL(params.m_Types.size(), 1, ());
|
||||
TEST(params.IsTypeExist(GetType(arrT)), ());
|
||||
}
|
||||
|
||||
// "NO" tag test.
|
||||
{
|
||||
char const * arr[][2] = {
|
||||
{ "building", "yes" },
|
||||
{ "shop", "no" },
|
||||
{ "atm", "no" }
|
||||
};
|
||||
|
||||
XMLElement e;
|
||||
FillXmlElement(arr, ARRAY_SIZE(arr), &e);
|
||||
|
||||
FeatureParams params;
|
||||
ftype::GetNameAndType(&e, params);
|
||||
|
||||
char const * arrT[] = { "building" };
|
||||
TEST_EQUAL(params.m_Types.size(), 1, ());
|
||||
TEST(params.IsTypeExist(GetType(arrT)), ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,8 +59,8 @@ namespace ftype
|
|||
{
|
||||
if (p->childs[i].name == "tag")
|
||||
{
|
||||
string const & k = p->childs[i].attrs["k"];
|
||||
string const & v = p->childs[i].attrs["v"];
|
||||
string & k = p->childs[i].attrs["k"];
|
||||
string & v = p->childs[i].attrs["v"];
|
||||
|
||||
if (k.empty() || is_skip_tag(k))
|
||||
continue;
|
||||
|
@ -70,7 +70,8 @@ namespace ftype
|
|||
continue;
|
||||
|
||||
res = toDo(k, v);
|
||||
if (res) return res;
|
||||
if (res)
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
@ -144,7 +145,8 @@ namespace ftype
|
|||
{
|
||||
++m_count;
|
||||
|
||||
if (v.empty()) return false;
|
||||
if (v.empty())
|
||||
return false;
|
||||
|
||||
// get name with language suffix
|
||||
string lang;
|
||||
|
@ -223,7 +225,8 @@ namespace ftype
|
|||
if (is_good_tag(k, v))
|
||||
{
|
||||
ClassifObjectPtr p = m_parent->BinaryFind(m_isKey ? k : v);
|
||||
if (p) return p;
|
||||
if (p)
|
||||
return p;
|
||||
}
|
||||
return ClassifObjectPtr(0, 0);
|
||||
}
|
||||
|
@ -256,13 +259,32 @@ namespace ftype
|
|||
|
||||
// now try to match correspondent value
|
||||
p = do_find_obj(p.get(), false)(k, v);
|
||||
if (p) m_path.push_back(p);
|
||||
if (p)
|
||||
m_path.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
return (!m_path.empty() ? m_path.back() : ClassifObjectPtr(0, 0));
|
||||
}
|
||||
};
|
||||
|
||||
/// Process synonim tags to match existing classificator types.
|
||||
/// @todo We are planning to rewrite classificator <-> tags matching.
|
||||
class do_replace_synonims
|
||||
{
|
||||
public:
|
||||
typedef bool result_type;
|
||||
|
||||
bool operator() (string & k, string & v) const
|
||||
{
|
||||
if (k == "atm" && v == "yes")
|
||||
{
|
||||
k = "amenity";
|
||||
v = "atm";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ClassifObjectPtr find_object(ClassifObject const * parent, XMLElement * p, bool isKey)
|
||||
|
@ -277,6 +299,11 @@ namespace ftype
|
|||
return count;
|
||||
}
|
||||
|
||||
void process_synonims(XMLElement * p)
|
||||
{
|
||||
for_each_tag(p, do_replace_synonims());
|
||||
}
|
||||
|
||||
//#ifdef DEBUG
|
||||
// class debug_find_string
|
||||
// {
|
||||
|
@ -324,6 +351,8 @@ namespace ftype
|
|||
if (process_common_params(p, params) == 0)
|
||||
return;
|
||||
|
||||
process_synonims(p);
|
||||
|
||||
set<string> skipRootKeys;
|
||||
|
||||
do
|
||||
|
|
Loading…
Add table
Reference in a new issue