本文整理汇总了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)
示例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')