1 #ifndef SEMSPEAR_TREE_H_
2 #define SEMSPEAR_TREE_H_
17 #include <boost/make_shared.hpp>
25 class Semantic_step_proposal;
38 typedef boost::shared_ptr<Semspear_tree>
Self_ptr;
51 typedef std::map<Lexicon_db::Val_type, bool>
LF_map_t;
72 const bool& learn =
true,
73 const bool& collins =
false
85 const bool& learn =
true,
86 const bool& collins =
false
94 const bool& learn =
true,
95 const bool& collins =
false
107 const bool& learn =
false
119 Word word()
const {
if(word_ != NULL)
return *word_;
else return Word();}
125 if(label_ != NULL)
return *label_;
133 if(head_ == children_.end())
return Self_ptr();
167 bool is_terminal()
const {
return children_.empty() && word_ != NULL;}
219 is_coord_ = new_value;
252 rebuild_events_recursively(NULL,
this);
257 if(event_ != NULL) event_ -> release_view_counts();
258 if(sem_event_ != NULL) sem_event_ -> release_view_counts();
261 children_.begin(), children_.end(),
268 if(event_ != NULL) event_->reacquire_view_counts();
269 if(sem_event_ != NULL) sem_event_->reacquire_view_counts();
277 children_.begin(), children_.end(),
294 bool is_head =
false,
302 bool is_head =
false,
348 static boost::shared_ptr<Freq_map> wfm(
new Freq_map());
357 Child_list::iterator head_iterator()
364 Child_list::reverse_iterator head_riterator()
366 return std::reverse_iterator<Child_list::iterator>(head_);
376 double resample_semantic_move(
383 double evaluate_reverse_move(
385 const bool tree_is_altered
406 void update_local_event(
409 const int& dist_code,
423 void update_semantic_context(
437 void update_semantic_association
440 bool resample_step_codes =
true
449 void rebuild_events_recursively(
452 const int& dist_code = 0,
453 bool punc_flag =
false,
455 bool coord_flag =
false,
469 template<
typename Iter>
470 void update_events_in_child_range(
473 const int& dist_base,
495 template<
typename Iter>
496 static kjb::Vector propose_associations_in_child_range(
521 const bool tree_is_altered
530 bool contains_verb()
const;
534 bool should_be_npb()
const;
538 void prune_unnecessary_nodes();
546 void insert_npb_parents();
550 void raise_punctuation(
552 Child_list::iterator begin,
553 Child_list::iterator end
558 void mark_coordinated_phrase_children();
565 Child_list::iterator head_;
583 boost::tuple<Semspear_tree::Self_ptr, kjb::Vector>
592 template<
typename Iter>
593 void Semspear_tree::update_events_in_child_range(
596 const int& dist_base,
601 bool adjacent_to_head =
true;
602 bool has_intervening_verb =
false;
603 bool next_punc_flag =
false;
605 bool next_coord_flag =
false;
607 int dist = dist_base + 10*adjacent_to_head + 1*has_intervening_verb;
608 for(Iter it = start; it != end; it++)
610 if(*it ==
head())
continue;
612 rebuild_events_recursively(
625 adjacent_to_head =
false;
626 next_punc_flag =
false;
628 next_coord_flag =
false;
633 adjacent_to_head =
true;
634 has_intervening_verb =
false;
635 }
else if((*it) -> contains_verb())
637 has_intervening_verb =
true;
640 assert((*it) ->
word() != 0);
641 assert((*it) ->
label() != 0);
642 next_punc_flag =
true;
646 next_coord_flag =
true;
650 dist = dist_base + 10*adjacent_to_head + 1*has_intervening_verb;
656 template<
typename Iter>
657 kjb::Vector Semspear_tree::propose_associations_in_child_range(
658 const Self_ptr source,
660 Iter source_child_start,
661 Iter source_child_end,
662 Iter dest_child_start,
664 const bool tree_is_altered
668 Result result(0.0, 0.0);
670 Iter s_it = source_child_start, d_it = dest_child_start;
672 s_it != source_child_end && d_it != dest_child_end;
675 if((*s_it) == source->head() || (*s_it)->is_punctuation())
continue;
676 (*d_it)->update_semantic_context(
677 dest->semantic_codes(),
681 Semspear_tree::propose_new_associations(
683 source->semantic_node_,
684 dest->semantic_node_,
687 if(dest->is_base_np_)
void update_event_views_recursively()
Definition: Semspear_tree.cpp:538
boost::shared_ptr< Syntactic_event > Event_ptr
Definition: Syntactic_event.h:27
void set_label(const Label &label)
assign a new value to the label field
Definition: Semspear_tree.cpp:374
friend boost::tuple< Self_ptr, kjb::Vector > propose_new_tree(const Self_ptr source)
Definition: Semspear_tree.cpp:70
bool is_coordination() const
is this a coordinating conjunction?
Definition: Semspear_tree.h:175
void preprocess_tree()
do some preprocessing in accordance with Collins' model
Definition: Semspear_tree.cpp:1033
const Hash_pair & semantic_codes() const
get the pair of semantic codes at the root of this subtree
Definition: Semspear_tree.h:155
Role
Definition: Semspear_tree.h:55
boost::shared_ptr< Semspear_tree > Self_ptr
Definition: Semspear_tree.h:38
void set_semantic_data(const Elab_ptr_const semantic_parent, const Step_code_t &step_code)
set semantic data for this node
Definition: Semspear_tree.cpp:410
Word head_word() const
get the head word for this subtree
Definition: Semspear_tree.cpp:330
friend void resample_event_tables(Self_ptr &source)
Definition: Semspear_tree.cpp:87
boost::shared_ptr< Word > Word_ptr
Definition: Semspear_tree.h:40
std::list< Self_ptr > Child_list
Definition: Semspear_tree.h:43
std::list< Token_map::Key_type > Symbol_list
Definition: Semspear_tree.h:53
Definition: Semspear_tree.h:55
static LF_map_t & lf_word_map()
accessor to a global map flagging low frequency words
Definition: Event_parser.h:93
Label head_tag() const
get the head tag for this subtree
Definition: Semspear_tree.cpp:339
boost::shared_ptr< Elaboration_tree > Sem_tree_ptr
Definition: Semspear_tree.h:47
The main syntactic tree object for semantic parsing.
Definition: Semspear_tree.h:32
Definition: Semspear_tree.h:55
void set_coord(const bool new_value)
set the coordinated phrase flag
Definition: Semspear_tree.h:217
void initialize_special_symbols()
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Elab_ptr_const semantic_root() const
get a pointer to the root of the associated semantic tree
Definition: Semspear_tree.cpp:350
Semantic_elaboration::Self_ptr Elab_ptr
Definition: Elaboration_tree.h:33
Definition: Semspear_tree.h:55
boost::tuple< Semspear_tree::Self_ptr, kjb::Vector > propose_new_tree(const Semspear_tree::Self_ptr source)
Definition: Semspear_tree.cpp:70
Semspear_tree(const Role &role, const bool &learn=true, const bool &collins=false)
default constructor, creates an empty tree
Definition: Semspear_tree.cpp:182
double dist(const pt a, const pt b)
compute approx. Great Circle distance between two UTM points
Definition: layer.cpp:45
Value_type Label_type
Definition: Tree_event.h:39
Step_code::Code Step_code_t
Definition: SemanticIO.h:73
~Semspear_tree()
decrements word count when destructed (if learn_ is true)
Definition: Semspear_tree.cpp:304
void set_role(const Role &role)
set the syntactic role of this node
Definition: Semspear_tree.h:213
Syntactic_event::Word_type Word
Definition: Semspear_tree.h:39
Syntactic_event::Node_data Node_data
Definition: Semspear_tree.h:46
void add_child(const Self_ptr &new_child, bool on_left=false)
append a new child subtree
Definition: Semspear_tree.cpp:318
void reacquire_event_counts()
Definition: Semspear_tree.h:266
void set_semantic_tree(const Sem_tree_ptr new_tree)
associate this syntactic tree w/ a new semantic tree
Definition: Semspear_tree.cpp:397
Syntactic_event::Label_type Label
Definition: Semspear_tree.h:41
static Freq_map & word_freq_map()
return a reference to the map indexing actual word frequencies
Definition: Semspear_tree.h:346
const Child_list & children() const
returns the list of children
Definition: Semspear_tree.h:139
Semantic_step_proposal::Elab_ptr_const Elab_ptr_const
Definition: Semantic_step_proposal.cpp:35
void set_head(const Child_list::const_iterator head)
assign a new head and acquire its info
Definition: Semspear_tree.cpp:384
boost::shared_ptr< Label > Label_ptr
Definition: Semspear_tree.h:42
void release_event_counts()
Definition: Semspear_tree.h:255
void print_constituency_tree(std::ostream &os, bool is_head=false, int indent_level=0) const
print as constituency tree (marking head)
Definition: Semspear_tree.cpp:676
double node_log_probability() const
compute log prob of this node by itself
Definition: Semspear_tree.cpp:626
boost::shared_ptr< Semantic_step_event > Event_ptr
Definition: Semantic_step_event.h:18
Elaboration_tree::Elab_ptr Elab_ptr
Definition: Semspear_tree.h:48
static Nonterminal_db & nt_lexicon()
return a reference to the underlying nonterminal lexicon
Definition: Semspear_tree.cpp:309
Definition: Lexicon_db.h:17
std::map< Word, size_t > Freq_map
Definition: Semspear_tree.h:52
static Lexicon_db & lexicon()
return a reference to the underlying terminal lexicon
Definition: Semspear_tree.h:334
friend void initialize_special_symbols()
Syntactic_event::Event_ptr Syn_event_ptr
Definition: Semspear_tree.h:44
void set_word(const Word &word)
assign a new value to the word field
Definition: Semspear_tree.cpp:360
const Syn_event_ptr syntactic_event() const
returns a pointer to the probabilistic event at the root
Definition: Semspear_tree.h:159
#define dest(triedge, pointptr)
Definition: triangle.c:938
void print_events_with_probabilities(std::ostream &os) const
print events and associated log probabilities
Definition: Semspear_tree.cpp:778
double subtree_log_probability() const
compute log prob of this tree according to events
Definition: Semspear_tree.cpp:633
Semantic_step_event::Event_ptr Sem_event_ptr
Definition: Semspear_tree.h:45
void print_dependency_tree(std::ostream &os, bool is_head=false, int indent_level=0) const
display as dependency tree
Definition: Semspear_tree.cpp:714
Elaboration_tree::Hash_pair Hash_pair
Definition: Semspear_tree.h:50
const Self_ptr head() const
returns a pointer to the head subtree
Definition: Semspear_tree.h:131
bool is_terminal() const
is this subtree a leaf?
Definition: Semspear_tree.h:167
Definition: Semspear_tree.h:55
Label label() const
returns the label field
Definition: Semspear_tree.h:123
Definition: Semspear_tree.h:55
void complete_tree()
signals that tree is fully built, and to process data
Definition: Semspear_tree.h:249
void reacquire_event_counts_recursively()
Definition: Semspear_tree.h:273
void print_subtree_view_counts(std::ostream &os) const
print count info at each node
Definition: Semspear_tree.cpp:760
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
Word word() const
Definition: Semspear_tree.h:119
Definition: Semspear_tree.h:55
static Lexicon_db & lexicon()
Definition: Tree_event.cpp:20
Semantic_data_base::Hash_pair Hash_pair
Definition: Elaboration_tree.h:32
Elaboration_tree::Elab_ptr_const Elab_ptr_const
Definition: Semspear_tree.h:49
Definition: Nonterminal_db.h:16
Semantic_elaboration::Self_ptr_const Elab_ptr_const
Definition: Elaboration_tree.h:34
Code
Definition: SemanticIO.h:54
static LF_map_t & lf_word_map()
return a reference to the map indexing whether words are rare
Definition: Semspear_tree.h:342
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void resample_event_tables(std::vector< Semspear_tree::Self_ptr > &trees)
Definition: sample_associations.cpp:89
Definition: Semspear_tree.h:55
bool is_punctuation() const
is this a punctuation node?
Definition: Semspear_tree.h:171
Value_type Word_type
Definition: Tree_event.h:37
static bool VERBOSE
should debugging messages be printed?
Definition: Semspear_tree.h:59
std::map< Lexicon_db::Val_type, bool > LF_map_t
Definition: Semspear_tree.h:51