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


Python wordnet.synset方法代码示例

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


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

示例1: get_static_welcome_message

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def get_static_welcome_message():
    """
    Get the static welcome page.
    """
    return \
"""
<h3>Search Help</h3>
<ul><li>The display below the line is an example of the output the browser
shows you when you enter a search word. The search word was <b>green</b>.</li>
<li>The search result shows for different parts of speech the <b>synsets</b>
i.e. different meanings for the word.</li>
<li>All underlined texts are hypertext links. There are two types of links:
word links and others. Clicking a word link carries out a search for the word
in the Wordnet database.</li>
<li>Clicking a link of the other type opens a display section of data attached
to that link. Clicking that link a second time closes the section again.</li>
<li>Clicking <u>S:</u> opens a section showing the relations for that synset.</li>
<li>Clicking on a relation name opens a section that displays the associated
synsets.</li>
<li>Type a search word in the <b>Next Word</b> field and start the search by the
<b>Enter/Return</b> key or click the <b>Search</b> button.</li>
</ul>
""" 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:25,代码来源:wordnet_app.py

示例2: senti_synset

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def senti_synset(self, *vals):        
        from nltk.corpus import wordnet as wn
        if tuple(vals) in self._db:
            pos_score, neg_score = self._db[tuple(vals)]
            pos, offset = vals
            synset = wn._synset_from_pos_and_offset(pos, offset)
            return SentiSynset(pos_score, neg_score, synset)
        else:
            synset = wn.synset(vals[0])
            pos = synset.pos()
            offset = synset.offset()
            if (pos, offset) in self._db:
                pos_score, neg_score = self._db[(pos, offset)]
                return SentiSynset(pos_score, neg_score, synset)
            else:
                return None 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:18,代码来源:sentiwordnet.py

示例3: get_synset_embedding

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def get_synset_embedding(synset, word_vectors, get_vector):
    class_name = wn.synset(synset).lemma_names()
    class_name = ', '.join([_.replace('_', ' ') for _ in class_name])
    class_name = class_name.lower()

    feat = np.zeros(feat_len)

    options = class_name.split(',')
    cnt_word = 0
    for j in range(len(options)):
        now_feat = get_embedding(options[j].strip(), word_vectors, get_vector)
        if np.abs(now_feat.sum()) > 0:
            cnt_word += 1
            feat += now_feat
    if cnt_word > 0:
        feat = feat / cnt_word

    if np.abs(feat.sum()) == 0:
        return feat
    else:
        # feat = feat / (np.linalg.norm(feat) + 1e-6)
        return feat 
开发者ID:ruotianluo,项目名称:Context-aware-ZSR,代码行数:24,代码来源:convert_gcn.py

示例4: get_synset_embedding

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def get_synset_embedding(synset, word_vectors, get_vector):
    class_name = wn.synset(synset).lemma_names()
    class_name = ', '.join([_.replace('_', ' ') for _ in class_name])
    class_name = class_name.lower()

    feat = np.zeros(feat_len)

    options = class_name.split(',')
    cnt_word = 0
    for j in range(len(options)):
        now_feat = get_embedding(options[j].strip(), word_vectors, get_vector)
        if np.abs(now_feat.sum()) > 0:
            cnt_word += 1
            feat += now_feat
    if cnt_word > 0:
        feat = feat / cnt_word

    if np.abs(feat.sum()) == 0:
        return None
    else:
        # feat = feat / (np.linalg.norm(feat) + 1e-6)
        return feat 
开发者ID:ruotianluo,项目名称:Context-aware-ZSR,代码行数:24,代码来源:convert_from_bansal.py

示例5: create_parent_children_file

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def create_parent_children_file(ln, ofile="/Users/tdong/data/glove_wordSenseChildren.txt",
                                w2vile= "/Users/tdong/data/glove/glove.6B.50d.txt"):
    """
    the problem of this method is: a->b->c, but b is not in the w2v file, a and c are in the w2v.
    the relation between a->c is brocken
    :param ln:
    :param ofile:
    :param w2vile:
    :return:
    """
    lst = ln.split()
    lines = [" ".join(["*root*"] + lst + ["\n"])]
    with open(w2vile, 'r') as vfh:
        vocLst = [word.split()[0] for word in vfh.readlines()]
    while lst:
        parent = lst.pop(0)
        children = [ele.name() for ele in wn.synset(parent).hyponyms() if ele.name().split('.')[0] in vocLst]
        newLine = " ".join([parent] + children + ["\n"])
        lines.append(newLine)
        print(parent, "::", children)
        lst += children
    with open(ofile, 'w') as ofh:
        ofh.write("".join(lines)) 
开发者ID:gnodisnait,项目名称:nball4tree,代码行数:25,代码来源:util_file.py

示例6: clean_wordsense_path

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def clean_wordsense_path(ifile="", w2vFile ="", ofile=""):
    lines = []
    with open(w2vFile, 'r') as ifh:
        vocLst = [ele.split()[0] for ele in ifh.readlines()]
    with open(ifile, 'r') as ifh:
        for ln in ifh:
            wlst = ln.strip().split()
            if len(wlst) > 2:
                node = wlst[0]
                lsts = [[ele.name() for ele in lst if ele.name().split(".")[0] in vocLst]
                        for lst in wn.synset(node).hypernym_paths()]
                wspath = sorted(lsts, key = len)[-1]
                lines.append(" ".join(wlst[:2] + wspath+["\n"]))
            else:
                lines.append(ln)
    with open(ofile, 'w') as ofh:
        ofh.write("".join(lines)) 
