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


Python compat.integer_types方法代碼示例

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


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

示例1: describe

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import integer_types [as 別名]
def describe(self, f_id):
        # Inherit docs.
        if not isinstance(f_id, compat.integer_types):
            raise TypeError('describe() expected an int')
        try:
            self._inv_mapping
        except AttributeError:
            self._inv_mapping = [-1]*len(self._mapping)
            for (info, i) in self._mapping.items():
                self._inv_mapping[i] = info

        if f_id < len(self._mapping):
            (fname, fval, label) = self._inv_mapping[f_id]
            return '%s==%r and label is %r' % (fname, fval, label)
        elif self._alwayson and f_id in self._alwayson.values():
            for (label, f_id2) in self._alwayson.items():
                if f_id == f_id2:
                    return 'label is %r' % label
        elif self._unseen and f_id in self._unseen.values():
            for (fname, f_id2) in self._unseen.items():
                if f_id == f_id2:
                    return '%s is unseen' % fname
        else:
            raise ValueError('Bad feature id') 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:26,代碼來源:maxent.py

示例2: encode

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import integer_types [as 別名]
def encode(self, featureset, label):
        # Inherit docs.
        encoding = []

        # Convert input-features to joint-features:
        for fname, fval in featureset.items():
            if isinstance(fval, (compat.integer_types, float)):
                # Known feature name & value:
                if (fname, type(fval), label) in self._mapping:
                    encoding.append((self._mapping[fname, type(fval),
                                                   label], fval))
            else:
                # Known feature name & value:
                if (fname, fval, label) in self._mapping:
                    encoding.append((self._mapping[fname, fval, label], 1))

                # Otherwise, we might want to fire an "unseen-value feature".
                elif self._unseen:
                    # Have we seen this fname/fval combination with any label?
                    for label2 in self._labels:
                        if (fname, fval, label2) in self._mapping:
                            break # we've seen this fname/fval combo
                    # We haven't -- fire the unseen-value feature
                    else:
                        if fname in self._unseen:
                            encoding.append((self._unseen[fname], 1))


        # Add always-on features:
        if self._alwayson and label in self._alwayson:
            encoding.append((self._alwayson[label], 1))

        return encoding 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:35,代碼來源:maxent.py

示例3: from_train

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import integer_types [as 別名]
def from_train(tokens):
        """
        Constructs an ARFF_Formatter instance with class labels and feature
        types determined from the given data. Handles boolean, numeric and
        string (note: not nominal) types.
        """
        # Find the set of all attested labels.
        labels = set(label for (tok, label) in tokens)

        # Determine the types of all features.
        features = {}
        for tok, label in tokens:
            for (fname, fval) in tok.items():
                if issubclass(type(fval), bool):
                    ftype = '{True, False}'
                elif issubclass(type(fval), (compat.integer_types, float, bool)):
                    ftype = 'NUMERIC'
                elif issubclass(type(fval), compat.string_types):
                    ftype = 'STRING'
                elif fval is None:
                    continue # can't tell the type.
                else:
                    raise ValueError('Unsupported value type %r' % ftype)

                if features.get(fname, ftype) != ftype:
                    raise ValueError('Inconsistent type for %s' % fname)
                features[fname] = ftype
        features = sorted(features.items())

        return ARFF_Formatter(labels, features) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:32,代碼來源:weka.py

示例4: _fmt_arff_val

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import integer_types [as 別名]
def _fmt_arff_val(self, fval):
        if fval is None:
            return '?'
        elif isinstance(fval, (bool, compat.integer_types)):
            return '%s' % fval
        elif isinstance(fval, float):
            return '%r' % fval
        else:
            return '%r' % fval 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:11,代碼來源:weka.py


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