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


Python CorpusReader.fileids方法代码示例

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


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

示例1: fileids

# 需要导入模块: from nltk.corpus.reader.api import CorpusReader [as 别名]
# 或者: from nltk.corpus.reader.api.CorpusReader import fileids [as 别名]
 def fileids(self, channels=None, domains=None, categories=None):
     if channels is not None and domains is not None and \
             categories is not None:
         raise ValueError('You can specify only one of channels, domains '
                          'and categories parameter at once')
     if channels is None and domains is None and \
             categories is None:
         return CorpusReader.fileids(self)
     if isinstance(channels, basestring):
         channels = [channels]
     if isinstance(domains, basestring):
         domains = [domains]
     if isinstance(categories, basestring):
         categories = [categories]
     if channels:
         return self._list_morph_files_by('channel', channels)
     elif domains:
         return self._list_morph_files_by('domain', domains)
     else:
         return self._list_morph_files_by('keyTerm', categories,
                 map=self._map_category)
开发者ID:B-Rich,项目名称:Fem-Coding-Challenge,代码行数:23,代码来源:ipipan.py

示例2: assemble_corpus

# 需要导入模块: from nltk.corpus.reader.api import CorpusReader [as 别名]
# 或者: from nltk.corpus.reader.api.CorpusReader import fileids [as 别名]
def assemble_corpus(corpus_reader: CorpusReader,
                    types_requested: List[str],
                    type_dirs: Dict[str, List[str]] = None,
                    type_files: Dict[str, List[str]] = None) -> CorpusReader:
    """
    Create a filtered corpus.
    :param corpus_reader: This get mutated
    :param types_requested: a list of string types, which are to be found in the type_dirs and
    type_files mappings
    :param type_dirs: a dict of corpus types to directories
    :param type_files: a dict of corpus types to files
    :return: a CorpusReader object containing only the mappings desired
    """
    fileid_names = []  # type: List[str]
    try:
        all_file_ids = list(corpus_reader.fileids())
        clean_ids_types = []  # type: List[Tuple[str, str]]
        if type_files:
            for key, valuelist in type_files.items():
                if key in types_requested:
                    for value in valuelist:
                        if value in all_file_ids:
                            if key:
                                clean_ids_types.append((value, key))
        if type_dirs:
            for key, valuelist in type_dirs.items():
                if key in types_requested:
                    for value in valuelist:
                        corrected_dir = value.replace('./', '')
                        corrected_dir = '{}/'.format(corrected_dir)
                        for name in all_file_ids:
                            if name and name.startswith(corrected_dir):
                                clean_ids_types.append((name, key))
        clean_ids_types.sort(key=lambda x: x[0])
        fileid_names, categories = zip(*clean_ids_types)  # type: ignore
        corpus_reader._fileids = fileid_names
        return corpus_reader
    except Exception:
        LOG.exception('failure in corpus building')
开发者ID:diyclassics,项目名称:cltk,代码行数:41,代码来源:readers.py


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