Commit 249b0dd1 authored by Davis King's avatar Davis King

Added serialization support to constituent and parse_tree_element.

parent 47d118c1
......@@ -7,6 +7,7 @@
#include <vector>
#include <string>
#include <sstream>
#include "../serialize.h"
#include "../array2d.h"
namespace dlib
......@@ -22,8 +23,38 @@ namespace dlib
T right_tag;
};
template <typename T>
void serialize(
const constituent<T>& item,
std::ostream& out
)
{
serialize(item.begin, out);
serialize(item.end, out);
serialize(item.k, out);
serialize(item.left_tag, out);
serialize(item.right_tag, out);
}
template <typename T>
void deserialize(
constituent<T>& item,
std::istream& in
)
{
deserialize(item.begin, in);
deserialize(item.end, in);
deserialize(item.k, in);
deserialize(item.left_tag, in);
deserialize(item.right_tag, in);
}
// -----------------------------------------------------------------------------------------
const unsigned long END_OF_TREE = 0xFFFFFFFF;
// -----------------------------------------------------------------------------------------
template <typename T>
struct parse_tree_element
{
......@@ -35,6 +66,33 @@ namespace dlib
double score;
};
template <typename T>
void serialize (
const parse_tree_element<T>& item,
std::ostream& out
)
{
serialize(item.c, out);
serialize(item.tag, out);
serialize(item.left, out);
serialize(item.right, out);
serialize(item.score, out);
}
template <typename T>
void deserialize (
parse_tree_element<T>& item,
std::istream& in
)
{
deserialize(item.c, in);
deserialize(item.tag, in);
deserialize(item.left, in);
deserialize(item.right, in);
deserialize(item.score, in);
}
// -----------------------------------------------------------------------------------------
namespace impl
{
......
......@@ -24,11 +24,33 @@ namespace dlib
T right_tag;
};
template <typename T>
void serialize(
const constituent<T>& item,
std::ostream& out
);
/*!
provides serialization support
!*/
template <typename T>
void deserialize(
constituent<T>& item,
std::istream& in
);
/*!
provides deserialization support
!*/
// -----------------------------------------------------------------------------------------
/*!A END_OF_TREE is used to indicate that parse_tree_element::left or
parse_tree_element::right doesn't point to another subtree.
!*/
const unsigned long END_OF_TREE = 0xFFFFFFFF;
// -----------------------------------------------------------------------------------------
template <typename T>
struct parse_tree_element
{
......@@ -46,6 +68,24 @@ namespace dlib
double score; // score for this tree
};
template <typename T>
void serialize (
const parse_tree_element<T>& item,
std::ostream& out
);
/*!
provides serialization support
!*/
template <typename T>
void deserialize (
parse_tree_element<T>& item,
std::istream& in
);
/*!
provides deserialization support
!*/
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
......
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