• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python syntax_tree.Syntax_tree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中syntax_tree.Syntax_tree的典型用法代码示例。如果您正苦于以下问题:Python Syntax_tree类的具体用法?Python Syntax_tree怎么用?Python Syntax_tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Syntax_tree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_prev_curr_production_rule

def get_prev_curr_production_rule(arg_clauses, clause_index, parse_dict):
    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index
    curr_clause_indices = arg_clauses.clauses[clause_index][0]# ([1,2,3],yes)
    if clause_index > 0:
        prev_clause_index = clause_index - 1
        curr_clause_indices = arg_clauses.clauses[prev_clause_index][0] + curr_clause_indices

    subtrees = []
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    if syntax_tree.tree != None:
        clause_leaves = set([syntax_tree.get_leaf_node_by_token_index(index) for index in curr_clause_indices])
        no_need = []
        for node in syntax_tree.tree.traverse(strategy="levelorder"):
            if node not in no_need:
                if set(node.get_leaves()) <= clause_leaves:
                    subtrees.append(node)
                    no_need.extend(node.get_descendants())

    production_rule = []
    for tree in subtrees:
        for node in tree.traverse(strategy="levelorder"):
            if not node.is_leaf():
                rule = node.name + "-->" + " ".join([child.name for child in node.get_children()])
                production_rule.append(rule)

    return production_rule
开发者ID:CoderChang,项目名称:conll2015_discourse,代码行数:28,代码来源:implicit_arg2_dict_util.py


示例2: _get_constituents

def _get_constituents(parse_dict, connective):
    DocID = connective.DocID
    sent_index = connective.sent_index
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    if syntax_tree.tree == None:
        return []

    conn_indices = connective.token_indices
    constituent_nodes = []
    if len(conn_indices) == 1:# like and or so...
        conn_node = syntax_tree.get_leaf_node_by_token_index(conn_indices[0]).up
    else:
        conn_node = syntax_tree.get_common_ancestor_by_token_indices(conn_indices)
        conn_leaves = set([syntax_tree.get_leaf_node_by_token_index(conn_index) for conn_index in conn_indices])
        children = conn_node.get_children()
        for child in children:
            leaves = set(child.get_leaves())
            if conn_leaves & leaves == set([]):
                constituent_nodes.append(child)

    curr = conn_node
    while not curr.is_root():
        constituent_nodes.extend(syntax_tree.get_siblings(curr))
        curr = curr.up

    # obtain the Constituent object according to the node.
    constituents = []
    for node in constituent_nodes:
        cons = Constituent(syntax_tree, node)
        cons.connective = connective
        constituents.append(cons)
    return constituents
开发者ID:peeceeprashant,项目名称:SharedTask,代码行数:33,代码来源:position_classifier.py


示例3: get_Arg_production_rules

def get_Arg_production_rules(relation, Arg, doc):
    #1.  dict[sent_index] = [token_list]
    dict = {}
    Arg_TokenList = get_Arg_TokenList(relation, Arg)
    for sent_index, word_index in Arg_TokenList:
        if sent_index not in dict:
            dict[sent_index] = [word_index]
        else:
            dict[sent_index].append(word_index)

    #2. production_rules
    Arg_subtrees = []
    for sent_index in dict.keys():
        parse_tree = doc["sentences"][sent_index]["parsetree"].strip()
        syntax_tree = Syntax_tree(parse_tree)
        if syntax_tree.tree != None:
            Arg_indices = dict[sent_index]
            Arg_leaves = set([syntax_tree.get_leaf_node_by_token_index(index) for index in Arg_indices])
            Arg_leaves_labels = set([leaf.label() for leaf in Arg_leaves])
            for nodeposition in syntax_tree.tree.treepositions():
                node = syntax_tree.tree[nodeposition]
                if set(node.leaves()) <= Arg_leaves_labels:
                    Arg_subtrees.append(node)

    production_rules = []
    for node in Arg_subtrees:
        if not isinstance(node, str):
            rule = node.label() + '-->' + ' '.join([child.label() for child in node])
            production_rules.append(rule)

    production_rules = list(set(production_rules))
    return production_rules
开发者ID:CoderChang,项目名称:nlp_project,代码行数:32,代码来源:conn_util.py


示例4: get_self_category

def get_self_category(parse_dict, DocID, sent_index, conn_indices):
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        self_category = "NONE_TREE"
    else:
        self_category = syntax_tree.get_self_category_node_by_token_indices(conn_indices).name

    return self_category
开发者ID:StevenLOL,项目名称:conll2015_discourse,代码行数:10,代码来源:NT_dict_util.py


示例5: get_conn_parent_categoryCtx

