def when_prev_connPOS(parse_dict, DocID, sent_index, conn_indices):
    # load dict
    dict_when_prev_connPOS = Explicit_dict().dict_when_prev_connPOS
    # feature
    when_prev_connPOS = dict_util.get_when_prev_connPOS(parse_dict, DocID, sent_index, conn_indices)

    return get_feature_by_feat(dict_when_prev_connPOS, when_prev_connPOS)
Ejemplo n.º 2
0
def when_prev_connPOS(parse_dict, DocID, sent_index, conn_indices):
    # load dict
    dict_when_prev_connPOS = Explicit_dict().dict_when_prev_connPOS
    # feature
    when_prev_connPOS = dict_util.get_when_prev_connPOS(
        parse_dict, DocID, sent_index, conn_indices)

    return get_feature_by_feat(dict_when_prev_connPOS, when_prev_connPOS)
Ejemplo n.º 3
0
def all_features(parse_dict, connective):
    ''' feat dict '''
    feat_dict_CString = {}
    feat_dict_CPOS = {}
    feat_dict_C_Prev = {}
    ''' load dict '''
    dict_CString = Explicit_dict().dict_CString
    dict_CPOS = Explicit_dict().dict_CPOS
    dict_C_Prev = Explicit_dict().dict_C_Prev
    dict_CLString = Explicit_dict().dict_CLString
    '''Pitler'''
    self_category_dict = Explicit_dict().self_category_dict
    parent_category_dict = Explicit_dict().parent_category_dict
    left_sibling_category_dict = Explicit_dict().left_sibling_category_dict
    right_sibling_category_dict = Explicit_dict().right_sibling_category_dict
    ''' conn_syn '''
    conn_self_category_dict = Explicit_dict().conn_self_category_dict
    conn_parent_category_dict = Explicit_dict().conn_parent_category_dict
    conn_left_sibling_category_dict = Explicit_dict(
    ).conn_left_sibling_category_dict
    conn_right_sibling_category_dict = Explicit_dict(
    ).conn_right_sibling_category_dict
    ''' syn-syn'''
    self_parent_dict = Explicit_dict().self_parent_dict
    self_right_dict = Explicit_dict().self_right_dict
    self_left_dict = Explicit_dict().self_left_dict
    parent_left_dict = Explicit_dict().parent_left_dict
    parent_right_dict = Explicit_dict().parent_right_dict
    left_right_dict = Explicit_dict().left_right_dict
    ''' mine '''
    dict_conn_parent_category_ctx = Explicit_dict(
    ).dict_conn_parent_category_ctx
    dict_as_prev_conn = Explicit_dict().dict_as_prev_conn
    dict_as_prev_connPOS = Explicit_dict().dict_as_prev_connPOS

    dict_when_prev_conn = Explicit_dict().dict_when_prev_conn
    dict_when_prev_connPOS = Explicit_dict().dict_when_prev_connPOS
    ''' feature '''
    DocID = connective.DocID
    sent_index = connective.sent_index
    conn_indices = connective.token_indices

    CString = dict_util.get_C_String(parse_dict, DocID, sent_index,
                                     conn_indices)
    CPOS = dict_util.get_CPOS(parse_dict, DocID, sent_index, conn_indices)
    prev = dict_util.get_prev1(parse_dict, DocID, sent_index, conn_indices)
    C_Prev = "%s|%s" % (CString, prev)
    CLString = CString.lower()

    # syntax tree
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip(
    )
    syntax_tree = Syntax_tree(parse_tree)
    #pitler
    self_category = dict_util.get_self_category(syntax_tree, conn_indices)
    parent_category = dict_util.get_parent_category(syntax_tree, conn_indices)
    left_sibling_category = dict_util.get_left_sibling_category(
        syntax_tree, conn_indices)
    right_sibling_category = dict_util.get_right_sibling_category(
        syntax_tree, conn_indices)
    #conn - syn
    conn_name = CLString
    conn_self_category = "%s|%s" % (conn_name, self_category)
    conn_parent_category = "%s|%s" % (conn_name, parent_category)
    conn_left_sibling_category = "%s|%s" % (conn_name, left_sibling_category)
    conn_right_sibling_category = "%s|%s" % (conn_name, right_sibling_category)

    #syn-syn
    self_parent = "%s|%s" % (self_category, parent_category)
    self_right = "%s|%s" % (self_category, right_sibling_category)
    self_left = "%s|%s" % (self_category, left_sibling_category)
    parent_left = "%s|%s" % (parent_category, left_sibling_category)
    parent_right = "%s|%s" % (parent_category, right_sibling_category)
    left_right = "%s|%s" % (left_sibling_category, right_sibling_category)
    ''' mine '''
    conn_parent_category_ctx = dict_util.get_conn_parent_category_Ctx(
        parse_dict, DocID, sent_index, conn_indices)
    as_prev_conn = dict_util.get_as_prev_conn(parse_dict, DocID, sent_index,
                                              conn_indices)
    as_prev_connPOS = dict_util.get_as_prev_connPOS(parse_dict, DocID,
                                                    sent_index, conn_indices)

    when_prev_conn = dict_util.get_when_prev_conn(parse_dict, DocID,
                                                  sent_index, conn_indices)
    when_prev_connPOS = dict_util.get_when_prev_connPOS(
        parse_dict, DocID, sent_index, conn_indices)

    features = []
    features.append(get_feature(feat_dict_CString, dict_CString, CString))
    features.append(get_feature(feat_dict_CPOS, dict_CPOS, CPOS))
    features.append(get_feature(feat_dict_C_Prev, dict_C_Prev, C_Prev))
    features.append(get_feature({}, dict_CLString, CLString))

    features.append(get_feature({}, self_category_dict, self_category))
    features.append(get_feature({}, parent_category_dict, parent_category))
    features.append(
        get_feature({}, left_sibling_category_dict, left_sibling_category))
    features.append(
        get_feature({}, right_sibling_category_dict, right_sibling_category))

    features.append(
        get_feature({}, conn_self_category_dict, conn_self_category))
    features.append(
        get_feature({}, conn_parent_category_dict, conn_parent_category))
    features.append(
        get_feature({}, conn_left_sibling_category_dict,
                    conn_left_sibling_category))
    features.append(
        get_feature({}, conn_right_sibling_category_dict,
                    conn_right_sibling_category))

    features.append(get_feature({}, self_parent_dict, self_parent))
    features.append(get_feature({}, self_right_dict, self_right))
    features.append(get_feature({}, self_left_dict, self_left))
    features.append(get_feature({}, parent_left_dict, parent_left))
    features.append(get_feature({}, parent_right_dict, parent_right))
    features.append(get_feature({}, left_right_dict, left_right))
    ''' mine '''
    features.append(
        get_feature_by_feat(dict_conn_parent_category_ctx,
                            conn_parent_category_ctx))
    features.append(get_feature_by_feat(dict_as_prev_conn, as_prev_conn))
    features.append(get_feature_by_feat(dict_as_prev_connPOS, as_prev_connPOS))

    features.append(get_feature_by_feat(dict_when_prev_conn, when_prev_conn))
    features.append(
        get_feature_by_feat(dict_when_prev_connPOS, when_prev_connPOS))

    return util.mergeFeatures(features)
