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


Python FreqDist.max方法代码示例

本文整理汇总了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)
开发者ID:gree2,项目名称:hobby,代码行数:13,代码来源:ch01.py

示例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)
开发者ID:Joselin,项目名称:nltk,代码行数:18,代码来源:decisiontree.py

示例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()
开发者ID:ANB2,项目名称:nltk-trainer,代码行数:9,代码来源:taggers.py

示例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()
开发者ID:RomanZacharia,项目名称:python_text_processing_w_nltk2_cookbook,代码行数:9,代码来源:classification.py

示例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())
开发者ID:billcary,项目名称:python_text_processing_w_nltk2_cookbook,代码行数:10,代码来源:taggers.py

示例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()
开发者ID:ANB2,项目名称:nltk-trainer,代码行数:10,代码来源:multi.py

示例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
开发者ID:adityajoshi5,项目名称:RESLVE,代码行数:11,代码来源:tfidf.py

示例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())
开发者ID:ShunyuanZ,项目名称:nltk3-cookbook,代码行数:11,代码来源:taggers.py

示例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)
开发者ID:Argonaught,项目名称:playground,代码行数:20,代码来源:shift.py

示例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)
开发者ID:prz3m,项目名称:kind2anki,代码行数:23,代码来源:decisiontree.py

示例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
开发者ID:atiassa,项目名称:recommend-2011,代码行数:15,代码来源:q2_1.py

示例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)
开发者ID:danigarabato,项目名称:qa,代码行数:52,代码来源:QA.py

示例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)
开发者ID:Argonaught,项目名称:playground,代码行数:16,代码来源:xor.py

示例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
开发者ID:danigarabato,项目名称:qa,代码行数:19,代码来源:answer.py

示例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
开发者ID:0623forbidden,项目名称:nltk4russian,代码行数:23,代码来源:tagger.py


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