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


Python Filter类代码示例

本文整理汇总了Python中Filter的典型用法代码示例。如果您正苦于以下问题:Python Filter类的具体用法?Python Filter怎么用?Python Filter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getGroupWide

def getGroupWide(folder='../test/patents/US_out/full/'):
    """Return a set of terms used across an entire set of files."""
    parser = NPParser.NPParser()
    filters = Settings.getDocumentFilters()
    if 'stops' in filters:
        filters.remove('stops')
    termlist = []
    filenames = [f for f in os.listdir(folder) if f[-4:]=='.txt']
    filtfname = os.path.join(folder, 'filter.save')
    if os.path.exists(filtfname):
            Filter._get_stemdict(filtfname)
    for f in filenames:
        nps = parser.getTerms(os.path.join(folder,f), filters)
        termlist.append(nps)
#    if not os.path.exists(filtfname):
#        Filter._save_stemdict(filtfname)
    all_terms = set()
    for termset in termlist:
        all_terms.update(termset)
    retlist = set()
    for term in all_terms:
        count = 0
        for termset in termlist:
            if term in termset:
                count += 1
        if count > len(filenames)*0.2:
            if 'stem' in filters:
                retlist.update(Filter.unstem(term))
            else:
                retlist.add(term)
    return retlist
开发者ID:AdamMeyers,项目名称:The_Termolator,代码行数:31,代码来源:patentterms.py

示例2: getTerms

 def getTerms(self, filename, filters=[], relaxed=False):
     """Input file, output a FreqDist of terms"""
     filterfname = os.path.join(os.path.dirname(filename), "filter.save")
     if os.path.exists(filename + ".nps") and os.path.exists(filterfname):
         f = open(filename + ".nps")
         old_filters, fd = pickle.load(f)
         f.close()
         if old_filters == filters:
             if not Filter.unstemdict:
                 Filter._get_stemdict(filterfname)
             return fd
     NPs = self.getNPs(filename)
     fd = FreqDist()
     for NP in NPs:
         # get the possible terms for each NP
         terms = self.extractPossibleTerms(NP, relaxed)
         # filter each term by some given criteria
         # this requires keeping case information until this point
         # filt = Filter.Filter() # class containing all filters
         for t in terms:
             for f in filters:
                 t = Filter.criteria[f](t)
             if t:
                 fd[t] += 1
     f = open(filename + ".nps", "w")
     pickle.dump((filters, fd), f)
     f.close()
     if os.path.exists(filterfname):
         os.remove(filterfname)
     return fd
开发者ID:AdamMeyers,项目名称:The_Termolator,代码行数:30,代码来源:NPParser.py

示例3: check_file

    def check_file(self, pkg, filename):
        if filename.startswith('/usr/lib/debug') or pkg.isSource():
            return
        if not stat.S_ISREG(pkg.files()[filename].mode):
            return

        if len(pkg.grep(self.build_root_re, filename)):
            Filter.printError(pkg, "file-contains-buildroot", filename)
开发者ID:jsegitz,项目名称:rpmlint-checks,代码行数:8,代码来源:CheckBuildRoot.py

示例4: check_file

 def check_file(self, pkg, filename):
     beam = BeamFile(pkg.files()[filename].path)
     if 'debug_info' not in beam.compileinfo['options']:
         Filter.printWarning(
             pkg, "beam-compiled-without-debug_info", filename)
     if not self.source_re.match(Pkg.b2s(beam.compileinfo['source'].value)):
         Filter.printWarning(
             pkg, "beam-was-not-recompiled", filename,
             beam.compileinfo['source'].value)
开发者ID:openSUSE,项目名称:rpmlint-checks,代码行数:9,代码来源:ErlangCheck.py

示例5: loopProcess

def loopProcess(url):
  r = requests.get(url)
  Filter.proc(url, r.text, r.headers)
# push all url into raw queue
  mats = re.findall(PATTERN_URL, r.text)
  if mats is not None:
    for mat in mats:
      link = mat[0]
      if not link.startswith('http://'):
        link = url[:url.find('/', 8)] + '/' + link
      URLService.pushRawUrl(link)
