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

Python featstruct.unify函数代码示例

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

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



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

示例1: apply

    def apply(self, chart, grammar, left_edge, right_edge):
        # Make sure the rule is applicable.
        if not (left_edge.end() == right_edge.start() and
                left_edge.is_incomplete() and
                right_edge.is_complete() and
                isinstance(left_edge, FeatureTreeEdge)):
            return
        found = right_edge.lhs()
        nextsym = left_edge.nextsym()
        if isinstance(right_edge, FeatureTreeEdge):
            if not is_nonterminal(nextsym): return
            if left_edge.nextsym()[TYPE] != right_edge.lhs()[TYPE]: return
            # Create a copy of the bindings.
            bindings = left_edge.bindings()
            # We rename vars here, because we don't want variables
            # from the two different productions to match.
            found = found.rename_variables(used_vars=left_edge.variables())
            # Unify B1 (left_edge.nextsym) with B2 (right_edge.lhs) to
            # generate B3 (result).
            result = unify(nextsym, found, bindings, rename_vars=False)
            if result is None: return
        else:
            if nextsym != found: return
            # Create a copy of the bindings.
            bindings = left_edge.bindings()

        # Construct the new edge.
        new_edge = left_edge.move_dot_forward(right_edge.end(), bindings)

        # Add it to the chart, with appropriate child pointers.
        if chart.insert_with_backpointer(new_edge, left_edge, right_edge):
            yield new_edge
开发者ID:Weiming-Hu,项目名称:text-based-six-degree,代码行数:32,代码来源:featurechart.py


示例2: apply_iter

    def apply_iter(self, chart, grammar, left_edge, right_edge):
        # Make sure the rule is applicable.
        if not (left_edge.end() == right_edge.start() and
                left_edge.is_incomplete() and
                right_edge.is_complete() and
                isinstance(left_edge, TreeEdge) and
                isinstance(right_edge, TreeEdge)):
            return

        # Unify B1 (left_edge.next) with B2 (right_edge.lhs) to
        # generate B3 (result).
        bindings = left_edge.bindings() # creates a copy.
        result = unify(left_edge.next(), right_edge.lhs(),
                       bindings, rename_vars=False)
        if result is None: return

        # Construct the new edge.
        new_edge = FeatureTreeEdge(span=(left_edge.start(), right_edge.end()),
                                   lhs=left_edge.lhs(), rhs=left_edge.rhs(),
                                   dot=left_edge.dot()+1, bindings=bindings)
        
        # Add it to the chart, with appropriate child pointers.
        changed_chart = False
        for cpl1 in chart.child_pointer_lists(left_edge):
            if chart.insert(new_edge, cpl1+(right_edge,)):
                changed_chart = True

        # If we changed the chart, then generate the edge.
        if changed_chart: yield new_edge
开发者ID:DrDub,项目名称:icsisumm,代码行数:29,代码来源:featurechart.py


示例3: apply

    def apply(self, chart, grammar, edge):
        if edge.is_incomplete():
            return
        found = edge.lhs()
        for prod in grammar.productions(rhs=found):
            bindings = {}
            if isinstance(edge, FeatureTreeEdge):
                _next = prod.rhs()[0]
                if not is_nonterminal(_next):
                    continue

                # We rename vars here, because we don't want variables
                # from the two different productions to match.
                used_vars = find_variables(
                    (prod.lhs(),) + prod.rhs(), fs_class=FeatStruct
                )
                found = found.rename_variables(used_vars=used_vars)

                result = unify(_next, found, bindings, rename_vars=False)
                if result is None:
                    continue

            new_edge = FeatureTreeEdge.from_production(
                prod, edge.start()
            ).move_dot_forward(edge.end(), bindings)
            if chart.insert(new_edge, (edge,)):
                yield new_edge
开发者ID:prz3m,项目名称:kind2anki,代码行数:27,代码来源:featurechart.py


示例4: parses

 def parses(self, start, tree_class=Tree):
     for edge in self.select(start=0, end=self._num_leaves):
         if ((isinstance(edge, FeatureTreeEdge)) and
             (edge.lhs()[TYPE] == start[TYPE]) and
             (unify(edge.lhs(), start, rename_vars=True))
             ):
             for tree in self.trees(edge, complete=True, tree_class=tree_class):
                 yield tree
开发者ID:Weiming-Hu,项目名称:text-based-six-degree,代码行数:8,代码来源:featurechart.py


示例5: _parses

 def _parses(self, chart, start, tree_class):
     # Output a list of complete parses.
     trees = []
     for edge in chart.select(span=(0, chart.num_leaves())):
         if unify(edge.lhs(), start, rename_vars=True):
             trees += chart.trees(edge, complete=True,
                                  tree_class=tree_class)
     return trees
开发者ID:DrDub,项目名称:icsisumm,代码行数:8,代码来源:featurechart.py


