treebank.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:word2vec-keras-in-gensim 作者: niitsuma 项目源码 文件源码
def trees2label_sents(trees,only_root=False,pos_neg_label=False,remove_double_count_sentence=False):
    #print 'trees2label_sents',flag_word_lower,flag_stemmer,flag_remove_double_count_sentence,only_root,pos_neg_label
    #sys.exit()
    lss=[]
    for tree in trees:
        lss_tmp=tree2label_sent(tree)
        if pos_neg_label and lss_tmp[0][0] == 2 :
            continue
        if pos_neg_label :
            lss_tmp2 = [ [1 if ls[0] > 2 else 0  ,ls[1]] for ls in lss_tmp]
        else:
            lss_tmp2 =lss_tmp
        if len(lss_tmp2) > 0 and only_root:
            lss.append(lss_tmp2[0])
        elif len(lss_tmp2) > 0:
            lss.extend(lss_tmp2)
    if remove_double_count_sentence :
        uss=label_sents2uni_sent(lss)
        lss_new =[[np.mean([lss[id][0] for id in uss[s]]),lss[uss[s][0]][1] ] for s in uss ]
        return lss_new
    else:
        return lss
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号