开发者ID:gnodisnait,项目名称:nball4tree,代码行数:19,代码来源:util_file.py

示例7: get_static_welcome_message

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def get_static_welcome_message():
    """
    Get the static welcome page.
    """
    return """
<h3>Search Help</h3>
<ul><li>The display below the line is an example of the output the browser
shows you when you enter a search word. The search word was <b>green</b>.</li>
<li>The search result shows for different parts of speech the <b>synsets</b>
i.e. different meanings for the word.</li>
<li>All underlined texts are hypertext links. There are two types of links:
word links and others. Clicking a word link carries out a search for the word
in the Wordnet database.</li>
<li>Clicking a link of the other type opens a display section of data attached
to that link. Clicking that link a second time closes the section again.</li>
<li>Clicking <u>S:</u> opens a section showing the relations for that synset.</li>
<li>Clicking on a relation name opens a section that displays the associated
synsets.</li>
<li>Type a search word in the <b>Next Word</b> field and start the search by the
<b>Enter/Return</b> key or click the <b>Search</b> button.</li>
</ul>
""" 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:24,代码来源:wordnet_app.py

示例8: senti_synset

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def senti_synset(self, *vals):
        from nltk.corpus import wordnet as wn

        if tuple(vals) in self._db:
            pos_score, neg_score = self._db[tuple(vals)]
            pos, offset = vals
            if pos == 's':
                pos = 'a'
            synset = wn.synset_from_pos_and_offset(pos, offset)
            return SentiSynset(pos_score, neg_score, synset)
        else:
            synset = wn.synset(vals[0])
            pos = synset.pos()
            if pos == 's':
                pos = 'a'
            offset = synset.offset()
            if (pos, offset) in self._db:
                pos_score, neg_score = self._db[(pos, offset)]
                return SentiSynset(pos_score, neg_score, synset)
            else:
                return None 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:23,代码来源:sentiwordnet.py

示例9: lemma_property

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def lemma_property(word, synset, func):

    def flattern(l):
        if l == []:
            return []
        else:
            return l[0] + flattern(l[1:])

    return flattern([func(l) for l in synset.lemmas if l.name == word]) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:11,代码来源:wordnet_app.py

示例10: _get_synset

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def _get_synset(synset_key):
    """
    The synset key is the unique name of the synset, this can be
    retrived via synset.name()
    """
    return wn.synset(synset_key) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:8,代码来源:wordnet_app.py

示例11: _collect_one_synset

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def _collect_one_synset(word, synset, synset_relations):
    '''
    Returns the HTML string for one synset or word

    :param word: the current word
    :type word: str
    :param synset: a synset
    :type synset: synset
    :param synset_relations: information about which synset relations
    to display.
    :type synset_relations: dict(synset_key, set(relation_id))
    :return: The HTML string built for this synset
    :rtype: str
    '''
    if isinstance(synset, tuple): # It's a word
        raise NotImplementedError("word not supported by _collect_one_synset")

    typ = 'S'
    pos_tuple = _pos_match((synset.pos(), None, None))
    assert pos_tuple is not None, "pos_tuple is null: synset.pos(): %s" % synset.pos()
    descr = pos_tuple[2]
    ref = copy.deepcopy(Reference(word, synset_relations))
    ref.toggle_synset(synset)
    synset_label = typ + ";"
    if synset.name() in synset_relations:
        synset_label = _bold(synset_label)
    s = '<li>%s (%s) ' % (make_lookup_link(ref, synset_label), descr)
    def format_lemma(w):
        w = w.replace('_', ' ')
        if w.lower() == word:
            return _bold(w)
        else:
            ref = Reference(w)
            return make_lookup_link(ref, w)

    s += ', '.join(format_lemma(l.name()) for l in synset.lemmas())

    gl = " (%s) <i>%s</i> " % \
        (synset.definition(),
         "; ".join("\"%s\"" % e for e in synset.examples()))
    return s + gl + _synset_relations(word, synset, synset_relations) + '</li>\n' 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:43,代码来源:wordnet_app.py

示例12: _collect_all_synsets

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def _collect_all_synsets(word, pos, synset_relations=dict()):
    """
    Return a HTML unordered list of synsets for the given word and
    part of speech.
    """
    return '<ul>%s\n</ul>\n' % \
        ''.join((_collect_one_synset(word, synset, synset_relations)
                 for synset
                 in wn.synsets(word, pos))) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:11,代码来源:wordnet_app.py

示例13: toggle_synset_relation

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def toggle_synset_relation(self, synset, relation):
        """
        Toggle the display of the relations for the given synset and
        relation type.

        This function will throw a KeyError if the synset is currently
        not being displayed.
        """
        if relation in self.synset_relations[synset.name()]:
            self.synset_relations[synset.name()].remove(relation)
        else:
            self.synset_relations[synset.name()].add(relation)

        return self 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:16,代码来源:wordnet_app.py

示例14: toggle_synset

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def toggle_synset(self, synset):
        """
        Toggle displaying of the relation types for the given synset
        """
        if synset.name() in self.synset_relations:
            del self.synset_relations[synset.name()]
        else:
            self.synset_relations[synset.name()] = set()

        return self 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:12,代码来源:wordnet_app.py

示例15: all_senti_synsets

# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import synset [as 别名]
def all_senti_synsets(self):
        from nltk.corpus import wordnet as wn
        for key, fields in self._db.items():
            pos, offset = key
            pos_score, neg_score = fields
            synset = wn._synset_from_pos_and_offset(pos, offset)
            yield SentiSynset(pos_score, neg_score, synset) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:9,代码来源:sentiwordnet.py


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