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


Python Lexicon.compile方法代码示例

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


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

示例1: Lect

# 需要导入模块: from lexicon import Lexicon [as 别名]
# 或者: from lexicon.Lexicon import compile [as 别名]

#.........这里部分代码省略.........
			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

	def get_categories(self, name):
		"""
		Return the lemma and word categories of a part of speech.

		@param name: The name of the part of speech.
		@type name: str

		@rtype: tuple of tuple of str
		@return: A tuple where the first element is a tuple containing the lemma categories and the second contains the word categories.
		"""
		if name not in self.__p_o_s:
			raise KeyError(name)
		return (self.__lemma_categories[name], self.__categories[name])

	def read(self, expression):
		"""
		Interprete an expression.

		@param expression: The expression to read.
		@type expression: C{str}

		@raise fsa.ParseError: If the grammar can not parse the expression.
		@raise expression.ExpressionParseError: If no syntax tree could be constructed.
		@raise tokenizer.UnknownTokenException: If an unexpected token is encountered.

		@return: The list of possible interpretations.
		@rtype: list of ParseTree
		"""

		if not isinstance(expression, unicode):
			raise TypeError("%s is not Unicode" % repr(expression))

		tokenizer = self.lexicon.compile(self.properties, False)
                # @type tokenizer pylilac.core.tokenizer.Tokenizer
		parser = self.grammar.compile(False)
                # @type parser pylilac.core.fsa.Parser
		er = ExpressionReader(tokenizer, parser)
		return er(expression)

	def compile(self, force = False):
		"""
		Compile the lexicon and the grammar.
		@param force: Recompile even if the result of a previous compilation was in memory.
		@type force: bool
		@raise grammar.GrammarError: If anomalies are encountered while precompiling the grammar.
		@raise tokenizer.UnknownTokenException: If an unknown character is encountered while precompiling the lexicon.
		@raise fsa.ParseError: If unexpected tokens or stops are encountered.
		"""
		self.lexicon.compile(self.properties, force)
		self.grammar.compile(force)

	def reset(self):
		"""
		Delete the internal results of the last compiling.
		"""
		self.lexicon.reset()
		self.grammar.reset()
开发者ID:BackupTheBerlios,项目名称:pylilac-svn,代码行数:104,代码来源:lect.py


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