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


Python Grammar.reset方法代码示例

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


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

示例1: Lect

# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import reset [as 别名]
class Lect(object):
	def __init__(self, code = "zxx"):
		"""
		Create a lect object.
		A I{lect} is language variety; it can either be a spoken or a written form, and a colloquial, mediatic or standard form, and so on.

		It wraps serialization and high-level features.

		It contains three independent internal members:
			- L{lexicon<lexicon>}
			- L{grammar<grammar>}
			- L{inflections<inflection>}

		@type code: str
		@param code:
			A language code according to U{ISO<http://www.iso.org>} standard.

			For the language codes, refer to 639-3 specifications.

			A country/variety code and a representation system might be added: C{eng-US}, C{esp:ERG}, C{por-BR:IPA}
		"""
		self.code = code
		self.name = u""
		self.english_name = ""
		self.__p_o_s = ()
		self.__lemma_categories = {}
		self.__categories = {}
		self.grammar = Grammar(code)
		self.lexicon = Lexicon()
		self.inflections = Inflections()
		self.properties = {"separator" : " ", "capitalization" : "3"} #Lexical and Initials

	#[Properties

	def __get_grammar(self):
		return self.__grammar
	def __get_lexicon(self):
		return self.__lexicon
	def __get_inflections(self):
		return self.__inflections

	def __tuple(self):
		return (self.code, self.name, self.english_name, self.properties, self.__p_o_s, self.__lemma_categories, self.__categories, self.grammar, self.lexicon, self.inflections)

	def save(self, filename, reset = False):
		"""
		Save the lect on the file system.
		The format is a Python I{pickle} file compressed using the GZip algorithm at a medium compression.

		@param reset: If True, resets the lect, stripping out the compilation result of lexicon and grammar.
			In particular, resetting before saving can be beneficial for lects with large lexica.
			The default value is False and the lect is saved in its current status.
		@type reset: bool
		@param filename: The name of the file to generate.
		@type filename: str
		"""
		f = utilities.ZipFile(filename, "wb", 5)
		if reset:
			self.reset()
		pickle.dump(self.__tuple(), f, -1)
		f.flush()
		f.close()

	def load(self, filename):
		"""
		Load the lect from the file system.
		The format is a Python I{pickle} file compressed using the GZip algorithm.

		@param filename: The name of the file to load.
		@type filename: str
		"""
		f = utilities.ZipFile(filename, "rb")
		tuple = pickle.load(f)
		self.code, self.name, self.english_name, self.properties, self.__p_o_s, self.__lemma_categories, self.__categories, self.grammar, self.lexicon, self.inflections = tuple
		f.close()

	def append_p_o_s(self, name, lemma_categories = (), categories = ()):
		"""
		Append a part of speech, defined by its name and the categories of lemmas and words belonging to it.

		@param name: The name of the part of speech.
		@type name: str
		@param lemma_categories: The categories of lemmas belonging to the part of speech. Optional.
		@type lemma_categories: tuple of str
		@param categories: The categories of words belonging to the part of speech. Optional.
		@type categories: tuple of str
		"""
		if name in self.__p_o_s:
			raise KeyError("P.o.s. %s already exists" % name)
		self.__p_o_s += (name,)
		self.__lemma_categories[name] = tuple(lemma_categories)
		self.__categories[name] = tuple(categories)

	def get_p_o_s_names(self):
		"""
		Return the names of the parts of speech.

		@rtype: tuple of str
		"""
		return self.__p_o_s
#.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:pylilac-svn,代码行数:103,代码来源:lect.py


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