def get_profile(uri): types = types_for_uri(uri) if 'http://dbpedia.org/ontology/Company' in types: profile = get_company_profile(uri) profile['type'] = 'company' return profile elif 'http://dbpedia.org/ontology/Place' in types: profile = get_place_profile(uri, types) profile['type'] = 'place' return profile else: return {}
def test_types_for_uri(self): self.mock_resp.read.return_value = b''' { "head": { "vars": [ "type" ] } , "results": { "bindings": [ { "type": { "type": "uri" , "value": "http://schema.org/Organization" } } , { "type": { "type": "uri" , "value": "http://dbpedia.org/ontology/Company" } } ] } } ''' types = knowledge.types_for_uri('http://dbpedia.org/resource/Google') self.assertEqual(types, ['http://schema.org/Organization', 'http://dbpedia.org/ontology/Company'])
def test_types_for_uri(self): self.mock_resp.read.return_value = b''' { "head": { "vars": [ "type" ] } , "results": { "bindings": [ { "type": { "type": "uri" , "value": "http://schema.org/Organization" } } , { "type": { "type": "uri" , "value": "http://dbpedia.org/ontology/Company" } } ] } } ''' types = knowledge.types_for_uri('http://dbpedia.org/resource/Google') self.assertEqual(types, [ 'http://schema.org/Organization', 'http://dbpedia.org/ontology/Company' ])