[classificator] Added admin level value for “place-city-capital” type (2-11).

This commit is contained in:
vng 2015-07-02 21:01:47 +03:00 committed by Alex Zolotarev
parent 0d1f958216
commit a58b1927cd
10 changed files with 3903 additions and 45 deletions

View file

@ -507,7 +507,18 @@ world +
{}
place +
city +
capital -
capital +
10 -
11 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
{}
{}
continent -
country -

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -994,3 +994,13 @@ shop|sports;[shop=sports];;name;int_name;993;
route|ferry|motor_vehicle;[route=ferry];;name;int_name;994;
railway|rail|motor_vehicle;[railway=rail];;name;int_name;995;
hwtag|nofoot;[hwtag=nofoot];;name;int_name;996;
place|city|capital|2;[place=city][capital=2];;name;int_name;997;
place|city|capital|3;[place=city][capital=3];;name;int_name;998;
place|city|capital|4;[place=city][capital=4];;name;int_name;999;
place|city|capital|5;[place=city][capital=5];;name;int_name;1000;
place|city|capital|6;[place=city][capital=6];;name;int_name;1001;
place|city|capital|7;[place=city][capital=7];;name;int_name;1002;
place|city|capital|8;[place=city][capital=8];;name;int_name;1003;
place|city|capital|9;[place=city][capital=9];;name;int_name;1004;
place|city|capital|10;[place=city][capital=10];;name;int_name;1005;
place|city|capital|11;[place=city][capital=11];;name;int_name;1006;

Can't render this file because it has a wrong number of fields in line 371.

View file

@ -994,3 +994,13 @@ shop|sports
route|ferry|motor_vehicle
railway|rail|motor_vehicle
hwtag|nofoot
place|city|capital|2
place|city|capital|3
place|city|capital|4
place|city|capital|5
place|city|capital|6
place|city|capital|7
place|city|capital|8
place|city|capital|9
place|city|capital|10
place|city|capital|11

View file

@ -507,7 +507,18 @@ world 00000000000000000000 +
{}
place 00000000000000000000 +
city 00000111111111110000 +
capital 00001111111111110000 -
capital 00001111111111110000 +
10 00000111111111110000 -
11 00000111111111110000 -
2 00000111111111110000 -
3 00000111111111110000 -
4 00000111111111110000 -
5 00000111111111110000 -
6 00000111111111110000 -
7 00000111111111110000 -
8 00000111111111110000 -
9 00000111111111110000 -
{}
{}
continent 11100000000000000000 -
country 00011111110000000000 -

View file

@ -306,8 +306,9 @@ UNIT_TEST(OsmType_Capital)
{
{
char const * arr[][2] = {
{ "admin_level", "6" },
{ "capital", "yes" },
{ "place", "city" },
{ "capital", "yes" }
};
XMLElement e;
@ -317,13 +318,14 @@ UNIT_TEST(OsmType_Capital)
ftype::GetNameAndType(&e, params);
TEST_EQUAL(params.m_Types.size(), 1, (params));
TEST(params.IsTypeExist(GetType({"place", "city", "capital"})), ());
TEST(params.IsTypeExist(GetType({"place", "city", "capital", "6"})), ());
}
{
char const * arr[][2] = {
{ "admin_level", "6" },
{ "capital", "no" },
{ "place", "city" },
{ "capital", "6" }
};
XMLElement e;
@ -335,6 +337,25 @@ UNIT_TEST(OsmType_Capital)
TEST_EQUAL(params.m_Types.size(), 1, (params));
TEST(params.IsTypeExist(GetType({"place", "city"})), ());
}
{
char const * arr[][2] = {
{ "admin_level", "6" },
{ "boundary", "administrative" },
{ "capital", "2" },
{ "place", "city" },
};
XMLElement e;
FillXmlElement(arr, ARRAY_SIZE(arr), &e);
FeatureParams params;
ftype::GetNameAndType(&e, params);
TEST_EQUAL(params.m_Types.size(), 2, (params));
TEST(params.IsTypeExist(GetType({"place", "city", "capital", "2"})), ());
TEST(params.IsTypeExist(GetType({"boundary", "administrative", "6"})), ());
}
}
UNIT_TEST(OsmType_Route)

