Commit 898ad4df authored by Davis King's avatar Davis King

Made parse_trees_to_string() and parse_trees_to_string_tagged() a little more

user friendly.
parent 658a8182
...@@ -340,14 +340,14 @@ namespace dlib ...@@ -340,14 +340,14 @@ namespace dlib
std::string parse_trees_to_string ( std::string parse_trees_to_string (
const std::vector<parse_tree_element<T> >& tree, const std::vector<parse_tree_element<T> >& tree,
const std::vector<U>& words, const std::vector<U>& words,
const unsigned long root_idx = 0 const T& tag_to_skip
) )
{ {
if (root_idx >= tree.size()) if (tree.size() == 0)
return ""; return "";
std::ostringstream sout; std::ostringstream sout;
impl::print_parse_tree_helper<false,true>(tree, words, root_idx, tree[root_idx].tag, sout); impl::print_parse_tree_helper<false,true>(tree, words, 0, tag_to_skip, sout);
return sout.str(); return sout.str();
} }
...@@ -357,14 +357,14 @@ namespace dlib ...@@ -357,14 +357,14 @@ namespace dlib
std::string parse_trees_to_string_tagged ( std::string parse_trees_to_string_tagged (
const std::vector<parse_tree_element<T> >& tree, const std::vector<parse_tree_element<T> >& tree,
const std::vector<U>& words, const std::vector<U>& words,
const unsigned long root_idx = 0 const T& tag_to_skip
) )
{ {
if (root_idx >= tree.size()) if (tree.size() == 0)
return ""; return "";
std::ostringstream sout; std::ostringstream sout;
impl::print_parse_tree_helper<true,true>(tree, words, root_idx, tree[root_idx].tag, sout); impl::print_parse_tree_helper<true,true>(tree, words, 0, tag_to_skip, sout);
return sout.str(); return sout.str();
} }
......
...@@ -298,7 +298,7 @@ namespace dlib ...@@ -298,7 +298,7 @@ namespace dlib
std::string parse_trees_to_string ( std::string parse_trees_to_string (
const std::vector<parse_tree_element<T> >& tree, const std::vector<parse_tree_element<T> >& tree,
const std::vector<U>& words, const std::vector<U>& words,
const unsigned long root_idx = 0 const T& tag_to_skip
); );
/*! /*!
requires requires
...@@ -307,9 +307,9 @@ namespace dlib ...@@ -307,9 +307,9 @@ namespace dlib
ensures ensures
- This function behaves just like parse_tree_to_string() except that it will - This function behaves just like parse_tree_to_string() except that it will
not print the brackets (i.e. []) for the top most parts of the tree which not print the brackets (i.e. []) for the top most parts of the tree which
have tags equal to tree[root_idx].tag. It will however print all the words. have tags equal to tag_to_skip. It will however print all the words.
Therefore, this function only includes brackets on the subtrees which begin Therefore, this function only includes brackets on the subtrees which begin
with a tag other than tree[root_idx].tag. with a tag other than tag_to_skip.
throws throws
- parse_tree_to_string_error - parse_tree_to_string_error
This exception is thrown if an invalid tree is detected. This might happen This exception is thrown if an invalid tree is detected. This might happen
...@@ -326,7 +326,7 @@ namespace dlib ...@@ -326,7 +326,7 @@ namespace dlib
std::string parse_trees_to_string_tagged ( std::string parse_trees_to_string_tagged (
const std::vector<parse_tree_element<T> >& tree, const std::vector<parse_tree_element<T> >& tree,
const std::vector<U>& words, const std::vector<U>& words,
const unsigned long root_idx = 0 const T& tag_to_skip
); );
/*! /*!
requires requires
...@@ -336,9 +336,9 @@ namespace dlib ...@@ -336,9 +336,9 @@ namespace dlib
ensures ensures
- This function behaves just like parse_tree_to_string_tagged() except that it - This function behaves just like parse_tree_to_string_tagged() except that it
will not print the brackets (i.e. []) for the top most parts of the tree will not print the brackets (i.e. []) for the top most parts of the tree
which have tags equal to tree[root_idx].tag. It will however print all the which have tags equal to tag_to_skip. It will however print all the words.
words. Therefore, this function only includes brackets on the subtrees which Therefore, this function only includes brackets on the subtrees which begin
begin with a tag other than tree[root_idx].tag. with a tag other than tag_to_skip.
throws throws
- parse_tree_to_string_error - parse_tree_to_string_error
This exception is thrown if an invalid tree is detected. This might happen This exception is thrown if an invalid tree is detected. This might happen
......
...@@ -131,10 +131,10 @@ namespace ...@@ -131,10 +131,10 @@ namespace
const std::string str3 = "[[The flight] [includes [a meal]]] [[The flight] [includes [a meal]]]"; const std::string str3 = "[[The flight] [includes [a meal]]] [[The flight] [includes [a meal]]]";
const std::string str4 = "[5 [3 The flight] [4 includes [3 a meal]]] [5 [3 The flight] [4 includes [3 a meal]]]"; const std::string str4 = "[5 [3 The flight] [4 includes [3 a meal]]] [5 [3 The flight] [4 includes [3 a meal]]]";
dlog << LINFO << parse_trees_to_string(parse_tree, words); dlog << LINFO << parse_trees_to_string(parse_tree, words, G);
DLIB_TEST(parse_trees_to_string(parse_tree, words) == str3); DLIB_TEST(parse_trees_to_string(parse_tree, words, G) == str3);
dlog << LINFO << parse_trees_to_string_tagged(parse_tree, words); dlog << LINFO << parse_trees_to_string_tagged(parse_tree, words, G);
DLIB_TEST(parse_trees_to_string_tagged(parse_tree, words) == str4); DLIB_TEST(parse_trees_to_string_tagged(parse_tree, words, G) == str4);
sequence.clear(); sequence.clear();
find_max_parse_cky(sequence, user_defined_ruleset<true>, parse_tree); find_max_parse_cky(sequence, user_defined_ruleset<true>, parse_tree);
......
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