本文整理汇总了Python中Node.Node.edge_label_方法的典型用法代码示例。如果您正苦于以下问题:Python Node.edge_label_方法的具体用法?Python Node.edge_label_怎么用?Python Node.edge_label_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.edge_label_方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revise_node
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import edge_label_ [as 别名]
def revise_node(content, amr_nodes_con, amr_nodes_acr):
m = re.search('\w+\s/\s\S+\s+(.+)', content.replace('\n', ''))
if m != None and \
' / name' not in content and \
':polarity -' not in content:
arg_nodes = list()
acr = re.search('\w+\s/\s\S+', content).group().split(' / ')[0]
nodes = re.findall('\S+\s\".+\"|\S+\s\S+', m.group(1))
for i in nodes:
i = re.search('(:\S+)\s(.+)', i)
role = i.group(1)
concept = i.group(2).strip(')')
if concept in amr_nodes_acr:
node = copy.copy(amr_nodes_acr[concept])
node.next_ = list()
else: # in case of (d / date-entity :year 2012)
node = Node(name=concept)
amr_nodes_acr[concept] = node
node.edge_label_ = role
arg_nodes.append(node)
amr_nodes_acr[acr].next_ = arg_nodes
amr_nodes_con[content].next_ = arg_nodes
示例2: generate_nodes_multiple
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import edge_label_ [as 别名]
def generate_nodes_multiple(content, amr_nodes_con, amr_nodes_acr):
assert content.count('(') > 1 and content.count(')') > 1
assert content.count('(') == content.count(')')
content_key = content # Key of dict() 'amr_nodes_con'
arg_nodes = list()
is_named_entity = False
is_polarity = False
'''
remove existing nodes from the content, and link those
nodes to the root of subtree
'''
for i in sorted(amr_nodes_con, key=len, reverse=True):
if i in content:
e = content.find(i)
s = content[:e].rfind(':')
role = re.search(':\S+\s', content[s:e]).group() # Edge label
content = content.replace(role+i, '', 1)
amr_nodes_con[i].edge_label_ = role.strip()
if ':name' in role:
is_named_entity = True
ne = amr_nodes_con[i]
else:
arg_nodes.append(amr_nodes_con[i])
predict_event = re.search('\w+\s/\s\S+', content).group().split(' / ')
acr = predict_event[0] # Acronym
ful = predict_event[1] # Full name
### In case of :polarity -
if re.search(":polarity\s-", content) != None:
is_polarity = True
nodes = re.findall(':\S+\s\S+', content)
for i in nodes:
i = re.search('(:\S+)\s(\S+)', i)
role = i.group(1)
concept = i.group(2).strip(')')
if role == ':wiki' and is_named_entity:
continue
if role == ':polarity':
continue
if concept in amr_nodes_acr:
node = copy.copy(amr_nodes_acr[concept])
node.next_ = list()
else: # In case of (d / date-entity :year 2012)
node = Node(name=concept)
amr_nodes_acr[concept] = node
node.edge_label_ = role
arg_nodes.append(node)
'''
Named entity is a special node, so the subtree of a
named entity will be merged. For example,
(p / person :wiki -
:name (n / name
:op1 "Pascale"))
will be consider as one node.
According to AMR Specification, "we fill the :instance
slot from a special list of standard AMR named entity types".
Thus, for named entity node, we will use entity type
(p / person in the example above) instead of :instance
'''
if is_named_entity:
### Find Wikipedia title:
wikititle = ''
if re.match('.+:wiki\s-.*', content) != None:
wikititle = '-' # Entity is NIL, Wiki title does not exist
else:
m = re.search(':wiki\s\"(.+?)\"', content)
if m != None:
wikititle = m.group(1) # Wiki title
else:
wikititle = '' # There is no Wiki title information
new_node = Node(name=acr, ful_name=ful, next_node=arg_nodes,
edge_label=ne.ful_name_, is_entity=True,
entity_type=ful, entity_name=ne.entity_name_,
wiki=wikititle, polarity=is_polarity)
amr_nodes_con[content_key] = new_node
amr_nodes_acr[acr] = new_node
elif len(arg_nodes) > 0:
new_node = Node(name=acr, ful_name=ful, next_node=arg_nodes,
polarity=is_polarity)
amr_nodes_con[content_key] = new_node
amr_nodes_acr[acr] = new_node