当前位置: 首页>>代码示例>>Python>>正文


Python PyDictionary.translate方法代码示例

本文整理汇总了Python中PyDictionary.PyDictionary.translate方法的典型用法代码示例。如果您正苦于以下问题:Python PyDictionary.translate方法的具体用法?Python PyDictionary.translate怎么用?Python PyDictionary.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyDictionary.PyDictionary的用法示例。


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

示例1: Meaning

# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import translate [as 别名]
class Meaning():
	def __init__(self):
		self.dictionary=PyDictionary()
	def meaning_function(self,query,task="mn"): #task can be meaning, translate,
		fo=open("meaning.txt","w")
		if task == "mn" :
			fo.write("Meaning :")
			fo.write(str(self.dictionary.meaning(query)))
			fo.write("Synonym :")
			fo.write(str(self.dictionary.synonym(query)))
			fo.write("Antonym :")
			fo.write(str(self.dictionary.antonym(query)))
			print (self.dictionary.meaning(query))
		elif task =="tr":
			fo.write("Translation :")
			unicodedata.normalize('NFKD', self.dictionary.translate(query,'hi')).encode('ascii','ignore')
			fo.write(unicodedata.normalize('NFKD', self.dictionary.translate(query,'hi')).encode('ascii','ignore')) ##Unicode to string conversion
			print(self.dictionary.translate(query,'hi'))
		fo.close()
	def __del__(self):
		os.remove("meaning.txt")
开发者ID:SDES-IITB-course-archive,项目名称:SDES_Readout,代码行数:23,代码来源:Meaning.py

示例2: RecursiveLambdaFunctionGrowth

# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import translate [as 别名]

#.........这里部分代码省略.........
			number_of_cycles=0
			for cycle in allsimplecycles:
				number_of_cycles += 1
				if number_of_cycles > 500:
					break
				try:
					print "==================================================================="
					print "Cycle :",cycle
					instrumented_cycle=self.instrument_relations(cycle)
					print "instrumented_cycle:",instrumented_cycle
					rw_ct=self.randomwalk_lambda_function_composition_tree(instrumented_cycle)
					print "Cycle Composition Tree for this cycle :",rw_ct
					print "maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit=",maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit
					print "==================================================================="
					if rw_ct[1] > maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit[1]:
						maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit=rw_ct
				except KeyError:
					pass
				rw_ct=""
		intrinsic_merit_dict={}
		print "grow_lambda_function3(): Graph Tensor Neuron Network Intrinsic Merit for this text:",self.graph_tensor_neuron_network_intrinsic_merit

		print "grow_lambda_function3(): Machine Translation Example - English to Kannada:"
		self.machine_translation(definitiongraph, "kn")

		self.korner_entropy(definitiongraph)
		print "grow_lambda_function3(): Korner Entropy Intrinsic Merit for this text:",self.entropy

		density = self.density(definitiongraph)
		print "grow_lambda_function3(): Graph Density (Regularity Lemma):",density

		bose_einstein_intrinsic_fitness=self.bose_einstein_intrinsic_fitness(definitiongraph)
		print "grow_lambda_function3(): Bose-Einstein Intrinsic Fitness:",bose_einstein_intrinsic_fitness

		print "grow_lambda_function3(): Maximum Per Random Walk Graph Tensor Neuron Network Intrinsic Merit :",maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit

		print "grow_lambda_function3(): Recursive Gloss Overlap Classifier classes for text:",RecursiveGlossOverlap_Classifier.RecursiveGlossOverlap_Classify(text)

		intrinsic_merit_dict["graph_tensor_neuron_network_intrinsic_merit"]=self.graph_tensor_neuron_network_intrinsic_merit
		intrinsic_merit_dict["maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit"]=maximum_per_random_walk_graph_tensor_neuron_network_intrinsic_merit
		intrinsic_merit_dict["korner_entropy"]=self.entropy
		intrinsic_merit_dict["density"]=density
		intrinsic_merit_dict["bose_einstein_intrinsic_fitness"]=bose_einstein_intrinsic_fitness
		intrinsic_merit_dict["recursive_gloss_overlap_intrinsic_merit"]=definitiongraph_merit[1]
		intrinsic_merit_dict["empath_sentiment"]=sentiment

		write_dot(definitiongraph,"RecursiveLambdaFunctionGrowth.dot")

		self.graph_tensor_neuron_network_intrinsic_merit=1.0
		print "intrinsic_merit_dict:",intrinsic_merit_dict
		return intrinsic_merit_dict 

	def machine_translation(self, definitiongraph, languagecode):
		nodes=definitiongraph.nodes()
		edges=definitiongraph.edges()
		translationgraph=nx.DiGraph()
		for k, v in edges:
			ktrans=self.dictionary.translate(k,languagecode)
			vtrans=self.dictionary.translate(v,languagecode)
			print "k=",k,",v=",v,",ktrans=",ktrans,",vtrans=",vtrans
			translationgraph.add_edge(ktrans, vtrans)
			translationgraph.add_edge(vtrans, ktrans)
		print "TextGraph Translated to ",languagecode,":",translationgraph		

	#KornerEntropy(G) = minimum [- sum_v_in_V(G) {1/|V(G)| * log(Pr[v in Y])}] for each independent set Y
	def korner_entropy(self, definitiongraph):
		nodes=definitiongraph.nodes()
		stable_sets=[]
		for v in nodes:
			stable_sets.append(nx.maximal_independent_set(definitiongraph.to_undirected(),[v]))
		print "korner_entropy(): Stable Independent Sets:",stable_sets
		entropy=0.0
		prob_v_in_stableset=0.0
		for v in nodes:
			for s in stable_sets:
				if v in s:
					prob_v_in_stableset=math.log(0.999999)
				else:
					prob_v_in_stableset=math.log(0.000001)
				entropy += (-1.0) * float(1.0/len(nodes)) * prob_v_in_stableset
			if entropy < self.entropy:
				self.entropy = entropy
			entropy=0.0
		return self.entropy

	#Graph Density - Regularity Lemma
	def density(self, definitiongraph):
		dty=nx.classes.function.density(definitiongraph)
		return dty

	#Bose-Einstein Bianconi intrinsic fitness 
	def bose_einstein_intrinsic_fitness(self, definitiongraph):
		#Bose-Einstein fitness presently assumes energy of a document vertex in a link graph to be
		#the entropy or extent of chaos in the definition graph of document text 
		#This has to be replaced by a more suitable fitness measure
		#Bose-Einstein Condensation function value is hardcoded
		entropy = self.korner_entropy(definitiongraph)
		becf = 0.3
		bei_fitness = math.pow(2, -1 * becf * entropy)
		return bei_fitness
开发者ID:shrinivaasanka,项目名称:asfer-github-code,代码行数:104,代码来源:RecursiveLambdaFunctionGrowth.py


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