本文整理汇总了Python中askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder.custom_query方法的典型用法代码示例。如果您正苦于以下问题:Python SparqlQueryBuilder.custom_query方法的具体用法?Python SparqlQueryBuilder.custom_query怎么用?Python SparqlQueryBuilder.custom_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder
的用法示例。
在下文中一共展示了SparqlQueryBuilder.custom_query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_sparql_query_from_json
# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import custom_query [as 别名]
def build_sparql_query_from_json(self, fromgraphs, variates, constraintes_relations,limit, send_request_to_tps=True):
"""
Build a sparql query from JSON constraints
"""
select = ' '.join(variates)
sqb = SparqlQueryBuilder(self.settings, self.session)
query_launcher = QueryLauncher(self.settings, self.session)
query = self.build_recursive_block('', constraintes_relations)
# if limit != None and limit > 0:
# query += ' LIMIT ' + str(limit)
if send_request_to_tps:
results = query_launcher.process_query(sqb.custom_query(fromgraphs, select, query).query)
else:
results = []
return results, sqb.custom_query(fromgraphs, select, query).query
示例2: build_sparql_query_from_json
# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import custom_query [as 别名]
def build_sparql_query_from_json(self,listEndpoints, typeEndpoints, fromgraphs, variates, constraintes_relations,limit, send_request_to_tps=True):
"""
Build a sparql query from JSON constraints
"""
if len(typeEndpoints) != len(listEndpoints):
self.log.warn("listEndpoints:"+str(listEndpoints))
self.log.warn("typeEndpoints:"+str(typeEndpoints))
raise ValueError("Devel error. Different size for List Endpoints and List type Endpoints. ")
select = ' '.join(variates)
sqb = SparqlQueryBuilder(self.settings, self.session)
query = self.build_recursive_block('', constraintes_relations)
# if limit != None and limit > 0:
# query += ' LIMIT ' + str(limit)
self.log.debug("============ build_sparql_query_from_json ========")
self.log.debug("type_endpoints:"+str(typeEndpoints))
self.log.debug("endpoints:"+str(listEndpoints))
self.log.debug("graphs"+str(fromgraphs))
extreq = False
typeQuery = ''
if send_request_to_tps:
if len(listEndpoints) == 0:
#raise ValueError("None endpoint are defined fo the current SPARLQ query !")
query_launcher = QueryLauncher(self.settings, self.session)
elif len(listEndpoints)==1:
self.log.debug("============ QueryLauncher ========")
endpoint = ''
type_endpoint='askomics'
if len(listEndpoints) == 1 :
endpoint = listEndpoints[0]
if typeEndpoints[0] != 'askomics':
extreq = True
query_launcher = QueryLauncher(self.settings, self.session,name = endpoint, endpoint = endpoint)
else:
self.log.debug("============ FederationQueryLauncher ========")
typeQuery = '(Federation)'
lE = []
iCount = 0
for i in range(0, len(listEndpoints)):
iCount+=1
end = {}
end['name'] = "endpoint"+str(iCount)
end['endpoint'] = listEndpoints[i]
end['askomics'] = (typeEndpoints[i] == 'askomics')
end['auth'] = 'Basic'
end['username'] = None
end['password'] = None
lE.append(end)
query_launcher = FederationQueryLauncher(self.settings, self.session,lE)
req = sqb.custom_query(fromgraphs, select, query,externalrequest=extreq).query
results = query_launcher.process_query(req)
else:
results = []
return results, sqb.custom_query(fromgraphs, select, query).query,typeQuery