def url_composer(self, query, service):
"""
This function is used to compose a url to call some web services, such as sparql endpoints.
:param query: is the string used in some rest calls.
:param service: type of service you request (dbpedia sparql endpoint)
:return url: the url composed
"""
# use quote_plus method from urllib to encode special character (must to do with web service)
query = urllib.quote_plus(query)
"""
The following if clause are differentiated by service requested Eg. 'dbpedia',..
but in all the cases url is composed using pre formatted string along with the query
"""
if service == 'dbpedia':
url = self.dbpedia_sparql_url + query + self.call_format_sparql
elif service == 'html':
url = self.html_format + query
else:
url = "ERROR"
return url
评论列表
文章目录