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


Python compat.PY3属性代码示例

本文整理汇总了Python中nltk.compat.PY3属性的典型用法代码示例。如果您正苦于以下问题:Python compat.PY3属性的具体用法?Python compat.PY3怎么用?Python compat.PY3使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在nltk.compat的用法示例。


在下文中一共展示了compat.PY3属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calc_dist

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def calc_dist(self, lang, trigram, text_profile):
        ''' Calculate the "out-of-place" measure between the
            text and language profile for a single trigram '''

        lang_fd = self._corpus.lang_freq(lang)
        dist = 0

        if trigram in lang_fd:
            idx_lang_profile = list(lang_fd.keys()).index(trigram)
            idx_text = list(text_profile.keys()).index(trigram)

            #print(idx_lang_profile, ", ", idx_text)
            dist = abs(idx_lang_profile - idx_text) 
        else:
            # Arbitrary but should be larger than
            # any possible trigram file length
            # in terms of total lines
            if PY3:
                dist = maxsize
            else:
                dist = maxint

        return dist 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:25,代码来源:textcat.py

示例2: outf_writer_compat

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def outf_writer_compat(outfile, encoding, errors, gzip_compress=False):
    """
    Identify appropriate CSV writer given the Python version
    """
    if compat.PY3:
        if gzip_compress:
            outf = gzip.open(outfile, 'wt', encoding=encoding, errors=errors)
        else:
            outf = open(outfile, 'w', encoding=encoding, errors=errors)
        writer = csv.writer(outf)
    else:
        if gzip_compress:
            outf = gzip.open(outfile, 'wb')
        else:
            outf = open(outfile, 'wb')
        writer = compat.UnicodeWriter(outf, encoding=encoding, errors=errors)
    return (writer, outf) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:19,代码来源:common.py

示例3: _load_lang_mapping_data

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def _load_lang_mapping_data(self):
        ''' Load language mappings between codes and description from table.txt '''
        if isinstance(self.root, ZipFilePathPointer):
            raise RuntimeError("Please install the 'crubadan' corpus first, use nltk.download()")
        
        mapper_file = path.join(self.root, self._LANG_MAPPER_FILE)
        if self._LANG_MAPPER_FILE not in self.fileids():
            raise RuntimeError("Could not find language mapper file: " + mapper_file)

        if PY3:
            raw = open(mapper_file, 'r', encoding='utf-8').read().strip()
        else:
            raw = open(mapper_file, 'rU').read().decode('utf-8').strip()

        self._lang_mapping_data = [row.split('\t') for row in raw.split('\n')] 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:17,代码来源:crubadan.py

示例4: _load_lang_ngrams

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def _load_lang_ngrams(self, lang):
        ''' Load single n-gram language file given the ISO 639-3 language code
            and return its FreqDist '''

        if lang not in self.langs():
            raise RuntimeError("Unsupported language.")

        crubadan_code = self.iso_to_crubadan(lang)
        ngram_file = path.join(self.root, crubadan_code + '-3grams.txt')

        if not path.isfile(ngram_file):
            raise Runtime("No N-gram file found for requested language.")

        counts = FreqDist()
        if PY3:
            f = open(ngram_file, 'r', encoding='utf-8')
        else:
            f = open(ngram_file, 'rU')

        for line in f:
            if PY3:
                data = line.split(' ')
            else:
                data = line.decode('utf8').split(' ')

            ngram = data[1].strip('\n')
            freq = int(data[0])
            
            counts[ngram] = freq
            
        return counts 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:33,代码来源:crubadan.py

示例5: setup_module

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def setup_module(module):
    from nose import SkipTest
    if PY3:
        raise SkipTest("test_2x_compat is for testing nltk.compat under Python 2.x") 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:6,代码来源:test_2x_compat.py

示例6: setup_module

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def setup_module(module):
    from nose import SkipTest

    raise SkipTest("portuguese_en.doctest imports nltk.examples.pt which doesn't exist!")

    if not PY3:
        raise SkipTest(
            "portuguese_en.doctest was skipped because non-ascii doctests are not supported under Python 2.x"
        ) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:11,代码来源:portuguese_en_fixt.py

示例7: fields

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def fields(self, strip=True, unwrap=True, encoding=None, errors='strict', unicode_fields=None):
        """
        Return an iterator that returns the next field in a ``(marker, value)``
        tuple, where ``marker`` and ``value`` are unicode strings if an ``encoding``
        was specified in the ``fields()`` method. Otherwise they are non-unicode strings.

        :param strip: strip trailing whitespace from the last line of each field
        :type strip: bool
        :param unwrap: Convert newlines in a field to spaces.
        :type unwrap: bool
        :param encoding: Name of an encoding to use. If it is specified then
            the ``fields()`` method returns unicode strings rather than non
            unicode strings.
        :type encoding: str or None
        :param errors: Error handling scheme for codec. Same as the ``decode()``
            builtin string method.
        :type errors: str
        :param unicode_fields: Set of marker names whose values are UTF-8 encoded.
            Ignored if encoding is None. If the whole file is UTF-8 encoded set
            ``encoding='utf8'`` and leave ``unicode_fields`` with its default
            value of None.
        :type unicode_fields: sequence
        :rtype: iter(tuple(str, str))
        """
        if encoding is None and unicode_fields is not None:
            raise ValueError('unicode_fields is set but not encoding.')
        unwrap_pat = re.compile(r'\n+')
        for mkr, val in self.raw_fields():
            if encoding and not PY3: # kludge - already decoded in PY3?
                if unicode_fields is not None and mkr in unicode_fields:
                    val = val.decode('utf8', errors)
                else:
                    val = val.decode(encoding, errors)
                mkr = mkr.decode(encoding, errors)
            if unwrap:
                val = unwrap_pat.sub(' ', val)
            if strip:
                val = val.rstrip()
            yield (mkr, val) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:41,代码来源:toolbox.py

示例8: _load_lang_ngrams

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def _load_lang_ngrams(self, lang):
        ''' Load single n-gram language file given the ISO 639-3 language code
            and return its FreqDist '''

        if lang not in self.langs():
            raise RuntimeError("Unsupported language.")

        crubadan_code = self.iso_to_crubadan(lang)
        ngram_file = path.join(self.root, crubadan_code + '-3grams.txt')

        if not path.isfile(ngram_file):
            raise RuntimeError("No N-gram file found for requested language.")

        counts = FreqDist()
        if PY3:
            f = open(ngram_file, 'r', encoding='utf-8')
        else:
            f = open(ngram_file, 'rU')

        for line in f:
            if PY3:
                data = line.split(' ')
            else:
                data = line.decode('utf8').split(' ')

            ngram = data[1].strip('\n')
            freq = int(data[0])
            
            counts[ngram] = freq
            
        return counts 
开发者ID:sdoran35,项目名称:hate-to-hugs,代码行数:33,代码来源:crubadan.py

示例9: setup_module

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import PY3 [as 别名]
def setup_module(module):
    from nose import SkipTest
    if PY3:
        raise SkipTest("compat.doctest is for Python 2.x") 
开发者ID:EastonLee,项目名称:FancyWord,代码行数:6,代码来源:compat_fixt.py


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