Esempio n. 1
0
    def findPoems(self,saveToFile=False):
        """
        Find and optionally save poems to file using learning model
        """
        if saveToFile:
            with open('poems'+self.date,'a') as f:
                f.write('Comment poems from %s\n\n' % self.date)

        for commentProperties in self.myComments.myComments:
            comment = commentProperties['comment']
            #comment = re.sub('\n+', '\n', comment)
           
            predProb = self.myModel.predictNewPoem(TimesComments.features(comment))
                
            # display everything with 20%+ chance of being a poem
            if predProb > 0.2:
                print 'Possible poem w/ probability=%f\n\n' % predProb
                print comment
                print '\n%s?comments#permid=%s' % (commentProperties['url'],commentProperties['id'])
                print '\n\n\n--------\n\n\n'
                if saveToFile:
                    with open('poems'+self.date,'a') as f:
                        f.write(comment+'\n')
                        f.write('\nPossible poem w/ probability=%f\n' % predProb)
                        f.write('%s?comments#permid=%s\n' % (commentProperties['url'],commentProperties['id']))
                        f.write('\n\n\n--------\n\n\n\n')
Esempio n. 2
0
    def findPoems(self, saveToFile=False):
        """
        Find and optionally save poems to file using learning model
        """
        self.myModel = LearningModel()

        if saveToFile:
            with open("poems%s.txt" % self.date, "w") as f:
                f.write("Comment poems from %s\n\n" % self.date)

        foundPoems = []
        for commentProperties in self.myComments.myComments:
            comment = commentProperties["comment"]
            # comment = re.sub('\n+', '\n', comment)

            predProb = self.myModel.predictNewPoem(TimesComments.features(comment))

            # display everything with 20%+ chance of being a poem
            if predProb > 0.2:
                foundPoems.append(
                    (predProb, comment, "%s?comments#permid=%s\n" % (commentProperties["url"], commentProperties["id"]))
                )
                if self.verbose:
                    print "Possible poem w/ probability=%f\n\n" % predProb
                    print comment
                    print "\n%s?comments#permid=%s" % (commentProperties["url"], commentProperties["id"])
                    print "\n\n\n--------\n\n\n"
                if saveToFile:
                    with open("poems%s.txt" % self.date, "a") as f:
                        f.write(comment + "\n")
                        f.write("\nPossible poem w/ probability=%f\n" % predProb)
                        f.write("%s?comments#permid=%s\n" % (commentProperties["url"], commentProperties["id"]))
                        f.write("\n\n\n--------\n\n\n\n")

        print "Found %d poems!\n\n" % len(foundPoems)
        return foundPoems