def get_conn_parent_categoryCtx(parse_dict, DocID, sent_index, conn_indices):
    conn_name = get_conn_name(parse_dict, DocID, sent_index, conn_indices)

    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    if syntax_tree.tree == None:
        parent_categoryCtx = "NONE_TREE"
    else:
        parent_category_node = syntax_tree.get_parent_category_node_by_token_indices(conn_indices)
        parent_categoryCtx = get_node_linked_Ctx(parent_category_node)

    conn_parent_categoryCtx = "%s|%s" % (conn_name, parent_categoryCtx)

    return conn_parent_categoryCtx
开发者ID:StevenLOL,项目名称:conll2015_discourse,代码行数:14,代码来源:NT_dict_util.py


示例6: get_conn_connCtx

def get_conn_connCtx(parse_dict,docID,sentID,conn_indices,conn_words):
    parse_tree = parse_dict[docID]["sentences"][sentID]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    # conn + connCtx
    if syntax_tree.tree == None:
        connCtx = "NONE_TREE"
    else:
        conn_node = syntax_tree.get_self_category_node_by_token_indices(conn_indices)
        connCtx = get_node_Ctx(conn_node, syntax_tree)

    #conn_connCtx = "%s|%s" % (conn_name, connCtx)
    conn_connCtx ='_'.join(conn_words)+'-'+connCtx
    return conn_connCtx
开发者ID:peeceeprashant,项目名称:SharedTask,代码行数:14,代码来源:func.py


示例7: get_conn_leftSibling_ctx

def get_conn_leftSibling_ctx(parse_dict, DocID, sent_index, conn_indices):
    conn_name = get_C_String(parse_dict, DocID, sent_index, conn_indices)

    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        leftSiblingCtx = "NONE_TREE"
    else:
        leftSibling_node = syntax_tree.get_left_sibling_category_node_by_token_indices(conn_indices)
        leftSiblingCtx = get_node_linked_Ctx(leftSibling_node, syntax_tree)

    conn_leftSiblingCtx = "%s|%s" % (conn_name, leftSiblingCtx)

    return conn_leftSiblingCtx
开发者ID:StevenLOL,项目名称:conll2015_discourse,代码行数:15,代码来源:exp_dict_util.py


示例8: get_CParent_to_root_path_node_names

def get_CParent_to_root_path_node_names(parse_dict,docID,sentID,conn_indices):
    parse_tree = parse_dict[docID]["sentences"][sentID]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        path = "NONE_TREE"
    else:
        path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
            conn_parent_node = conn_node.up
            path += syntax_tree.get_node_path_to_root(conn_parent_node) + "-->"
        if path[-3:] == "-->":
            path = path[:-3]
    return path.split("-->")
开发者ID:peeceeprashant,项目名称:SharedTask,代码行数:15,代码来源:func.py


示例9: get_conn_to_root_path

def get_conn_to_root_path(parse_dict,docID,sentID,conn_indices):
    parse_tree = parse_dict[docID]["sentences"][sentID]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    if syntax_tree.tree == None:
        path = "NONE_TREE"
    else:
        path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
            t = syntax_tree.get_node_path_to_root(conn_node)
            path += t + "&"
        if path[-1] == "&":
            path = path[:-1]

    return path
开发者ID:peeceeprashant,项目名称:SharedTask,代码行数:15,代码来源:func.py


示例10: ssArgumentExt

def ssArgumentExt(inputFilenamePath):
 parse_file = codecs.open(inputFilenamePath+'/parses.json', encoding='utf8');
 en_parse_dict = json.load(parse_file);
 i = 0;
 for prediction in observedArray:
  filename = bigDiction[i][2];
  sentenceNumber = int(bigDiction[i+1][3]) + 1;
  connWordID = int(bigDiction[i][4]);
  print "ConnWordID: " + str(connWordID);
  parse_tree = en_parse_dict[filename]["sentences"][sentenceNumber]["parsetree"].strip();
  syntax_tree = Syntax_tree(parse_tree)
  if syntax_tree.tree == None:
   return []
  #Get Connective Indices
  conn_indices = [connWordID];
  constituent_nodes = [];
  if len(conn_indices) == 1:# like and or so...
        conn_node = syntax_tree.get_leaf_node_by_token_index(conn_indices[0]).up
  else:
        conn_node = syntax_tree.get_common_ancestor_by_token_indices(conn_indices)
        conn_leaves = set([syntax_tree.get_leaf_node_by_token_index(conn_index) for conn_index in conn_indices])
        children = conn_node.get_children()
        for child in children:
            leaves = set(child.get_leaves())
            if conn_leaves & leaves == set([]):
                constituent_nodes.append(child)
  
  curr = conn_node
  while not curr.is_root():
   constituent_nodes.extend(syntax_tree.get_siblings(curr))
   curr = curr.up

  # obtain the Constituent object according to the node.
  constituents = []
  for node in constituent_nodes:
   cons = Constituent(syntax_tree, node)
   #print "Object Type: " + str(cons.type());
   #print "Object Dir: " + str(cons.dir());
   #print "Object id: " + str(cons.id());
   #print "cons: " + str(cons.connective);
   connective = Connective(filename, sentenceNumber, conn_indices, "text");
   cons.connective = connective
   constituents.append(cons)
  i = i + 1;
  print "Connective ID:" + str(connWordID); 
  print "Size of Observed Array: " + str(len(observedArray));
  print "Size of Constituents Array: " + str(len(constituents)); 
