ZGen  0.2.0
a linearization system for natural language.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
span.h
Go to the documentation of this file.
1 #ifndef __ZGEN_BESTFIRST_SPAN_H__
2 #define __ZGEN_BESTFIRST_SPAN_H__
3 
4 #include <bitset>
5 #include "settings.h"
6 #include "types/instance.h"
7 
8 namespace ZGen {
9 
10 namespace BestFirst {
11 
12 // Span is flexiable, memory statable.
13 struct Span {
14  Span();
15 
24  void init(const dependency_t* ref,
25  int root_id,
26  postag_t tag);
27 
28 
34  void copy(const Span *other);
35 
36 
41  void clear();
42 
43 
50  bool complete();
51 
52 
59  bool link_left(const Span *modifier);
60 
61 
68  bool link_right(const Span *modifier);
69 
75  void repr(std::string& s) const;
76 
78  friend std::ostream& operator << (std::ostream& os, const Span& span);
79 
80  bool initialized;
81  const dependency_t* ref;
82  int root_id;
85  std::vector<const Span *> left_spans;
87  std::vector<const Span *> right_spans;
89  std::bitset<kMaxNumberOfWords> used_words;
91 };
92 
94  bool operator () (const Span* lhs, const Span* rhs) const {
95  return lhs->score > rhs->score;
96  }
97 };
98 
99 struct SpanPtrLess {
100  bool operator () (const Span* lhs, const Span* rhs) const {
101  return lhs->score < rhs->score;
102  }
103 };
104 
105 struct SpanPtrEqual {
106  bool operator () (const Span* x, const Span* y) const {
107  std::string xrepr; xrepr.reserve(512); x->repr(xrepr);
108  std::string yrepr; yrepr.reserve(512); y->repr(yrepr);
109 
110  return xrepr == yrepr;
111  }
112 };
113 
114 struct SpanPtrHash {
115  size_t operator () (const Span* x) const {
116  std::string xrepr; xrepr.reserve(512); x->repr(xrepr);
117  return boost::hash_value<std::string>(xrepr);
118  }
119 };
120 
121 } // end for namespace Bestfirst
122 
123 } // end for namespace ZGen
124 
125 #endif // end for __ZGEN_BESTFIRST_SPAN_H__
Definition: span.h:105
void repr(std::string &s) const
Definition: span.cc:82
bool complete()
Definition: span.cc:48
bool link_left(const Span *modifier)
Definition: span.cc:59
postag_t tag
Definition: span.h:83
bool initialized
Definition: span.h:80
Definition: instance.h:18
bool operator()(const Span *lhs, const Span *rhs) const
Definition: span.h:94
void copy(const Span *other)
Definition: span.cc:25
Definition: span.h:114
size_t operator()(const Span *x) const
Definition: span.h:115
void clear()
Definition: span.cc:36
void init(const dependency_t *ref, int root_id, postag_t tag)
Definition: span.cc:14
double floatval_t
Definition: settings.h:24
Definition: span.h:93
bool operator()(const Span *lhs, const Span *rhs) const
Definition: span.h:100
std::vector< const Span * > right_spans
Definition: span.h:87
std::vector< const Span * > left_spans
Definition: span.h:85
bool operator()(const Span *x, const Span *y) const
Definition: span.h:106
int postag_t
Definition: instance.h:12
Definition: span.h:99
bool link_right(const Span *modifier)
Definition: span.cc:70
friend std::ostream & operator<<(std::ostream &os, const Span &span)
Definition: span.cc:102
Span()
Definition: span.cc:8
Definition: span.h:13
floatval_t score
Definition: span.h:84
int root_id
Definition: span.h:82
const dependency_t * ref
Definition: span.h:81
std::bitset< kMaxNumberOfWords > used_words
Definition: span.h:89