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


Python Memory.forget方法代码示例

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


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

示例1: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import forget [as 别名]
class Parrott:
    def __init__(self):
        '''
        Births a new Parrott,
        with a Naive Bayes brain
        and a Solr memory.
        '''
        self.brain = naive_bayes.NaiveBayes()
        self.twitter = membrane.twitter.api()
        self.memory = Memory()

    def train(self):
        '''
        Trains the Parrott on examples
        stored in Memory (Solr)
        '''
        # Fetch 1000 positive and negative examples.
        pos_tweets = self.memory.recall_positive(0, 1000)
        neg_tweets = self.memory.recall_negative(0, 1000)

        # Pull out the proper text for training data.
        pos = [' '.join([tweet['tweet'], tweet['user']]) for tweet in pos_tweets]
        neg = [' '.join([tweet['tweet'], tweet['user']]) for tweet in neg_tweets]

        # Train the brain.
        self.brain.train(pos, neg)

    def test(self, pos_set, neg_set, threshold=0.8):
        '''
        Tests the Parrott on a set of positive
        and negative examples.

        Args:
            pos_set (list): positive test examples
            neg_set (list): negative test examples
            threshold (float): testing threshold
        Returns:
            dict of test results.
        '''
        return self.brain.test(threshold, pos_set, neg_set)

    def classify(self, tweet):
        '''
        Classifies a Tweet.

        Args:
            tweet (string): the Tweet content
        Returns:
            probability of positive classification.
        '''
        return self.brain.classify(tweet)

    def audit(self, tweet, pos):
        '''
        Deletes an existing Tweet from Memory
        and replaces it with the updated Tweet.

        Args:
            tweet (dict): the Tweet to audit
            pos (bool): is the Tweet is a positive example?
        '''

        # Solr cannot "update", just delete & add.
        self.memory.forget(tweet)

        # Update the tweet.
        tweet.update({'positive':pos, 'audited':True})

        # Clear id and _version_ to prevent conflicts.
        del tweet['id']
        del tweet['_version_']

        # Re-memorize.
        self.memory.memorize(tweet)
开发者ID:frnsys,项目名称:parrott,代码行数:76,代码来源:parrott.py

示例2: Importer

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import forget [as 别名]
class Importer(Thread):
    skip_dirs = ['Originals', 'Thumb', re.compile(r'^\..*')]

    def __init__(self, frame, sources, opts):
        Thread.__init__(self)
        self.started_at = time.time()
        self.interrupt = Event()
        self.frame = frame
        self.opts = opts
        self.source_dirs = []
        self.source_files = []
        for s in sources:
            if os.path.isdir(s):
                self.source_dirs.append(s)
            elif os.path.isfile(s):
                self.source_files.append(os.path.abspath(s))
        self.dest_dirs = parse_dest_dirs(opts.dest_dirs)
        self.already_imported = Memory()
        self.__msg("%sImporting media from %s" % (("" if self.dest_dirs else "Not "), ", ".join(self.source_dirs + self.source_files)))
        if self.dest_dirs:
            self.start()

    def __msg(self, s, min_verbosity = 1):
        try:
            self.__service_interrupt()
            if self.opts.verbosity >= min_verbosity:
                wx.CallAfter(self.frame.logger, s)
        except wx.PyDeadObjectError:
            self.interrupt.set()

    def __dmsg(self, s, min_verbosity = 1):
        if self.opts.dry_run:
            self.__msg("NOT %s" % (s,), min_verbosity)
        else:
            self.__msg(s, min_verbosity)

    def __twiddle(self, mode):
        self.__service_interrupt()
        if self.opts.verbosity > 1:
            wx.CallAfter(self.frame.twiddle, mode)

    def __start(self):
        self.__twiddle(0)

    def __advance(self):
        self.__twiddle(1)

    def __complete(self):
        self.__twiddle(2)

    def __service_interrupt(self):
        if self.interrupt.is_set():
          raise UserWarning("Raise Thread Quitting")

    def __find_media(self):
        from idir import idirs
        import itertools

        def desc_dirs(action, tup):
            if action == "dir":
                (dirpath, fcount, dcount) = tup
                fdets = "%d file%s" % (fcount, ("" if fcount == 1 else "s"))
                ddets = "%d sub-director%s" % (dcount, ("y" if dcount == 1 else "ies"),)
                if fcount > 0:
                    if dcount > 0:
                        para = " (%s & %s)" % (fdets, ddets)
                    else:
                        para = " (%s)" % (fdets,)
                elif dcount > 0:
                    para = " (%s)" % (ddets,)
                else:
                    para = ""
                self.__msg("Scanning directory %s%s" % (dirpath, para), 2)
            elif action == "skip":
                (skipped) = tup
                self.__msg("Skipping dir %s" % (skipped,), 2)

        ret = []
        self.__start()
        paths = idirs(self.source_dirs, desc_dirs, Importer.skip_dirs)
        if self.source_files:
            paths = itertools.chain(self.source_files, paths)
        paths = itertools.ifilter(MediaMetadata.has_media_suff, paths)
        mds = map(lambda path: MediaMetadata(path), paths)
        if self.opts.skip_already_imported and self.opts.forget is False:
            mds = itertools.ifilterfalse(lambda md: self.already_imported.known(md.digest()), mds)
        self.__complete()
        return mds

    def __examine_media(self, mds):
        # Now examine their EXIF data, if we can
        media_details = list(mds)
        media_count = len(media_details)
        ret = {}
        date_count = 0
        self.__msg("Found %s file%s (Not already inspected), now getting shot date info" % (media_count, ("" if media_count == 1 else "s")))
        self.__start()
        for md in media_details:
            self.__advance()
            dirpath = md.dirname
#.........这里部分代码省略.........
开发者ID:craigemery,项目名称:ImportPhotos,代码行数:103,代码来源:importer.py


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