开发者ID:peeceeprashant,项目名称:SharedTask,代码行数:47,代码来源:curr_pc.py


示例11: get_conn_to_root_compressed_path

def get_conn_to_root_compressed_path(parse_dict,docID,sentID,conn_indices):
    parse_tree = parse_dict[docID]["sentences"][sentID]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    if syntax_tree.tree == None:
        compressed_path = "NONE_TREE"
    else:
        compressed_path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
	    conn_parent_node = conn_node.up
	    path = syntax_tree.get_node_path_to_root(conn_parent_node)
	    compressed_path += util.get_compressed_path(path) + "&"
            #t = syntax_tree.get_node_path_to_root(conn_node)
            #path += t + "&"
        if compressed_path[-1] == "&":
            compressed_path = compressed_path[:-1]
    return compressed_path
开发者ID:peeceeprashant,项目名称:SharedTask,代码行数:17,代码来源:func.py


示例12: get_CParent_to_root_path

def get_CParent_to_root_path(parse_dict, DocID, sent_index, conn_indices):
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    ''' c parent to root '''
    if syntax_tree.tree == None:
        cparent_to_root_path = "NONE_TREE"
    else:
        cparent_to_root_path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
            conn_parent_node = conn_node.up
            cparent_to_root_path += syntax_tree.get_node_path_to_root(conn_parent_node) + "&"
        if cparent_to_root_path[-1] == "&":
            cparent_to_root_path = cparent_to_root_path[:-1]

    return cparent_to_root_path
开发者ID:StevenLOL,项目名称:conll2015_discourse,代码行数:17,代码来源:NT_dict_util.py


示例13: get_curr_first_prev_last_parse_path

def get_curr_first_prev_last_parse_path(arg_clauses, clause_index, parse_dict):
    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index

    if clause_index - 1 < 0:
        return "NONE"

    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    curr_first_index = arg_clauses.clauses[clause_index][0][0]
    prev_last_index = arg_clauses.clauses[clause_index - 1][0][-1]

    curr_first_node = syntax_tree.get_leaf_node_by_token_index(curr_first_index)
    prev_last_node = syntax_tree.get_leaf_node_by_token_index(prev_last_index)

    return syntax_tree.get_node_to_node_path(curr_first_node, prev_last_node)
开发者ID:alishir,项目名称:conll2015_discourse,代码行数:17,代码来源:ps_arg2_dict_util.py


示例14: get_conn_to_root_path

def get_conn_to_root_path(arg_clauses, clause_index, parse_dict):
    conn_indices = arg_clauses.conn_indices
    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)
    if syntax_tree.tree == None:
        path = "NONE_TREE"
    else:
        path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
            t = syntax_tree.get_node_path_to_root(conn_node)
            path += t + "&"
        if path[-1] == "&":
            path = path[:-1]

    return path
开发者ID:alishir,项目名称:conll2015_discourse,代码行数:18,代码来源:ps_arg2_dict_util.py


示例15: get_conn_parent_category_Ctx

def get_conn_parent_category_Ctx(arg_clauses, clause_index, parse_dict):
    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index
    conn_indices = arg_clauses.conn_indices

    conn_name = get_con_str(arg_clauses, clause_index, parse_dict)

    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        parent_categoryCtx = "NONE_TREE"
    else:
        parent_category_node = syntax_tree.get_parent_category_node_by_token_indices(conn_indices)
        parent_categoryCtx = get_node_linked_Ctx(parent_category_node, syntax_tree)

    conn_parent_categoryCtx = "%s|%s" % (conn_name, parent_categoryCtx)

    return conn_parent_categoryCtx
开发者ID:alishir,项目名称:conll2015_discourse,代码行数:19,代码来源:ps_arg2_dict_util.py


示例16: get_CParent_to_root_path_node_names

def get_CParent_to_root_path_node_names(arg_clauses, clause_index, parse_dict):
    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index
    conn_indices = arg_clauses.conn_indices

    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        path = "NONE_TREE"
    else:
        path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
            conn_parent_node = conn_node.up
            path += syntax_tree.get_node_path_to_root(conn_parent_node) + "-->"
        if path[-3:] == "-->":
            path = path[:-3]

    return path.split("-->")
