Handle special characters in JSON model dump. (#9474)
This commit is contained in:
@@ -398,11 +398,14 @@ class JsonGenerator : public TreeGenerator {
|
||||
static std::string const kIndicatorTemplate =
|
||||
R"ID( "nodeid": {nid}, "depth": {depth}, "split": "{fname}", "yes": {yes}, "no": {no})ID";
|
||||
auto split_index = tree[nid].SplitIndex();
|
||||
auto fname = fmap_.Name(split_index);
|
||||
std::string qfname; // quoted
|
||||
common::EscapeU8(fname, &qfname);
|
||||
auto result = SuperT::Match(
|
||||
kIndicatorTemplate,
|
||||
{{"{nid}", std::to_string(nid)},
|
||||
{"{depth}", std::to_string(depth)},
|
||||
{"{fname}", fmap_.Name(split_index)},
|
||||
{"{fname}", qfname},
|
||||
{"{yes}", std::to_string(nyes)},
|
||||
{"{no}", std::to_string(tree[nid].DefaultChild())}});
|
||||
return result;
|
||||
@@ -430,12 +433,14 @@ class JsonGenerator : public TreeGenerator {
|
||||
std::string const &template_str, std::string cond,
|
||||
uint32_t depth) const {
|
||||
auto split_index = tree[nid].SplitIndex();
|
||||
auto fname = split_index < fmap_.Size() ? fmap_.Name(split_index) : std::to_string(split_index);
|
||||
std::string qfname; // quoted
|
||||
common::EscapeU8(fname, &qfname);
|
||||
std::string const result = SuperT::Match(
|
||||
template_str,
|
||||
{{"{nid}", std::to_string(nid)},
|
||||
{"{depth}", std::to_string(depth)},
|
||||
{"{fname}", split_index < fmap_.Size() ? fmap_.Name(split_index) :
|
||||
std::to_string(split_index)},
|
||||
{"{fname}", qfname},
|
||||
{"{cond}", cond},
|
||||
{"{left}", std::to_string(tree[nid].LeftChild())},
|
||||
{"{right}", std::to_string(tree[nid].RightChild())},
|
||||
|
||||
Reference in New Issue
Block a user