示例6: apply_iter

 def apply_iter(self, chart, grammar, edge):
     if edge.is_incomplete(): return
     if isinstance(edge, FeatureTreeEdge): 
         for prod in grammar.productions(rhs=edge.lhs()):
             next = prod.rhs()[0]
             if not isinstance(next, FeatStructNonterminal): continue
             bindings = {}
             if unify(next, edge.lhs(), bindings):
                 new_edge = FeatureTreeEdge(edge.span(), prod.lhs(), prod.rhs(), 1, bindings)
                 if chart.insert(new_edge, (edge,)):
                     yield new_edge
     else: # The edge is a LeafEdge:
         for prod in grammar.productions(rhs=edge.lhs()):
             new_edge = FeatureTreeEdge(edge.span(), prod.lhs(), prod.rhs(), 1)
             if chart.insert(new_edge, (edge,)):
                 yield new_edge
开发者ID:ciju,项目名称:yql_hash,代码行数:16,代码来源:featurechart.py


示例7: generate_from

 def generate_from (self, x):
     options = self.expansions(x)
     if not options:
         raise Failure
     (r, x, bindings) = random.choice(options)
     children = []
     for y in r.rhs():
         if isinstance(y, str):
             children.append(y)
         else:
             y = y.substitute_bindings(bindings)
             child = self.generate_from(y)
             children.append(child)
             # just to update the bindings
             if not unify(y, child.label(), bindings, rename_vars=False):
                 raise Exception("This can't happen")
     x = x.substitute_bindings(bindings).rename_variables()
     return Tree(x, children)
开发者ID:caiqizhe,项目名称:Archive,代码行数:18,代码来源:gdev.py


示例8: checkSentence

def checkSentence(iii,s,corrlist,rec=0):
	"""
	iii: index of sentence in the sentence list
	s: sentence in nodedic format
	rec: recursion level
	"""
	#print "_____________________________________________"
	#if rec>10:
		#print s,rec
		#1/0
	if debug: print "checking sentence",iii,"rec",rec,"len(s)",len(s)
	
	
	# TODO: kick out:
	if rec<1:
		#print "____________________________"
		#for i in s:	print i,s[i][tokenname], s[i]
		#print "____________________________"
		
		
		for i in s:
			#print s
			if "gov" in s[i]:
				for g in s[i]["gov"]:
					if s[i]["gov"][g].endswith("_invisible"):
						s[i]["gov"][g]=s[i]["gov"][g].replace("_invisible","_inherited")
	
	
	if rec<3:
				
		
		for i in sorted(s):
			
			if debug>1:
				try:
					print "checking:",i,s[i][tokenname]
					
					#s[i]
					#print s[i]["lemma"],s[i]["lemma"] in corrdic,i in s
					#print corrdic
				except:
					print "index",i,"is gone"
				#if s[i]['cat']=="unknown" and s[i][tokenname]=="d'":
				#if s[i][tokenname]==u"écrivant":
					#print "********************************************************"
					#for i in sorted(s):
						#print s[i]
					##print s
					#1/0
			#print i,s[i]		
			
			
			if i in s:
				for matchdic,insdic in corrlist:
					if unify(s[i],matchdic):
						
						
						#( s[i]["lemma"] in corrdic or s[i][tokenname] in corrdic):
						if debug>1:
							print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè"
							#if s[i]["lemma"] in corrdic : print corrdic[s[i]["lemma"]]
							#else:print corrdic[s[i][tokenname]]
							print s[i]
							print "matched oooooooooooooooooooooooooooooooo"
							print matchdic
							print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè"
						#if s[i]["lemma"] in corrdic : insdic=corrdic[s[i]["lemma"]]
						#else:insdic=corrdic[s[i][tokenname]]
						if isinstance(insdic,int):# glueing. in this case insdic contains the direction of the token glueing
							s = glue(copy.deepcopy(s),i,insdic)
							s = checkSentence(iii,copy.deepcopy(s),corrlist,rec+1)
						else:
							s = integrate(copy.deepcopy(s),i,insdic)
							if len(insdic)>1:
								s=checkSentence(iii,copy.deepcopy(s),corrlist,rec+1)
			#elif i in s and  ( s[i]["lemma"] in gluedic or s[i][tokenname] in gluedic) :
				#if debug>1:
					#print "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"
					#if s[i]["lemma"] in gluedic :print gluedic[s[i]["lemma"]]
					#else:print gluedic[s[i][tokenname]]
					#print "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"
				#if s[i]["lemma"] in gluedic : insdic=gluedic[s[i]["lemma"]]
				#else:insdic=gluedic[s[i][tokenname]]
				#news = glue(s,i,insdic)
				#s=checkSentence(iii,news,corrlist,rec+1)
			
			
	return s			
开发者ID:amir-zeldes,项目名称:arborator,代码行数:88,代码来源:treebankfiles.py


示例9: iter_expansions

 def iter_expansions (self, x):
     for r in self.__grammar.productions(lhs=x):
         bindings = {}
         x1 = unify(x, r.lhs(), bindings, rename_vars=False)
         if x1:
             yield (r, x1, bindings)
开发者ID:caiqizhe,项目名称:Archive,代码行数:6,代码来源:gdev.py


示例10: iter_expansions

def iter_expansions(x, g):
    for r in g.productions(lhs=x):
        bindings = {}
        x1 = unify(x, r.lhs(), bindings, rename_vars=False)
        if x1:
            yield (r, x1, bindings)
开发者ID:jeneisen,项目名称:computational-ling,代码行数:6,代码来源:fcfg.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python grammar.is_nonterminal函数代码示例发布时间:2022-05-27
下一篇:
Python util.CanvasWidget类代码示例发布时间: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