开发者ID:alishir,项目名称:conll2015_discourse,代码行数:20,代码来源:ps_arg2_dict_util.py


示例17: get_curr_first_to_prev_last_path

def get_curr_first_to_prev_last_path(arg_clauses, clause_index, parse_dict):
    if clause_index == 0:
        return "NULL"

    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        return "NOTREE"

    curr_first_index = arg_clauses.clauses[clause_index][0][0]
    prev_last_index = arg_clauses.clauses[clause_index - 1][0][-1]

    curr_first_node = syntax_tree.get_leaf_node_by_token_index(curr_first_index).up
    prev_last_node = syntax_tree.get_leaf_node_by_token_index(prev_last_index).up

    path = syntax_tree.get_node_to_node_path(curr_first_node, prev_last_node)

    return path
开发者ID:CoderChang,项目名称:conll2015_discourse,代码行数:21,代码来源:implicit_arg2_dict_util.py


示例18: get_conn_to_root_compressed_path

def get_conn_to_root_compressed_path(arg_clauses, clause_index, parse_dict):
    DocID = arg_clauses.DocID
    sent_index = arg_clauses.sent_index
    conn_indices = arg_clauses.conn_indices
    parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
    syntax_tree = Syntax_tree(parse_tree)

    if syntax_tree.tree == None:
        compressed_path = "NONE_TREE"
    else:
        compressed_path = ""
        for conn_index in conn_indices:
            conn_node = syntax_tree.get_leaf_node_by_token_index(conn_index)
            conn_parent_node = conn_node.up

            path = syntax_tree.get_node_path_to_root(conn_parent_node)

            compressed_path += util.get_compressed_path(path) + "&"

        if compressed_path[-1] == "&":
            compressed_path = compressed_path[:-1]
    return compressed_path
开发者ID:alishir,项目名称:conll2015_discourse,代码行数:22,代码来源:ps_arg2_dict_util.py


示例19: getProductionRules

    def getProductionRules(self, clause):
        curr_clause_indices = clause# ([1,2,3],yes)

        subtrees = []
        parse_tree = self.parseTree
        syntax_tree = Syntax_tree(parse_tree)
        if syntax_tree.tree != None:
            clause_leaves = set([syntax_tree.get_leaf_node_by_token_index(index) for index in curr_clause_indices])
            no_need = []
            for node in syntax_tree.tree.traverse(strategy="levelorder"):
                if node not in no_need:
                    if set(node.get_leaves()) <= clause_leaves:
                        subtrees.append(node)
                        no_need.extend(node.get_descendants())

        production_rule = []
        for tree in subtrees:
            for node in tree.traverse(strategy="levelorder"):
                if not node.is_leaf():
                    rule = node.name + "-->" + " ".join([child.name for child in node.get_children()])
                    production_rule.append(rule)

        return production_rule
开发者ID:saurabhc123,项目名称:SharedTask,代码行数:23,代码来源:Clause.py


示例20: get_Arg_production_rules

def get_Arg_production_rules(relation, Arg, parse_dict):
    #1.  dict[(DocID, sent_index)] = [token_list]
    dict = {}
    DocID = relation["DocID"]
    Arg_TokenList = get_Arg_TokenList(relation, Arg)
    for sent_index, word_index in Arg_TokenList:
        if (DocID, sent_index) not in dict:
            dict[(DocID, sent_index)] = [word_index]
        else:
            dict[(DocID, sent_index)].append(word_index)

    #2.
    Arg_subtrees = []
    for (DocID, sent_index) in dict.keys():
        parse_tree = parse_dict[DocID]["sentences"][sent_index]["parsetree"].strip()
        syntax_tree = Syntax_tree(parse_tree)
        if syntax_tree.tree != None:
            Arg_indices = dict[(DocID, sent_index) ]
            Arg_leaves = set([syntax_tree.get_leaf_node_by_token_index(index) for index in Arg_indices])

            no_need = []
            for node in syntax_tree.tree.traverse(strategy="levelorder"):
                if node not in no_need:
                    if set(node.get_leaves()) <= Arg_leaves:
                        Arg_subtrees.append(node)
                        no_need.extend(node.get_descendants())


    production_rule = []
    for tree in Arg_subtrees:
        for node in tree.traverse(strategy="levelorder"):
            if not node.is_leaf():
                rule = node.name + "-->" + " ".join([child.name for child in node.get_children()])
                production_rule.append(rule)

    return production_rule
开发者ID:CoderChang,项目名称:conll2015_discourse,代码行数:36,代码来源:non_exp_dict_util.py



注:本文中的syntax_tree.Syntax_tree类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python syntax_visitor.SyntaxVisitor类代码示例发布时间:2022-05-27
下一篇:
Python utils.render_to_string函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap