Chooses the highest scoring category for a sample of text

        :param text: sample text to classify
        :type text: str
        :return: the "winning" category
        :rtype: str
960614
def classify(self, text):
        
        score = self.score(text)
        if not score:
            return None
        return sorted(score.items(), key=lambda v: v[1])[-1][0]
472431
def predict(self, text:str, n_words:int=1, no_unk:bool=True, temperature:float=1., min_p:float=None, sep:str=' ',
                decoder=decode_spec_tokens):
        ""
        ds = self.data.single_dl.dataset
        self.model.reset()
        xb,yb = self.data.one_item(text)
        new_idx = []
        for _ in range(n_words): #progress_bar(range(n_words), leave=False):
            res = self.pred_batch(batch=(xb,yb))[0][-1]
            #if len(new_idx) == 0: self.model[0].select_hidden([0])
            if no_unk: res[self.data.vocab.stoi[UNK]] = 0.
            if min_p is not None: 
                if (res >= min_p).float().sum() == 0:
                    warn(f"There is no item with probability >= {min_p}, try a lower value.")
                else: res[res < min_p] = 0.
            if temperature != 1.: res.pow_(1 / temperature)
            idx = torch.multinomial(res, 1).item()
            new_idx.append(idx)
            xb = xb.new_tensor([idx])[None]
        return text + sep + sep.join(decoder(self.data.vocab.textify(new_idx, sep=None)))
807126
def text(self,text):
        
        if text:
            text = utfstr(text)
            text = text.strip()
            text = re.sub('\s+',' ',text)
            if text:
                self.dirty = True
                self.escpos.text(text)
361832
def _title_similarity_score(full_text, title):
    """"""

    sentences = sentence_tokenizer(full_text)
    norm = _normalize([title]+sentences)
    similarity_matrix = pairwise_kernels(norm, metric='cosine')
    return sorted(zip(
                     similarity_matrix[0,1:],
                     range(len(similarity_matrix)),
                     sentences
                     ),
                 key = lambda tup: tup[0],
                 reverse=True
                 )
1343323
def get(self, wordCategories, aFilter='PV|CLICK|AVGCPC|COMPETITION', nick=None):
        ''''''
        request = TOPRequest('taobao.simba.insight.wordscats.get')
        request['wordCategories'] = wordCategories
        request['filter'] = aFilter
        if nick!=None: request['nick'] = nick
        self.create(self.execute(request))
        return self.result
433019
def extract_features(self, text):
        
        # Feature extractor may take one or two arguments
        try:
            return self.feature_extractor(text, self.train_set)
        except (TypeError, AttributeError):
            return self.feature_extractor(text)
1127993
def text_filter_changed(self, text):
        
        text = text.strip() if text else None

        if text is not None:
            self.__text_filter = ListModel.TextFilter("text_for_filter", text)
        else:
            self.__text_filter = None

        self.__update_filter()
1094639
def get_keyword(text):
    
    first_word = text.split(" ")[0]

    if len(first_word) > 1 and first_word.isupper(): 
        kwd = str(first_word.lower())
    else:
        kwd = None

    return kwd
874737
public Record predict(String text) {
        TrainingParameters trainingParameters = (TrainingParameters) knowledgeBase.getTrainingParameters();
        
        Dataframe testDataset = new Dataframe(knowledgeBase.getConfiguration());
        testDataset.add(
            new Record(
                new AssociativeArray(
                    AbstractTextExtractor.newInstance(trainingParameters.getTextExtractorParameters()).extract(StringCleaner.clear(text))
                ),
                null
            )
        );
        
        predict(testDataset);
        
        Record r = testDataset.iterator().next();
        
        testDataset.close();
        
        return r;
    }
63233
def highest(self):
        
        scores = self.scores()
        if not scores:
            return None
        maxscore = max(map(score, scores))
        return filter(lambda x: score(x) == maxscore, scores)
625436
def MaximinWinner(profile):
    

    # Currently, we expect the profile to contain complete ordering over candidates.
    elecType = profile.getElecType()
    if elecType != "soc" and elecType != "toc":
        print("ERROR: unsupported profile type")
        exit()

    maximinscores = getMaximinScores(profile)
    winner = max(maximinscores.items(), key=lambda x: x[1])[0]
    return winner
545751
def scores(self, text: str) -> Dict[str, float]:
        
        values = extract(text)
        input_fn = _to_func(([values], []))
        prediction = self._classifier.predict_proba(input_fn=input_fn)
        probabilities = next(prediction).tolist()
        sorted_languages = sorted(self.languages)
        return dict(zip(sorted_languages, probabilities))
1348385
def probable_languages(
            self,
            text: str,
            max_languages: int = 3) -> Tuple[str, ...]:
        
        scores = self.scores(text)

        # Sorted from the most probable language to the least probable
        sorted_scores = sorted(scores.items(), key=itemgetter(1), reverse=True)
        languages, probabilities = list(zip(*sorted_scores))

        # Find the most distant consecutive languages.
        # A logarithmic scale is used here because the probabilities
        # are most of the time really close to zero
        rescaled_probabilities = [log(proba) for proba in probabilities]
        distances = [
            rescaled_probabilities[pos] - rescaled_probabilities[pos+1]
            for pos in range(len(rescaled_probabilities)-1)]

        max_distance_pos = max(enumerate(distances, 1), key=itemgetter(1))[0]
        limit = min(max_distance_pos, max_languages)
        return languages[:limit]
133749
def sentiment(
    text       = None,
    confidence = False
    ):
    
    try:
        words = text.split(" ")
        # Remove empty strings.
        words = [word for word in words if word]
        features = word_features(words)
        classification = classifier.classify(features)
        confidence_classification = classifier.prob_classify(features).prob(classification)
    except:
        classification = None
        confidence_classification = None
    if confidence:
        return (
            classification,
            confidence_classification
        )
    else:
        return classification
1374133
def categorize(str)
      raise ArgumentError, 'str param must be a String' unless str.is_a?(String)

      outcomes = j_instance.categorize(str)
      j_instance.getBestCategory(outcomes)
    end
905105
def parse(self, text):
        
        tokens = self.lex(text)
        parser = Parser(tokens)
        return parser.parse()
426064
def analyze(self, text, tokenizer=str.split):
        
        if not self.tagger:
            self.tagger = Tagger(self.model,
                                 preprocessor=self.p,
                                 tokenizer=tokenizer)

        return self.tagger.analyze(text)