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


Python data.FileSystemPathPointer方法代碼示例

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


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

示例1: find_corpus_fileids

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import FileSystemPathPointer [as 別名]
def find_corpus_fileids(root, regexp):
    if not isinstance(root, PathPointer):
        raise TypeError('find_corpus_fileids: expected a PathPointer')
    regexp += '$'

    # Find fileids in a zipfile: scan the zipfile's namelist.  Filter
    # out entries that end in '/' -- they're directories.
    if isinstance(root, ZipFilePathPointer):
        fileids = [name[len(root.entry):] for name in root.zipfile.namelist()
                 if not name.endswith('/')]
        items = [name for name in fileids if re.match(regexp, name)]
        return sorted(items)

    # Find fileids in a directory: use os.walk to search all (proper
    # or symlinked) subdirectories, and match paths against the regexp.
    elif isinstance(root, FileSystemPathPointer):
        items = []
        # workaround for py25 which doesn't support followlinks
        kwargs = {}
        if not py25():
            kwargs = {'followlinks': True}
        for dirname, subdirs, fileids in os.walk(root.path, **kwargs):
            prefix = ''.join('%s/' % p for p in _path_from(root.path, dirname))
            items += [prefix+fileid for fileid in fileids
                      if re.match(regexp, prefix+fileid)]
            # Don't visit svn directories:
            if '.svn' in subdirs: subdirs.remove('.svn')
        return sorted(items)

    else:
        raise AssertionError("Don't know how to handle %r" % root) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:33,代碼來源:util.py


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