开发者ID:kintomiko,项目名称:novel_crawler,代码行数:11,代码来源:slave.py

示例6: check

    def check(self, pkg):
        ghosts = pkg.ghostFiles()
        for filename in pkg.files():
            if filename in ghosts:
                continue

            if not stat.S_ISREG(pkg.files()[filename].mode):
                continue

            if wrong_compression(os.path.join(pkg.dirname, filename)):
                Filter.printError(pkg, 'files-wrong-compression', filename)
开发者ID:bmwiedemann,项目名称:rpmlint-checks,代码行数:11,代码来源:CompressionCheck.py

示例7: playFilteredSound

def playFilteredSound():
    Zero.list = []
    Pole.list = []

    for key in entryDictionary.keys():
        entryDictionary[key].complexRoot.addToList()

    soundFilter = Filter(Zero.list, Pole.list)
    filteredSamples = soundFilter.filterStream(originalSamples)

    snd.play(getWaveBytes(inputSoundInfo, filteredSamples))
开发者ID:mijallen,项目名称:PythonSoundFilter,代码行数:11,代码来源:interface.py

示例8: check_file

    def check_file(self, pkg, filename):
        if pkg.isSource() or not stat.S_ISREG(pkg.files()[filename].mode):
            return

        if pkg.grep(self.suspicious_dir, filename):
            Filter.printError(pkg, "invalid-pkgconfig-file", filename)

        pc_file = file(pkg.dirName() + "/" + filename, "r")
        for l in pc_file:
            if l.startswith('Libs:') and self.wronglib_dir.search(l):
                Filter.printError(pkg, 'pkgconfig-invalid-libs-dir',
                                  filename, l)
开发者ID:StefanBruens,项目名称:rpmlint-checks,代码行数:12,代码来源:CheckPkgConfig.py

示例9: saveSound

def saveSound():
    Zero.list = []
    Pole.list = []

    for key in entryDictionary.keys():
        entryDictionary[key].complexRoot.addToList()

    soundFilter = Filter(Zero.list, Pole.list)
    filteredSamples = soundFilter.filterStream(originalSamples)

    filename = tkFileDialog.asksaveasfilename(filetypes=[("Waveform Audio", ".wav")],
        defaultextension='.wav')
    saveSoundToFile(inputSoundInfo, filteredSamples, filename)
开发者ID:mijallen,项目名称:PythonSoundFilter,代码行数:13,代码来源:interface.py

示例10: grep

 def grep(self, regex, filename):
     """Grep regex from a file, return matching line numbers."""
     ret = []
     lineno = 0
     try:
         with open(os.path.join(
                 self.dirName() or '/', filename.lstrip('/'))) as in_file:
             for line in in_file:
                 lineno += 1
                 if regex.search(line):
                     ret.append(str(lineno))
                     break
     except Exception as e:
         Filter.printWarning(self, 'read-error', filename, e)
     return ret
开发者ID:Fak3,项目名称:rpmlint,代码行数:15,代码来源:Pkg.py

示例11: run

def run(args):
    usage = 'Usage: ' + args[0] + ' path [-terms|-chem|-dna|-group]'
    logging.basicConfig(level=LEVEL)
    if len(args) < 2 or len(args) > 3:
        print usage
        return None
    path = None
    getFunc = None
    for arg in args[1:]:
        if os.path.isdir(arg):
            path = arg
        elif arg == '-terms':
            getFunc = getPatentTerms
        elif arg == '-chem':
            getFunc = getChemicals
        elif arg == '-dna':
            getFunc = getDNA
        elif arg == '-group':
            getFunc = getGroupWide
    if not path or not getFunc:
        print usage
        return None
    path = os.path.abspath(path)
    logging.info('RDG path: '+path)
    logging.info('Get Function: '+getFunc.func_name)
    if getFunc.func_name == 'getGroupWide':
        terms = getFunc(path)
    else:
        logging.debug('Collecting File ids...')
        filenames = [f for f in os.listdir(path) if f[-4:]=='.txt']
        terms = []
        logging.debug('Finding terms...')
        filtfname = os.path.join(path, 'filter.save')
        if getFunc.func_name == 'getPatentTerms' and os.path.exists(filtfname):
            Filter._get_stemdict(filtfname)
        for f in filenames:
            logging.debug('...'+f+'...')
            terms.extend(getFunc(os.path.join(path,f)))