def all_features(parse_dict, connective):
    ''' feat dict '''
    feat_dict_CString = {}
    feat_dict_CPOS = {}
    feat_dict_C_Prev = {}


    ''' load dict '''
    dict_CString = Explicit_dict().dict_CString
    dict_CPOS = Explicit_dict().dict_CPOS
    dict_C_Prev = Explicit_dict().dict_C_Prev
    dict_CLString = Explicit_dict().dict_CLString

    '''Pitler'''
    self_category_dict = Explicit_dict().self_category_dict
    parent_category_dict = Explicit_dict().parent_category_dict
    left_sibling_category_dict = Explicit_dict().left_sibling_category_dict
    right_sibling_category_dict = Explicit_dict().right_sibling_category_dict
    ''' conn_syn '''
    conn_self_category_dict = Explicit_dict().conn_self_category_dict
    conn_parent_category_dict = Explicit_dict().conn_parent_category_dict
    conn_left_sibling_category_dict = Explicit_dict().conn_left_sibling_category_dict
    conn_right_sibling_category_dict = Explicit_dict().conn_right_sibling_category_dict
    ''' syn-syn'''
    self_parent_dict = Explicit_dict().self_parent_dict
    self_right_dict = Explicit_dict().self_right_dict
    self_left_dict = Explicit_dict().self_left_dict
    parent_left_dict = Explicit_dict().parent_left_dict
    parent_right_dict = Explicit_dict().parent_right_dict
    left_right_dict = Explicit_dict().left_right_dict

    ''' mine '''
    dict_conn_parent_category_ctx = Explicit_dict().dict_conn_parent_category_ctx
    dict_as_prev_conn = Explicit_dict().dict_as_prev_conn
    dict_as_prev_connPOS = Explicit_dict().dict_as_prev_connPOS

    dict_when_prev_conn = Explicit_dict().dict_when_prev_conn
    dict_when_prev_connPOS = Explicit_dict().dict_when_prev_connPOS


    ''' feature '''
    DocID = connective.DocID
    sent_index = connective.sent_index
    conn_indices = connective.token_indices

    CString = dict_util.get_C_String(parse_dict, DocID, sent_index, conn_indices)
    CPOS = dict_util.get_CPOS(parse_dict, DocID, sent_index, conn_indices)
    prev = dict_util.get_prev1(parse_dict, DocID, sent_index, conn_indices)
    C_Prev = "%s|%s" % (CString, prev)
    CLString = CString.lower()

    # syntax tree
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    #pitler
    self_category = dict_util.get_self_category(syntax_tree, conn_indices)
    parent_category = dict_util.get_parent_category(syntax_tree, conn_indices)
    left_sibling_category = dict_util.get_left_sibling_category(syntax_tree, conn_indices)
    right_sibling_category = dict_util.get_right_sibling_category(syntax_tree, conn_indices)
    #conn - syn
    conn_name = CLString
    conn_self_category = "%s|%s" % (conn_name, self_category)
    conn_parent_category = "%s|%s" % (conn_name, parent_category)
    conn_left_sibling_category = "%s|%s" % (conn_name, left_sibling_category)
    conn_right_sibling_category = "%s|%s" % (conn_name, right_sibling_category)

    #syn-syn
    self_parent = "%s|%s" % (self_category, parent_category)
    self_right = "%s|%s" % (self_category, right_sibling_category)
    self_left = "%s|%s" % (self_category, left_sibling_category)
    parent_left = "%s|%s" % (parent_category, left_sibling_category)
    parent_right = "%s|%s" % (parent_category, right_sibling_category)
    left_right = "%s|%s" % (left_sibling_category, right_sibling_category)

    ''' mine '''
    conn_parent_category_ctx = dict_util.get_conn_parent_category_Ctx(parse_dict, DocID, sent_index, conn_indices)
    as_prev_conn = dict_util.get_as_prev_conn(parse_dict, DocID, sent_index, conn_indices)
    as_prev_connPOS = dict_util.get_as_prev_connPOS(parse_dict, DocID, sent_index, conn_indices)

    when_prev_conn = dict_util.get_when_prev_conn(parse_dict, DocID, sent_index, conn_indices)
    when_prev_connPOS = dict_util.get_when_prev_connPOS(parse_dict, DocID, sent_index, conn_indices)


    features = []
    features.append(get_feature(feat_dict_CString, dict_CString , CString))
    features.append(get_feature(feat_dict_CPOS, dict_CPOS , CPOS))
    features.append(get_feature(feat_dict_C_Prev, dict_C_Prev , C_Prev))
    features.append(get_feature({}, dict_CLString , CLString))


    features.append(get_feature({}, self_category_dict , self_category))
    features.append(get_feature({}, parent_category_dict , parent_category))
    features.append(get_feature({}, left_sibling_category_dict , left_sibling_category))
    features.append(get_feature({}, right_sibling_category_dict , right_sibling_category))


    features.append(get_feature({}, conn_self_category_dict , conn_self_category))
    features.append(get_feature({}, conn_parent_category_dict , conn_parent_category))
    features.append(get_feature({}, conn_left_sibling_category_dict , conn_left_sibling_category))
    features.append(get_feature({}, conn_right_sibling_category_dict , conn_right_sibling_category))

    features.append(get_feature({}, self_parent_dict, self_parent))
    features.append(get_feature({}, self_right_dict, self_right ))
    features.append(get_feature({}, self_left_dict, self_left))
    features.append(get_feature({}, parent_left_dict, parent_left))
    features.append(get_feature({}, parent_right_dict, parent_right))
    features.append(get_feature({}, left_right_dict, left_right))

    ''' mine '''
    features.append(get_feature_by_feat(dict_conn_parent_category_ctx, conn_parent_category_ctx))
    features.append(get_feature_by_feat(dict_as_prev_conn, as_prev_conn))
    features.append(get_feature_by_feat(dict_as_prev_connPOS, as_prev_connPOS))

    features.append(get_feature_by_feat(dict_when_prev_conn, when_prev_conn))
    features.append(get_feature_by_feat(dict_when_prev_connPOS, when_prev_connPOS))


    return util.mergeFeatures(features)