Made parse_trees_to_string() and parse_trees_to_string_tagged() a little more

user friendly.
This commit is contained in:
Davis King 2012-11-21 10:03:26 -05:00
parent 658a818256
commit 898ad4df70
3 changed files with 17 additions and 17 deletions

View File

@ -340,14 +340,14 @@ namespace dlib
std::string parse_trees_to_string (
const std::vector<parse_tree_element<T> >& tree,
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 "";
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();
}
@ -357,14 +357,14 @@ namespace dlib
std::string parse_trees_to_string_tagged (
const std::vector<parse_tree_element<T> >& tree,
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 "";
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();
}

View File

@ -298,7 +298,7 @@ namespace dlib
std::string parse_trees_to_string (
const std::vector<parse_tree_element<T> >& tree,
const std::vector<U>& words,
const unsigned long root_idx = 0
const T& tag_to_skip
);
/*!
requires
@ -307,9 +307,9 @@ namespace dlib
ensures
- 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
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
with a tag other than tree[root_idx].tag.
with a tag other than tag_to_skip.
throws
- parse_tree_to_string_error
This exception is thrown if an invalid tree is detected. This might happen
@ -326,7 +326,7 @@ namespace dlib
std::string parse_trees_to_string_tagged (
const std::vector<parse_tree_element<T> >& tree,
const std::vector<U>& words,
const unsigned long root_idx = 0
const T& tag_to_skip
);
/*!
requires
@ -336,9 +336,9 @@ namespace dlib
ensures
- 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
which have tags equal to tree[root_idx].tag. It will however print all the
words. Therefore, this function only includes brackets on the subtrees which
begin with a tag other than tree[root_idx].tag.
which 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
with a tag other than tag_to_skip.
throws
- parse_tree_to_string_error
This exception is thrown if an invalid tree is detected. This might happen

View File

@ -131,10 +131,10 @@ namespace
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]]]";
dlog << LINFO << parse_trees_to_string(parse_tree, words);
DLIB_TEST(parse_trees_to_string(parse_tree, words) == str3);
dlog << LINFO << parse_trees_to_string_tagged(parse_tree, words);
DLIB_TEST(parse_trees_to_string_tagged(parse_tree, words) == str4);
dlog << LINFO << parse_trees_to_string(parse_tree, words, G);
DLIB_TEST(parse_trees_to_string(parse_tree, words, G) == str3);
dlog << LINFO << parse_trees_to_string_tagged(parse_tree, words, G);
DLIB_TEST(parse_trees_to_string_tagged(parse_tree, words, G) == str4);
sequence.clear();
find_max_parse_cky(sequence, user_defined_ruleset<true>, parse_tree);