#        if getFunc.func_name == 'getPatentTerms' and not os.path.exists(filtfname):
#            Filter._save_stemdict(filtfname)
        logging.debug('Clean up...')
        if getFunc.func_name == 'getPatentTerms':
            temp = set()
            for t in terms:
                temp.update(Filter.unstem(t))
            terms = temp
        terms = set(terms)
    return terms
开发者ID:AdamMeyers,项目名称:The_Termolator,代码行数:48,代码来源:patentterms.py

示例12: __init__

 def __init__(self, recordFactory, sensorView):
     self.recordFactory = recordFactory
     self.records = []
     self.frecuency = 30.0
     self.a = 0
     self.sensorView = sensorView
     self.filter = Filter.filter()
开发者ID:DavidJavier,项目名称:PocketSystem,代码行数:7,代码来源:RecordController.py

示例13: check_file

    def check_file(self, pkg, filename):
        if filename.startswith('/usr/lib/debug') or pkg.isSource():
            return

        if not stat.S_ISREG(pkg.files()[filename].mode):
            return

        grep_date = pkg.grep(self.istoday, filename)

        if len(grep_date):
            grep_time = pkg.grep(self.looksliketime, filename)

            if len(grep_time):
                Filter.printError(pkg, "file-contains-date-and-time", filename)
            else:
                Filter.printWarning(pkg, "file-contains-current-date",
                                    filename)
开发者ID:jsegitz,项目名称:rpmlint-checks,代码行数:17,代码来源:CheckBuildDate.py

示例14: check

    def check(self, pkg):

        if pkg.isSource():
            return

        md5s = {}
        sizes = {}
        files = pkg.files()
        configFiles = pkg.configFiles()

        for f, pkgfile in files.items():
            if f in pkg.ghostFiles():
                continue

            if not stat.S_ISREG(pkgfile.mode):
                continue

            md5s.setdefault(pkgfile.md5, set()).add(f)
            sizes[pkgfile.md5] = pkgfile.size

        sum = 0
        for f in md5s:
            duplicates = md5s[f]
            if len(duplicates) == 1:
                continue

            one = duplicates.pop()
            one_is_config = False
            if one in configFiles:
                one_is_config = True

            partition = get_prefix(one)

            st = os.stat(pkg.dirName() + '/' + one)
            diff = 1 + len(duplicates) - st[stat.ST_NLINK]
            if diff <= 0:
                for dupe in duplicates:
                    if partition != get_prefix(dupe):
                        Filter.printError(pkg, "hardlink-across-partition",
                                          one, dupe)
                    if one_is_config and dupe in configFiles:
                        Filter.printError(pkg, "hardlink-across-config-files",
                                          one, dupe)
                continue

            for dupe in duplicates:
                if partition != get_prefix(dupe):
                    diff = diff - 1
            sum += sizes[f] * diff
            if sizes[f] and diff > 0:
                Filter.printWarning(pkg, 'files-duplicate', one,
                                    ":".join(duplicates))

        if sum > 100000:
            Filter.printError(pkg, 'files-duplicated-waste', sum)
开发者ID:StefanBruens,项目名称:rpmlint-checks,代码行数:55,代码来源:DuplicatesCheck.py

示例15: convert

 def convert(self, raw_data):
     raw_data_s = Filter.s(raw_data)
     if raw_data == u'n/a':
         return 0
     elif raw_data == u'< 1 year':
         return 1
     elif raw_data == u'10+ years':
         return 11
     return int(raw_data[0]) + 1
开发者ID:prostickman,项目名称:LendingClub,代码行数:9,代码来源:EmploymentLength.py


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