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


Python wordnet.Synset方法代码示例

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


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

示例1: morphy

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def morphy(token):
	"""emulates wn.morphy"""
	if ' ' in token:
		return None
	if token in data._words:
		return token
	morph = data._morphy(token)
	if morph in data._words:
		return morph
	return None


###############################################################################
################ Synset Wrapper, Replacement, and Access Methods ##############
###############################################################################


# updates synset based on current language 
开发者ID:mkhodak,项目名称:pawn,代码行数:20,代码来源:wordnet.py

示例2: _synset_update

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def _synset_update(synset):
	language = data._language
	if dir(synset)[0] == _indicator:
		if synset._language != language:
			PWN_name = synset._PWN_name
			if language == 'en':
				setattr(synset, '_name', PWN_name)
			else:
				setattr(synset, '_name', data._synset2lang.get(PWN_name, _dummy+PWN_name))
			setattr(synset, '_language', language)
	else:
		PWN_name = synset._name
		setattr(synset, '_PWN_name', PWN_name)
		if language != 'en':
			setattr(synset, '_name', data._synset2lang.get(PWN_name, _dummy+PWN_name))
		setattr(synset, _indicator, None)
		setattr(synset, '_language', language)


# wrapper to update class 'Synset' before function execution 
开发者ID:mkhodak,项目名称:pawn,代码行数:22,代码来源:wordnet.py

示例3: get_siblings

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def get_siblings(self, synset: Synset):
        """
        Returns up to five siblings of the synset.
        :param synset: The synset to obtain the siblings from
        :return: The siblings obtained from the synset
        """

        siblings = []
        sibling_count = 0
        parent = self.get_parent(synset)

        for sibling in parent.hyponyms():
            if sibling_count == 5:
                break
            if sibling != synset and self.valid_synset(sibling):
                siblings.insert(sibling_count, sibling)
                sibling_count += 1
        
        return siblings 
开发者ID:zevisert,项目名称:Imagyn,代码行数:21,代码来源:lexicon.py

示例4: _lemma

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [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

示例5: _synset_lemmas

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


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

示例6: get_synset_id

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def get_synset_id(synset: Synset):
        """
        Get the corresponding synset id of the synset.
        :param synset: The synset to extract the id from
        :return: The corresponding synset id
        """

        sid = "n{}".format(str(synset.offset()).zfill(8))
        return sid 
开发者ID:zevisert,项目名称:Imagyn,代码行数:11,代码来源:lexicon.py

示例7: valid_synset

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def valid_synset(self, synset: Synset):
        """
        Determines if the synset is valid by checking to see that it is in ImageNet.
        :param synset: The synset to check for validity
        :return: A boolean determining whether or not the synset is in ImageNet
        """

        sid = self.get_synset_id(synset)
        return sid in self.API.all_synsets 
开发者ID:zevisert,项目名称:Imagyn,代码行数:11,代码来源:lexicon.py

示例8: get_parent

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def get_parent(synset: Synset):
        """
        Returns one of the parents of the synset.
        :param synset: The synset to obtain the parent from
        :return: One of the parents of the synset
        """

        return random.choice(synset.hypernyms()) 
开发者ID:zevisert,项目名称:Imagyn,代码行数:10,代码来源:lexicon.py

示例9: get_grandparents

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [as 别名]
def get_grandparents(synset: Synset):
        """
        Returns all grandparents of the synset.
        :param synset: The synset to obtain the grandparents from
        :return: The grandparents of the synset
        """

        grandparents = []

        for parent in synset.hypernyms():
            grandparents.extend(parent.hypernyms())
        
        return grandparents 
开发者ID:zevisert,项目名称:Imagyn,代码行数:15,代码来源:lexicon.py

示例10: _synset_relations

# 需要导入模块: from nltk.corpus.reader import wordnet [as 别名]
# 或者: from nltk.corpus.reader.wordnet import Synset [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.Synset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。