本文整理汇总了Python中nltk.corpus.wordnet.NOUN属性的典型用法代码示例。如果您正苦于以下问题:Python wordnet.NOUN属性的具体用法?Python wordnet.NOUN怎么用?Python wordnet.NOUN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类nltk.corpus.wordnet
的用法示例。
在下文中一共展示了wordnet.NOUN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tag_semantic_similarity
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def tag_semantic_similarity(x, y, ic):
mx = wn.morphy(x)
my = wn.morphy(y)
if mx is None or my is None:
return 0
synX = wn.synsets(mx, pos=wn.NOUN)
synY = wn.synsets(my, pos=wn.NOUN)
if len(synX) > 0 and len(synY) > 0:
maxSim = synX[0].lin_similarity(synY[0], ic)
else:
maxSim = 0
return maxSim
示例2: pos_tag_convert_penn_to_wn
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def pos_tag_convert_penn_to_wn(tag):
"""
Convert POS tag from Penn tagset to WordNet tagset.
:param tag: a tag from Penn tagset
:return: a tag from WordNet tagset or None if no corresponding tag could be found
"""
from nltk.corpus import wordnet as wn
if tag in ['JJ', 'JJR', 'JJS']:
return wn.ADJ
elif tag in ['RB', 'RBR', 'RBS']:
return wn.ADV
elif tag in ['NN', 'NNS', 'NNP', 'NNPS']:
return wn.NOUN
elif tag in ['VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']:
return wn.VERB
return None
示例3: get_wordnet_pos
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def get_wordnet_pos(self,treebank_tag):
"""
return WORDNET POS compliance to WORDENT lemmatization (a,n,r,v)
"""
if treebank_tag.startswith('J'):
return wordnet.ADJ
elif treebank_tag.startswith('V'):
return wordnet.VERB
elif treebank_tag.startswith('N'):
return wordnet.NOUN
elif treebank_tag.startswith('R'):
return wordnet.ADV
else:
return wordnet.NOUN
示例4: graph_synsets
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def graph_synsets(terms, pos=wn.NOUN, depth=2):
"""
Create a networkx graph of the given terms to the given depth.
"""
G = nx.Graph(
name="WordNet Synsets Graph for {}".format(", ".join(terms)), depth=depth,
)
def add_term_links(G, term, current_depth):
for syn in wn.synsets(term):
for name in syn.lemma_names():
G.add_edge(term, name)
if current_depth < depth:
add_term_links(G, name, current_depth+1)
for term in terms:
add_term_links(G, term, 0)
return G
示例5: pos_tag_text
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def pos_tag_text(text):
def penn_to_wn_tags(pos_tag):
if pos_tag.startswith('J'):
return wn.ADJ
elif pos_tag.startswith('V'):
return wn.VERB
elif pos_tag.startswith('N'):
return wn.NOUN
elif pos_tag.startswith('R'):
return wn.ADV
else:
return None
tagged_text = tag(text)
tagged_lower_text = [(word.lower(), penn_to_wn_tags(pos_tag))
for word, pos_tag in
tagged_text]
return tagged_lower_text
# lemmatize text based on POS tags
示例6: _pos_tuples
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def _pos_tuples():
return [
(wn.NOUN,'N','noun'),
(wn.VERB,'V','verb'),
(wn.ADJ,'J','adj'),
(wn.ADV,'R','adv')]
示例7: get_wordnet_pos
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def get_wordnet_pos(treebank_tag):
if treebank_tag.startswith('J'):
return wordnet.ADJ
elif treebank_tag.startswith('V'):
return wordnet.VERB
elif treebank_tag.startswith('N'):
return wordnet.NOUN
elif treebank_tag.startswith('R'):
return wordnet.ADV
else:
return None
示例8: lemmatize_word
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def lemmatize_word(word, pos=wordnet.NOUN):
return LEMMATIZER.lemmatize(word, pos)
示例9: lemmatize_sentence
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def lemmatize_sentence(sentence):
res = []
sentence_ = get_valid_words(sentence)
for word, pos in pos_tag(sentence_):
wordnet_pos = get_wordnet_pos(pos) or wordnet.NOUN
res.append(lemmatize_word(word, pos=wordnet_pos))
return res
示例10: check_robustpca
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def check_robustpca(trainCollection, testCollection, feature):
ready = True
# check matlab
if not check_matlab():
print_msg('RobustPCA (%s, %s, %s)' % (trainCollection, testCollection, feature), 'Matlab is not available or incorrectly configured.')
ready = False
# check if knn is available
if not check_knn(trainCollection, testCollection, feature):
print_msg('RobustPCA (%s, %s, %s)' % (trainCollection, testCollection, feature), 'KNN is not available.')
ready = False
# check data files
datafiles = [ os.path.join(ROOT_PATH, trainCollection, 'TextData', 'id.userid.lemmtags.txt'),
os.path.join(ROOT_PATH, trainCollection, 'FeatureData', feature)]
res = find_missing_files(datafiles)
if res:
print_msg('RobustPCA (%s, %s, %s)' % (trainCollection, testCollection, feature), 'the following files or folders are missing:\n%s' % res)
return False
# check external dependencies
try:
import h5py
import numpy
import scipy.io
import scipy.sparse
from nltk.corpus import wordnet as wn
from nltk.corpus import wordnet_ic
brown_ic = wordnet_ic.ic('ic-brown.dat')
wn.morphy('cat')
wn.synsets('cat', pos=wn.NOUN)
except Exception, e:
try:
import nltk
nltk.download('brown')
nltk.download('wordnet')
nltk.download('wordnet_ic')
except Exception, e:
print e
ready = False
示例11: wup_similarity
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def wup_similarity(tagx, tagy):
scores = []
for pos in [wn.NOUN, wn.VERB, wn.ADJ, wn.ADJ_SAT, wn.ADV]:
try:
synsetx = wn.synset('%s.%s.01' % (tagx,pos))
synsety = wn.synset('%s.%s.01' % (tagy,pos))
score = synsetx.wup_similarity(synsety)
if score is None:
score = 0
except Exception, e:
score = 0
scores.append(score)
示例12: test_pos_tag_convert_penn_to_wn
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def test_pos_tag_convert_penn_to_wn():
assert pos_tag_convert_penn_to_wn('JJ') == wn.ADJ
assert pos_tag_convert_penn_to_wn('RB') == wn.ADV
assert pos_tag_convert_penn_to_wn('NN') == wn.NOUN
assert pos_tag_convert_penn_to_wn('VB') == wn.VERB
for tag in ('', 'invalid', None):
assert pos_tag_convert_penn_to_wn(tag) is None
示例13: __get_wordnet_pos
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def __get_wordnet_pos(self, treebank_tag):
if treebank_tag.startswith("J"):
return wordnet.ADJ
elif treebank_tag.startswith("V"):
return wordnet.VERB
elif treebank_tag.startswith("N"):
return wordnet.NOUN
elif treebank_tag.startswith("R"):
return wordnet.ADV
else:
return ""
示例14: tagwn
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def tagwn(self, tag):
"""
Returns the WordNet tag from the Penn Treebank tag.
"""
return {
'N': wn.NOUN,
'V': wn.VERB,
'R': wn.ADV,
'J': wn.ADJ
}.get(tag[0], wn.NOUN)
示例15: get_wordnet_pos
# 需要导入模块: from nltk.corpus import wordnet [as 别名]
# 或者: from nltk.corpus.wordnet import NOUN [as 别名]
def get_wordnet_pos(treebank_tag):
""" Converts a Penn Tree-Bank part of speech tag into a corresponding WordNet-friendly tag.
Borrowed from: http://stackoverflow.com/questions/15586721/wordnet-lemmatization-and-pos-tagging-in-python. """
if treebank_tag.startswith('J') or treebank_tag.startswith('A'):
return wordnet.ADJ
elif treebank_tag.startswith('V'):
return wordnet.VERB
elif treebank_tag.startswith('N'):
return wordnet.NOUN
elif treebank_tag.startswith('R'):
return wordnet.ADV
else:
return 'OTHER'