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


Python wordnet.Lemma方法代码示例

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


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

示例1: lemma

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Lemma [as 别名]
def lemma(name):
	"""emulates wn.lemma"""
	chunks = name.split('.')
	i = 3
	success = 0
	while not success:
		try:
			synsetname = '.'.join(chunks[:i])
			lemmas = data._synset2lemmas[synsetname]
			success = 1
		except KeyError:
			i += 1
	if name in lemmas:
		lemmaname = '.'.join(chunks[i:])
		return _lemma(lemmaname, synset(synsetname))
	raise WordNetError('Lemma ' + name + ' Not Found') 
开发者ID:mkhodak,项目名称:pawn,代码行数:18,代码来源:wordnet.py

示例2: synsets

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Lemma [as 别名]
def synsets(token, pos='anrsv'):
	"""emulates wn.synsets"""
	morph = morphy(token)
	if morph:
		return [wn.synset(name) for name in data._word2synsets[morph] if name.split('.')[-2] in pos]
	return []


###############################################################################
################ Lemma Wrapper, Replacement, and Access Methods ###############
###############################################################################


# instantiation of Lemma object 
开发者ID:mkhodak,项目名称:pawn,代码行数:16,代码来源:wordnet.py

示例3: _lemma

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Lemma [as 别名]
def _lemma(name, synset):
	language = data._language
	synset_name = synset.name()
	for lemma_name, lemma in _lemmas[language][synset_name].items():
		if name == lemma_name:
			return lemma
	lemma = Lemma(WordNetCorpusReader, synset, name, 0, 0, None)
	_lemmas[language][synset_name][name] = lemma
	return lemma


# replacement for 'lemmas' method of class 'Synset' 
开发者ID:mkhodak,项目名称:pawn,代码行数:14,代码来源:wordnet.py

示例4: _synset_lemma_names

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Lemma [as 别名]
def _synset_lemma_names(self):
	if data._language == 'en':
		return self._lemma_names
	return [name for name in data._synset2lemmas.get(self.name(), [])]


# wrapper for lexical relation functions of class 'Lemma' 
开发者ID:mkhodak,项目名称:pawn,代码行数:9,代码来源:wordnet.py

示例5: _lexical_relation_wrapper

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Lemma [as 别名]
def _lexical_relation_wrapper(func):
	def wrapper(self):
		if data._language == 'en':
			return func(self)
		return sum((lemma2.synset().lemmas() for lemma1 in wn.synset(self._PWN_name)._lemmas for lemma2 in func(lemma1)), [])
	return wrapper


# replacement for 'count' method of class 'Lemma' 
开发者ID:mkhodak,项目名称:pawn,代码行数:11,代码来源:wordnet.py

示例6: _synset_relations

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Lemma [as 别名]
def _synset_relations(word, synset, synset_relations):
    '''
    Builds the HTML string for the relations of a synset

    :param word: The current word
    :type word: str
    :param synset: The synset for which we're building the relations.
    :type synset: Synset
    :param synset_relations: synset keys and relation types for which to display relations.
    :type synset_relations: dict(synset_key, set(relation_type))
    :return: The HTML for a synset's relations
    :rtype: str
    '''

    if not synset.name() in synset_relations:
        return ""
    ref = Reference(word, synset_relations)

    def relation_html(r):
        if isinstance(r, Synset):
            return make_lookup_link(Reference(r.lemma_names()[0]), r.lemma_names()[0])
        elif isinstance(r, Lemma):
            return relation_html(r.synset())
        elif isinstance(r, tuple):
            # It's probably a tuple containing a Synset and a list of
            # similar tuples.  This forms a tree of synsets.
            return "%s\n<ul>%s</ul>\n" % \
                (relation_html(r[0]),
                 ''.join('<li>%s</li>\n' % relation_html(sr) for sr in r[1]))
        else:
            raise TypeError("r must be a synset, lemma or list, it was: type(r) = %s, r = %s" % (type(r), r))

    def make_synset_html(db_name, disp_name, rels):
        synset_html = '<i>%s</i>\n' % \
            make_lookup_link(
                copy.deepcopy(ref).toggle_synset_relation(synset, db_name).encode(),
                disp_name)

        if db_name in ref.synset_relations[synset.name()]:
             synset_html += '<ul>%s</ul>\n' % \
                ''.join("<li>%s</li>\n" % relation_html(r) for r in rels)

        return synset_html

    html = '<ul>' + \
        '\n'.join(("<li>%s</li>" % make_synset_html(*rel_data) for rel_data
                   in get_relations_data(word, synset)
                   if rel_data[2] != [])) + \
        '</ul>'

    return html 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:53,代码来源:wordnet_app.py


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