def test_single_quotes_uri(self): test_uris = [ "http://dbpedia.org/resource/O'Reilly_Media", "http://dbpedia.org/resource/O'Reilly'_Media", ] for uri in test_uris: knowledge.name_for_uri(uri) knowledge.summary_for_uri(uri) knowledge.coordinates_for_uri(uri) knowledge.image_for_uri(uri) knowledge.aliases_for_uri(uri)
def test_double_quotes_uri(self): test_uris = [ 'http://dbpedia.org/resource/O"Reilly_Media', 'http://dbpedia.org/resource/O"Reilly"_Media' ] for uri in test_uris: knowledge.name_for_uri(uri) knowledge.summary_for_uri(uri) knowledge.coordinates_for_uri(uri) knowledge.image_for_uri(uri) knowledge.aliases_for_uri(uri)
def test_image_for_uri(self): self.mock_resp.read.return_value = b'{\n "head": {\n "vars": [ "image_url" ]\n } ,\n "results": {\n "bindings": [\n {\n "image_url": { "type": "uri" , "value": "http://upload.wikimedia.org/wikipedia/commons/7/7e/StarTrek_Logo_2007.JPG" }\n }\n ]\n }\n}\n' image_url = knowledge.image_for_uri( 'http://dbpedia.org/resource/Star_Trek') self.assertEqual( image_url, 'http://upload.wikimedia.org/wikipedia/commons/7/7e/StarTrek_Logo_2007.JPG' )
def test_image_for_uri(self): self.mock_resp.read.return_value = b'{\n "head": {\n "vars": [ "image_url" ]\n } ,\n "results": {\n "bindings": [\n {\n "image_url": { "type": "uri" , "value": "http://upload.wikimedia.org/wikipedia/commons/7/7e/StarTrek_Logo_2007.JPG" }\n }\n ]\n }\n}\n' image_url = knowledge.image_for_uri('http://dbpedia.org/resource/Star_Trek') self.assertEqual(image_url, 'http://upload.wikimedia.org/wikipedia/commons/7/7e/StarTrek_Logo_2007.JPG')
def get_company_profile(uri): """ Example return value:: {'assets': 'US$ 93.80 billion', 'contributions': [{ 'direct_amount': '0', 'direct_count': '0', 'employee_amount': '1602978.00', 'employee_count': '2274', 'id': '4148b26f6f1c437cb50ea9ca4699417a', 'name': 'Barack Obama (D)', 'party': 'D', 'state': '', 'total_amount': '1602978.00', 'total_count': '2274' }], 'party_contributions': { 'Democrats': ['5157', '6166411.11'], 'Other': ['831', '2022397.43'], 'Republicans': ['1114', '1998822.25'] }, 'employees': '53861', 'income': 'US$ 10.74 billion', 'name': 'Google', 'revenue': 'US$ 50.18 billion', 'subsidiaries': [{ 'http://dbpedia.org/resource/YouTube': { 'image': 'http://upload.wikimedia.org/wikipedia/commons/e/e8/Logo_Youtube.svg', 'name': 'YouTube' } }], 'symbol': 'GOOG', 'sources': ['Influence Explorer'] } """ # MISSING # Perhaps need to be using dbpedia live for this. #dbo:parentCompany ?children; #dbo:owningCompany ?owns; #dbo:board ?board; #dbo:developer ?products; #dbo:manufacturer ?moreproducts . uri = _quote(uri) query = ''' SELECT * WHERE {{ <{uri}> rdfs:label ?name; dbo:subsidiary ?subsidiaries; dbo:numberOfEmployees ?employees; dbp:symbol ?symbol; dbp:assets ?assets; dbp:netIncome ?income; dbp:revenue ?revenue . }} '''.format(uri=uri) results = _get_results(query) # Get the names for each subsidiary. subsidiaries = {} for subsidiary in [result['subsidiaries'] for result in results]: # This should be combined into a single query. subsidiaries[subsidiary] = {'name': name_for_uri(subsidiary), 'image': image_for_uri(subsidiary)} profile = None if results: profile = results[0] profile['subsidiaries'] = subsidiaries services.process(profile, { 'influence_explorer': [ 'recipients_for_organization', 'parties_for_organization' ] }) return profile
def get_company_profile(uri): """ Example return value:: {'assets': 'US$ 93.80 billion', 'contributions': [{ 'direct_amount': '0', 'direct_count': '0', 'employee_amount': '1602978.00', 'employee_count': '2274', 'id': '4148b26f6f1c437cb50ea9ca4699417a', 'name': 'Barack Obama (D)', 'party': 'D', 'state': '', 'total_amount': '1602978.00', 'total_count': '2274' }], 'party_contributions': { 'Democrats': ['5157', '6166411.11'], 'Other': ['831', '2022397.43'], 'Republicans': ['1114', '1998822.25'] }, 'employees': '53861', 'income': 'US$ 10.74 billion', 'name': 'Google', 'revenue': 'US$ 50.18 billion', 'subsidiaries': [{ 'http://dbpedia.org/resource/YouTube': { 'image': 'http://upload.wikimedia.org/wikipedia/commons/e/e8/Logo_Youtube.svg', 'name': 'YouTube' } }], 'symbol': 'GOOG', 'sources': ['Influence Explorer'] } """ # MISSING # Perhaps need to be using dbpedia live for this. #dbo:parentCompany ?children; #dbo:owningCompany ?owns; #dbo:board ?board; #dbo:developer ?products; #dbo:manufacturer ?moreproducts . uri = _quote(uri) query = ''' SELECT * WHERE {{ <{uri}> rdfs:label ?name; dbo:subsidiary ?subsidiaries; dbo:numberOfEmployees ?employees; dbp:symbol ?symbol; dbp:assets ?assets; dbp:netIncome ?income; dbp:revenue ?revenue . }} '''.format(uri=uri) results = _get_results(query) # Get the names for each subsidiary. subsidiaries = {} for subsidiary in [result['subsidiaries'] for result in results]: # This should be combined into a single query. subsidiaries[subsidiary] = { 'name': name_for_uri(subsidiary), 'image': image_for_uri(subsidiary) } profile = None if results: profile = results[0] profile['subsidiaries'] = subsidiaries services.process( profile, { 'influence_explorer': ['recipients_for_organization', 'parties_for_organization'] }) return profile