From 1d536e6cbcf8e0cbd1d24d9621b60b93b3ebbbd3 Mon Sep 17 00:00:00 2001 From: Alexis Nasr <alexis.nasr@lif.univ-mrs.fr> Date: Wed, 7 Feb 2018 16:36:26 +0100 Subject: [PATCH] fixed a bug in word.h --- CMakeLists.txt | 1 + maca_common/include/word.h | 2 +- maca_trans_parser/src/movements.c | 56 +++++++++---------- .../src/oracle_parser_arc_eager.c | 15 +++-- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c53a8c1..80f3d0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(macaon2) find_package(FLEX) find_package(BLAS) +find_package(DyNet) add_definitions("-Wall" ) SET(CMAKE_C_COMPILER g++) diff --git a/maca_common/include/word.h b/maca_common/include/word.h index 7e8f30b..51b9622 100644 --- a/maca_common/include/word.h +++ b/maca_common/include/word.h @@ -59,7 +59,7 @@ typedef struct _word { #define word_get_cpos(w) (((w) == NULL) ? -1 : (w)->wf_array[MCD_WF_CPOS]) #define word_get_pos(w) (((w) == NULL) ? -1 : (w)->wf_array[MCD_WF_POS]) #define word_get_feats(w) (((w) == NULL) ? -1 : (w)->wf_array[MCD_WF_FEATS]) -#define word_get_gov(w) (((w) == NULL) ? 0 : (w)->wf_array[MCD_WF_GOV]) +#define word_get_gov(w) (((w) == NULL) ? WORD_INVALID_GOV : (w)->wf_array[MCD_WF_GOV]) #define word_get_label(w) (((w) == NULL) ? -1 : (w)->wf_array[MCD_WF_LABEL]) #define word_get_stag(w) (((w) == NULL) ? -1 : (w)->wf_array[MCD_WF_STAG]) #define word_get_sent_seg(w) (((w) == NULL) ? 0 : (w)->wf_array[MCD_WF_SENT_SEG]) diff --git a/maca_trans_parser/src/movements.c b/maca_trans_parser/src/movements.c index 1107e79..6c2f280 100644 --- a/maca_trans_parser/src/movements.c +++ b/maca_trans_parser/src/movements.c @@ -4,33 +4,6 @@ #include"util.h" #include"movements.h" -int movement_eos(config *c, int movement_code) -{ - if(stack_is_empty(config_get_stack(c))) return 0; - word *s0 = stack_top(config_get_stack(c)); - - /* word on top of stack is already eos */ - if(word_get_sent_seg(s0) == 1) return 0; - - /* set word on the top of the stack to eos */ - word_set_sent_seg(s0, 1); - - config_push_mvt(c, movement_code, s0, NULL); - - return 1; -} - -int movement_eos_undo(config *c) -{ - word *gov = mvt_get_gov(mvt_stack_top(config_get_history(c))); - - /* word on the top of the stack is not eos anymore */ - word_set_sent_seg(gov, 0); - - mvt_free(config_pop_mvt(c)); - return 1; -} - int movement_left_arc(config *c, int movement_code, int label) { if(stack_is_empty(config_get_stack(c))) return 0; @@ -158,8 +131,9 @@ int movement_root(config *c, int movement_code, int root_code) s0->is_root = 1; /*---- ajout 19/12/17 ----------*/ - // word_set_sent_seg(word_buffer_get_word_n(config_get_buffer(c), s0->rspan), 1); + // word_set_sent_seg(word_buffer_get_word_n(config_get_buffer(c), s0->rspan), 1); /*-----------------------------*/ + stack_pop(config_get_stack(c)); config_push_mvt(c, movement_code, s0, NULL); @@ -179,6 +153,32 @@ int movement_root_undo(config *c) return 1; } +int movement_eos(config *c, int movement_code) +{ + if(stack_is_empty(config_get_stack(c))) return 0; + word *s0 = stack_top(config_get_stack(c)); + + /* word on top of stack is already eos */ + if(word_get_sent_seg(s0) == 1) return 0; + + /* set word on the top of the stack to eos */ + word_set_sent_seg(s0, 1); + stack_pop(config_get_stack(c)); + config_push_mvt(c, movement_code, s0, NULL); + return 1; +} + +int movement_eos_undo(config *c) +{ + word *gov = mvt_get_gov(mvt_stack_top(config_get_history(c))); + + /* word on the top of the stack is not eos anymore */ + word_set_sent_seg(gov, 0); + + mvt_free(config_pop_mvt(c)); + return 1; +} + int movement_add_pos(config *c, int movement_code, int pos) { if(word_buffer_b0(config_get_buffer(c)) == NULL) return 0; diff --git a/maca_trans_parser/src/oracle_parser_arc_eager.c b/maca_trans_parser/src/oracle_parser_arc_eager.c index 7a34fcd..e4aae78 100644 --- a/maca_trans_parser/src/oracle_parser_arc_eager.c +++ b/maca_trans_parser/src/oracle_parser_arc_eager.c @@ -61,17 +61,20 @@ int oracle_parser_arc_eager(config *c, word_buffer *ref, int root_label) printf("dans ref gov de b0 (%d) = %d\n", b0_index, b0_gov_index);*/ /* s0 is the root of the sentence */ - /* if((s0_label == root_label) - && check_all_dependents_of_word_in_ref_are_in_hyp(c, ref, s0_index) + if((s0_label == root_label) + // && (word_get_label(word_buffer_get_word_n(config_get_buffer(c), s0_index)) != root_label) + && check_all_dependents_of_word_in_ref_are_in_hyp(c, ref, s0_index) ){ return MVT_PARSER_ROOT; - }*/ - + } + /* word on the top of the stack is an end of sentence marker */ if((word_get_sent_seg(word_buffer_get_word_n(ref, s0_index)) == 1) - && (word_get_sent_seg(word_buffer_get_word_n(config_get_buffer(c), s0_index)) != 1)){ + // && (word_get_sent_seg(word_buffer_get_word_n(config_get_buffer(c), s0_index)) != 1) + && check_all_dependents_of_word_in_ref_are_in_hyp(c, ref, s0_index) + ){ return MVT_PARSER_EOS; - } + } /* LEFT ARC b0 is the governor and s0 the dependent */ if(s0_gov_index == b0_index){ return movement_parser_left_code(word_get_label(word_buffer_get_word_n(ref, s0_index))); -- GitLab