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


Python Photo.getCaption方法代码示例

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


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

示例1: removeDuplicatePhotos

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
	def removeDuplicatePhotos(self):
		# this method is not good, just for tempory use
		# by judging if the caption is duplicate
		new_photos = []
		num_duplicate = 0
		for photo in self._event['photos']:
			p = Photo(photo)
			is_duplicate = False
			cap1 = p.getCaption()
			user1 = p.getUserName()
			for new_photo in new_photos:
				p2 = Photo(new_photo)
				cap2 = p2.getCaption()
				user2 = p2.getUserName()
				if user1 == user2 and (len(cap1)>0 and cap1 == cap2):
					is_duplicate = True
					num_duplicate += 1
					break
			if not is_duplicate:
				new_photos.append(photo)
				
		if num_duplicate > 0:
			self._event['photos'] = new_photos
			
		return num_duplicate
开发者ID:daifanxiang,项目名称:CityBeat,代码行数:27,代码来源:event.py

示例2: getWordList

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
	def getWordList(self, event):
		# word_list is a list of (word, freq)
		cp = CaptionParser(True)
		for photo in event['photos']:
			photo = Photo(photo)
			cp.insertCaption(photo.getCaption())
		return cp.getTopWords(-1, False)
开发者ID:daifanxiang,项目名称:CityBeat,代码行数:9,代码来源:corpus.py

示例3: _getTopWords

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
 def _getTopWords(self, k, stopword_removal=False):
     caption_parser = CaptionParser(stopword_removal=stopword_removal)
     for photo in self._event["photos"]:
         p = Photo(photo)
         caption = p.getCaption()
         if not caption is None:
             caption_parser.insertCaption(caption)
     return caption_parser.getTopWords(k)
开发者ID:oeddyo,项目名称:CityBeat,代码行数:10,代码来源:event_feature.py

示例4: _getTopWords

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
 def _getTopWords(self, k, stopword_removal=False):
     # get top words by counting the frequecy
     text_parser = TextParser(stopword_removal=stopword_removal)
     for photo in self._event['photos']:
         p = Photo(photo)
         caption = p.getCaption()
         if not caption is None:
             text_parser.insertCaption(caption)
     return text_parser.getTopWords(k)
开发者ID:juicyJ,项目名称:citybeat_online,代码行数:11,代码来源:event_feature_tweet.py

示例5: getCaptionPercentage

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
 def getCaptionPercentage(self):
     cap_number = 0
     photos = self._event["photos"]
     for photo in photos:
         photo = Photo(photo)
         cap_len = len(photo.getCaption())
         if cap_len > 0:
             cap_number += 1
     return cap_number * 1.0 / len(photos)
开发者ID:oeddyo,项目名称:CityBeat,代码行数:11,代码来源:event_feature.py

示例6: computeWordKLDivergenceWithByEddie

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
    def computeWordKLDivergenceWithByEddie(self, event):
        # this method calls the kl divergence computation by eddie's methods
        text1 = ''
        text2 = ''
        for photo in self._event['photos']:
            p = Photo(photo)
            text1 += ' '
            text1 += p.getCaption()

        if type(event) is types.DictType:
            pass
        else:
            event = event.toDict()

        for photo in event['photos']:
            p = Photo(photo)
            text2 += ' '
            text2 += p.getCaption()
        return kldiv(tokenize(text1), tokenize(text2))
开发者ID:juicyJ,项目名称:citybeat_online,代码行数:21,代码来源:event_feature_tweet.py

示例7: PhotoDistanceByCaption

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
        def PhotoDistanceByCaption(photo1, photo2):

            p1 = Photo(photo1)
            p2 = Photo(photo2)
            cap1 = p1.getCaption()
            cap2 = p2.getCaption()
            cp1 = TextParser(True)
            cp1.insertCaption(cap1)
            cp2 = TextParser(True)
            cp2.insertCaption(cap2)
            word_list1 = cp1.getTopWords(-1)
            word_list2 = cp2.getTopWords(-1)
            if len(word_list1) == 0 or len(word_list2) == 0:
                # unable to compare
                return None
            word_dict1 = {}
            for word, freq in word_list1:
                word_dict1[word] = freq
            word_dict2 = {}
            for word, freq in word_list2:
                word_dict2[word] = freq
            return kldiv(word_dict1, word_dict2)
开发者ID:juicyJ,项目名称:citybeat_online,代码行数:24,代码来源:event_feature_tweet.py

示例8: getAvgCaptionLen

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
 def getAvgCaptionLen(self):
     cap_number = 0
     cap_lens = 0
     photos = self._event["photos"]
     for photo in photos:
         photo = Photo(photo)
         cap_len = len(photo.getCaption())
         if cap_len > 0:
             cap_lens += cap_len
             cap_number += 1
     if cap_number == 0:
         return -1
     else:
         return 1.0 * cap_lens / cap_number
开发者ID:oeddyo,项目名称:CityBeat,代码行数:16,代码来源:event_feature.py

示例9: countHashtagsFromPhotosContainingTopKeywords

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
 def countHashtagsFromPhotosContainingTopKeywords(self, k=3):
     # count the number of hashtags of photos that associated with topwords
     # k is the number of top keywords
     # rank top keywords by counting their frequency
     word_photo_list = self.getTopKeywordsAndPhotos(k, 10000)
     cnt = [0] * k
     cnt2 = [0] * k
     for i in xrange(0, len(word_photo_list)):
         j = 0
         for photo in word_photo_list[i][2]:
             p = Photo(photo)
             cap = p.getCaption()
             j += 1
             cnt[i] += cap.count('#')
             # return the number of hashtags
         cnt[i] = cnt[i] * 1.0 / j
         # reteurn the number of photos
         cnt2[i] = len(word_photo_list[i][2])
     return [cnt, cnt2]
开发者ID:juicyJ,项目名称:citybeat_online,代码行数:21,代码来源:event_feature_tweet.py

示例10: PhotoInterface

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import getCaption [as 别名]
from photo_interface import PhotoInterface
from caption_parser import CaptionParser
from photo import Photo
from mongodb_interface import MongoDBInterface

import random


if __name__ == '__main__':
	pi = PhotoInterface()
	pi.setDB('citybeat')
	pi.setCollection('photos')
	
	mi = MongoDBInterface()
	mi.setDB('test_caption')
	mi.setCollection('captions')
	
	photos = pi.getAllDocuments()
	for photo in photos:
		i = random.randint(0,10)
		if i > 0:
			continue
		p = Photo(photo)
		cap = p.getCaption()
		if len(cap) > 0:
			cap = {'caption':cap}
			mi.saveDocument(cap)
开发者ID:daifanxiang,项目名称:CityBeat,代码行数:29,代码来源:extract_caption.py


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