當前位置: 首頁>>代碼示例>>Python>>正文


Python wordnet.synset_from_pos_and_offset方法代碼示例

本文整理匯總了Python中nltk.corpus.wordnet.synset_from_pos_and_offset方法的典型用法代碼示例。如果您正苦於以下問題:Python wordnet.synset_from_pos_and_offset方法的具體用法?Python wordnet.synset_from_pos_and_offset怎麽用?Python wordnet.synset_from_pos_and_offset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nltk.corpus.wordnet的用法示例。


在下文中一共展示了wordnet.synset_from_pos_and_offset方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fit

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [as 別名]
def fit(self, X):
        """Fit the transformer."""
        super().fit(X)
        X = self._unpack(X)

        related = Counter()
        for x in X:
            for (offset, pos) in x:
                s = wn.synset_from_pos_and_offset(pos, int(offset))
                related.update(self.recursive_related(s))

        if self.prune:
            related = {k: v for k, v in related.items() if v > 1}
        self.feature_names = set(chain.from_iterable(X))
        self.features = {k: idx for idx, k in enumerate(related)}
        self.vec_len = len(self.features)
        return self 
開發者ID:clips,項目名稱:wordkit,代碼行數:19,代碼來源:wordnet.py

示例2: procecss_wn18_definitions

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [as 別名]
def procecss_wn18_definitions(self, wn18_path=""):
        definitions_file = os.path.join(wn18_path, "wordnet-mlj12-definitions.txt")
        with open(definitions_file) as f:
            lines = f.readlines()

        pos_conversion_map = {'NN':'n', 'VB':'v', 'JJ':'a', 'RB':'r'}
        self.definition_map = {}
        n_empty_definitions = 0
        for line in tqdm(lines):
            synset_offset, synset_tag, _ = line.split('\t')
            #definition_map[synset_idx.strip()] = definition.strip()
            #fetch definition from wordnet
            pos = synset_tag.split('_')[-2]
            wn_ss = wn.synset_from_pos_and_offset(pos_conversion_map[pos], int(synset_offset))
            definition = wn_ss.definition().strip()
            if len(definition) == 0:
                n_empty_definitions = n_empty_definitions + 1

            self.definition_map[synset_offset.strip()] = definition

        print ("#Empty definitions {}/{}".format(n_empty_definitions, len(self.definition_map)))
        synsets = sorted(self.definition_map.keys())
        self.synset_to_idx = {v:i for i,v in enumerate(synsets)}
        self.idx_to_synset = {v:i for i,v in self.synset_to_idx.items()}
        self.definitions = [self.definition_map[k] for k in synsets] 
開發者ID:malllabiisc,項目名稱:EWISE,代碼行數:27,代碼來源:definition_preprocessor.py

示例3: senti_synset

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [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

示例4: id2ss

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [as 別名]
def id2ss(self,ID):
        """
        Parameters
            ----------
            ID : str
                the id of a chinese word found in zh_wordnet.
        Returns
            ----------
            nltk.corpus.reader.wordnet.Synset
                an object in en_wordnet.
        """
        return wn.synset_from_pos_and_offset(str(ID[-1:]), int(ID[:8])) 
開發者ID:Coldog2333,項目名稱:Financial-NLP,代碼行數:14,代碼來源:NLP.py

示例5: vectorize

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [as 別名]
def vectorize(self, x):
        """Vectorize a word."""
        vec = np.zeros(self.vec_len)
        for (offset, pos) in x:
            s = wn.synset_from_pos_and_offset(pos, int(offset))
            res = self.recursive_related(s)
            if self.prune:
                res = [x for x in res if x in self.features]
            s = [self.features[s] for s in res]
            vec[s] = 1

        return vec 
開發者ID:clips,項目名稱:wordkit,代碼行數:14,代碼來源:wordnet.py

示例6: getnode

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [as 別名]
def getnode(x):
    return wn.synset_from_pos_and_offset('n', int(x[1:])) 
開發者ID:cyvius96,項目名稱:DGP,代碼行數:4,代碼來源:make_induced_graph.py

示例7: all_senti_synsets

# 需要導入模塊: from nltk.corpus import wordnet [as 別名]
# 或者: from nltk.corpus.wordnet import synset_from_pos_and_offset [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:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:10,代碼來源:sentiwordnet.py


注:本文中的nltk.corpus.wordnet.synset_from_pos_and_offset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。