View file

@ -235,25 +235,13 @@ namespace ftype
if (is_name_tag(k))
return false;
// Filter 3rd component of type here.
if (m_isKey)
if (!m_isKey)
{
/// @todo Probably, we need to filter most keys like == "yes" here,
/// but need to carefully investigate the classificator.
// Grab only "capital == yes" and skip all other capitals.
if (k == "capital")
return (get_mark_value(k, v) == 1);
// Take numbers only for "capital" and "admin_level".
int dummy;
if (strings::to_int(v, dummy))
return (k == "admin_level" || k == "capital");
}
else
{
// Numbers are used in boundary-administrative-X types.
// Take only "admin_level" tags to avoid grabbing any other trash numbers.
uint64_t dummy;
if (strings::to_uint64(v, dummy))
return (k == "admin_level");
}
return true;
}
@ -262,26 +250,27 @@ namespace ftype
ClassifObjectPtr operator() (string const & k, string const & v) const
{
if (!is_good_tag(k, v))
return ClassifObjectPtr(0, 0);
return m_parent->BinaryFind(m_isKey ? k : v);
return (is_good_tag(k, v) ? m_parent->BinaryFind(m_isKey ? k : v) : ClassifObjectPtr(0, 0));
}
};
typedef vector<ClassifObjectPtr> path_type;
class do_find_root_obj
class do_find_key_value_obj
{
ClassifObject const * m_parent;
path_type & m_path;
public:
explicit do_find_root_obj(path_type & path) : m_path(path) {}
do_find_key_value_obj(ClassifObject const * p, path_type & path)
: m_parent(p), m_path(path)
{
}
bool operator() (string const & k, string const & v)
{
// first try to match key
ClassifObjectPtr p = do_find_obj(classif().GetRoot(), true)(k, v);
ClassifObjectPtr p = do_find_obj(m_parent, true)(k, v);
if (p)
{
m_path.push_back(p);
@ -332,14 +321,6 @@ namespace ftype
};
}
ClassifObjectPtr find_object(ClassifObject const * parent, XMLElement * p, set<int> & skipRows)
{
// next objects trying to find by value first
ClassifObjectPtr pObj = for_each_tag_ex<ClassifObjectPtr>(p, do_find_obj(parent, false), skipRows);
// if no - try find object by key (in case of k = "area", v = "yes")
return pObj ? pObj : for_each_tag_ex<ClassifObjectPtr>(p, do_find_obj(parent, true), skipRows);
}
size_t ProcessCommonParams(XMLElement * p, FeatureParams & params)
{
size_t count;
@ -425,21 +406,35 @@ namespace ftype
return;
set<int> skipRows;
ClassifObject const * root = classif().GetRoot();
do
{
path_type path;
// find first root object by key
do_find_root_obj doFindRoot(path);
for_each_tag_ex<bool>(p, doFindRoot, skipRows);
if (path.empty())
if (!for_each_tag_ex<bool>(p, do_find_key_value_obj(root, path), skipRows))
break;
CHECK(!path.empty(), ());
// continue find path from last element
ClassifObjectPtr pObj;
while ((pObj = find_object(path.back().get(), p, skipRows)))
path.push_back(pObj);
do
{
// continue find path from last element
ClassifObject const * parent = path.back().get();
// next objects trying to find by value first
ClassifObjectPtr pObj = for_each_tag_ex<ClassifObjectPtr>(p, do_find_obj(parent, false), skipRows);
if (pObj)
{
path.push_back(pObj);
}
else
{
// if no - try find object by key (in case of k = "area", v = "yes")
if (!for_each_tag_ex<bool>(p, do_find_key_value_obj(parent, path), skipRows))
break;
}
} while (true);
// assign type
uint32_t t = ftype::GetEmptyValue();