本文整理汇总了Python中nltk.probability.FreqDist.max方法的典型用法代码示例。如果您正苦于以下问题:Python FreqDist.max方法的具体用法?Python FreqDist.max怎么用?Python FreqDist.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.probability.FreqDist
的用法示例。
在下文中一共展示了FreqDist.max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fun14
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def fun14():
"""counting other things"""
# print [len(w) for w in text1]
fdist1 = FreqDist([len(w) for w in text1])
# print fdist1.keys()
# print fdist1.items()
# word length 3 => 50223
print fdist1[3]
print fdist1.max()
# frequency 20%
print fdist1.freq(3)
示例2: binary_stump
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def binary_stump(feature_name, feature_value, labeled_featuresets):
label = FreqDist([label for (featureset,label)
in labeled_featuresets]).max()
# Find the best label for each value.
pos_fdist = FreqDist()
neg_fdist = FreqDist()
for featureset, label in labeled_featuresets:
if featureset.get(feature_name) == feature_value:
pos_fdist.inc(label)
else:
neg_fdist.inc(label)
decisions = {feature_value: DecisionTreeClassifier(pos_fdist.max())}
default = DecisionTreeClassifier(neg_fdist.max())
return DecisionTreeClassifier(label, feature_name, decisions, default)
示例3: choose_tag
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def choose_tag(self, tokens, index, history):
tags = FreqDist()
for tagger in self._taggers:
tags.inc(tagger.choose_tag(tokens, index, history))
return tags.max()
示例4: classify
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def classify(self, feats):
counts = FreqDist()
for classifier in self._classifiers:
counts.inc(classifier.classify(feats))
return counts.max()
示例5: choose_tag
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def choose_tag(self, tokens, index, history):
word = tokens[index]
fd = FreqDist()
for synset in wordnet.synsets(word):
fd.inc(synset.pos)
return self.wordnet_tag_map.get(fd.max())
示例6: classify
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def classify(self, feat):
'''Return the label with the most agreement among classifiers'''
label_freqs = FreqDist()
for classifier in self._classifiers:
label_freqs.inc(classifier.classify(feat))
return label_freqs.max()
示例7: __compute_tf__
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def __compute_tf__(self, term, doc_terms):
""" Computes the normalized frequency of term t in document d, which
is the number of times t occurs in d divided by the maximum number
of times any term occurs in d: tf(t,d) = f(t,d) / max{f(w,d)} """
fdist = FreqDist(term.lower() for term in doc_terms)
max_freq = doc_terms.count(fdist.max())
if max_freq==0:
return 0.0
return float(doc_terms.count(term)) / max_freq
示例8: choose_tag
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def choose_tag(self, tokens, index, history):
word = tokens[index]
fd = FreqDist()
for synset in wordnet.synsets(word):
fd[synset.pos()] += 1
if not fd: return None
return self.wordnet_tag_map.get(fd.max())
示例9: shiftByAlpha
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def shiftByAlpha(alphas, cipherText, common, reverse):
key = []
for alpha in alphas:
fdist = FreqDist(alpha)
if reverse:
shift = (ord(common) - ord(fdist.max()))
else:
shift = (ord(fdist.max()) - ord(common))
key.append(shift)
print('shift ' + str(shift))
keyLen = len(key)
res = ''
for i in range(0, len(cipherText)):
c = chr((ord(cipherText[i]) + key[i%keyLen])%128)
res += c
print (res)
示例10: binary_stump
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def binary_stump(feature_name, feature_value, labeled_featuresets):
label = FreqDist(label for (featureset, label) in labeled_featuresets).max()
# Find the best label for each value.
pos_fdist = FreqDist()
neg_fdist = FreqDist()
for featureset, label in labeled_featuresets:
if featureset.get(feature_name) == feature_value:
pos_fdist[label] += 1
else:
neg_fdist[label] += 1
decisions = {}
default = label
# But hopefully we have observations!
if pos_fdist.N() > 0:
decisions = {feature_value: DecisionTreeClassifier(pos_fdist.max())}
if neg_fdist.N() > 0:
default = DecisionTreeClassifier(neg_fdist.max())
return DecisionTreeClassifier(label, feature_name, decisions, default)
示例11: worst_errors_many_wrong_decisions
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def worst_errors_many_wrong_decisions(self, k, feature_extractor):
worst_errors = []
features = []
wrongDocs = self.error_prediction_docs(self.maintest, self.testClassify)
for doc in wrongDocs:
feature_dic = feature_extractor(movie_reviews.words(fileids=[doc]))
features = features + feature_dic.keys()
fd = FreqDist(feature.lower() for feature in features)
for i in range(1, k+1):
x = fd.max()
fd.pop(x)
worst_errors.append(x)
return worst_errors
示例12: get_best_answers
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def get_best_answers(self, passage_list, q):
logger = logging.getLogger("qa_logger")
logger.info("%s:\tAnswer Processing", q.id_q)
empty = passage_list == []
logger.info("%s:\t\tAnswer Extraction", q.id_q)
answer_list = []
for passage in passage_list:
a = passage.find_answer(q)
if a.is_successful():
answer_list.append(a)
if not answer_list:
return ([], empty)
logger.info("%s:\t\tAnswer Filtering", q.id_q)
# Obtain answer frequency
fd = FreqDist(answer_list)
# Normalize frequencies
normalize = fd.freq(fd.max())
# Modify scores by frequency
for answer in answer_list:
answer.score = int(answer.score * (fd.freq(answer) / normalize))
# Sort answers by score
answer_list.sort(key=lambda x: x.score, reverse=True)
# Filter bad answers
try:
threshold = int(MyConfig.get("answer_filtering", "threshold"))
except:
logger = logging.getLogger("qa_logger")
logger.error("answer quality threshold not found")
threshold = 50
answer_list = filter(lambda x: x.score > threshold, answer_list)
final_answers = []
for a in answer_list:
if a not in final_answers:
final_answers.append(a)
if len(final_answers) == 3:
break
return (final_answers, empty)
示例13: xorByAlpha
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def xorByAlpha(alphas, cipherText, common):
key = []
for alpha in alphas:
fdist = FreqDist(alpha)
kxor = (ord(fdist.max()) ^ ord(common))
key.append(kxor)
keyLen = len(key)
res = ''
for i in range(0, len(cipherText)):
c = chr((ord(cipherText[i]) ^ key[i%keyLen]))
res += c
print (res)
示例14: _entity_ranking
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def _entity_ranking(self, entities):
if len(entities) == 0:
return "", "", int(0)
# Obtain frequency of entities
entities_freq = FreqDist(entities)
# Our answer is the sample with the greatest number of outcomes
exact = entities_freq.max()
# Our window is empty because this algorithm generates exact answers
window = ""
# Our score is the entity frequency
score = int(entities_freq.freq(exact) * 1000)
return exact, window, score
示例15: choose_tag
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import max [as 别名]
def choose_tag(self, tokens, index, history):
context = self.context(tokens, index, history)
s = self._morph.parse(tokens[index])
tags = [unicode(x.tag).replace(u' ', u',') for x in s]
if len(tags) == 0:
return None
if (len(tags) == 1) or not (context in self._contexts_to_tags.keys()):
return tags[0]
tagsconts = FreqDist()
for tag in tags:
#print 'TAG: ', tag
#print tokens[index]
tagsconts[tag] = self._contexts_to_tags[context].get(tag, 0)
#print 'PROB: | ', context, tagsconts[tag]
best_tag = tagsconts.max()
if tagsconts[best_tag] == 0:
return tags[0]
return best_tag