예제 #1
0
def getOpenCalaisResultFromURL(url):
    API_KEY = openCalaisKeys[randint(0,6)]
    calais = Calais(API_KEY, submitter="python-calais demo")
    try:
        result = calais.analyze_url(url)
    except:
        result = None
    return result
예제 #2
0
def calaisify_main(options, args):
    m = persistence.MongoPersistence()
    calais = Calais(config.calais["api_key"], submitter="python-calais demo")
    for d in m.get_non_calaised_entries():
        l = short_url.has(d["title"])
        if len(l):
            for url in l:
                long_url = short_url.find_real(url)
                response = calais.analyze_url(long_url)
                response.print_summary()
                response.print_topics()
                response.print_entities()

        else:
            pass
예제 #3
0
def calais_test(request):
    content_url= request.REQUEST['content_url']
    if content_url == '':
        content_url='http://n-tv.de'
    calais = Calais('pc5v39x8sq3mh4mv9zm2ppre' , submitter="ask-a-sap-question")
    result= calais.analyze_url(content_url)
    result.print_summary()
    c_data= {
        "name"  :   "Barack",
    }
    for entity in result.entities:
        c_data[entity['name']]=entity['_type']
    lang= result.doc['meta']['language']
    return render_to_response('calais_test.html',{ 'text': content_url, 'calais_data': c_data, 'language': lang})
    
    
    
    
topicsList = []
entitiesList = []
#id,lastVisitTime,title,typedCount,url,visitCount

lines.pop(0)
for line in lines:
	line = line.rstrip('\n')
	data = line.split(',')

	#here we want to create topics objects and entities objects with values related to visit count

	visitCount = data[-1]
	url = data[-2].replace('\"','')
	print url
	try:
		result = calais.analyze_url(url)
		print result
		# print result.topics
		print ""
		# print result.entities
		# print topics
		# for topic in topics:
			# t = Topic(name, visitCount)
    		# topics.append(t)
    	# print entities
    	# for entity in entities:
    	# 	e = Entity(name, visitCount*val)
    	# 	entities.append(e)
	except ValueError:
		print "This URL is f****d up. You need to deal with this in the future: %s" % (url)
	# except: