本文整理汇总了Python中askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder类的典型用法代码示例。如果您正苦于以下问题:Python SparqlQueryBuilder类的具体用法?Python SparqlQueryBuilder怎么用?Python SparqlQueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SparqlQueryBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: positionable_attr
def positionable_attr(self):
"""
Return the positionable attributes in common between two positionable entity
"""
#FIXEME: Rewrite this ugly method
body = self.request.json_body
data = {}
sqb = SparqlQueryBuilder(self.settings, self.request.session)
ql = QueryLauncher(self.settings, self.request.session)
# Check if the two entity are positionable
positionable1 = ql.process_query(sqb.get_if_positionable(body['node']).query)
positionable2 = ql.process_query(sqb.get_if_positionable(body['node']).query)
if positionable1 == 0 or positionable2 == 0:
data['error'] = 'not positionable nodes'
return data
results = ql.process_query(sqb.get_common_positionable_attributes(body['node'], body['second_node']).query)
self.log.debug(results)
data['results'] = {}
list_pos_attr = []
for elem in results:
if elem['pos_attr'] not in list_pos_attr:
list_pos_attr.append(elem['pos_attr'].replace("http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#", ""))
for elem in list_pos_attr:
data['results'][elem] = False not in [bool(int(p['status'])) for p in results if p['pos_attr'] == "http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#"+elem]
return data
开发者ID:cbettemb,项目名称:askomics,代码行数:35,代码来源:ask_view.py
示例2: empty
def empty(self):
#empty database
sqb = SparqlQueryBuilder(self.settings, self.request.session)
ql = QueryLauncher(self.settings, self.request.session)
namedGraphs = self.list_named_graphs()
for graph in namedGraphs:
ql.execute_query(sqb.get_delete_query_string(graph).query)
开发者ID:cbettemb,项目名称:askomics,代码行数:7,代码来源:interface_tps.py
示例3: insert_metadatas
def insert_metadatas(self,accessL):
"""
Insert the metadatas into the parent graph
"""
self.log.debug('--- insert_metadatas ---')
sqb = SparqlQueryBuilder(self.settings, self.session)
query_laucher = QueryLauncher(self.settings, self.session)
valAcces = 'public' if accessL else 'private'
ttl = '<' + self.graph + '> prov:generatedAtTime "' + self.timestamp + '"^^xsd:dateTime .\n'
ttl += '<' + self.graph + '> dc:creator "' + self.session['username'] + '" .\n'
ttl += '<' + self.graph + '> :accessLevel "' + valAcces + '" .\n'
ttl += '<' + self.graph + '> foaf:Group "' + self.session['group'] + '" .\n'
ttl += '<' + self.graph + '> prov:wasDerivedFrom "' + self.name + '" .\n'
ttl += '<' + self.graph + '> dc:hasVersion "' + get_distribution('Askomics').version + '" .\n'
ttl += '<' + self.graph + '> prov:describesService "' + os.uname()[1] + '" .\n'
if self.is_defined("askomics.endpoint"):
ttl += '<' + self.graph + '> prov:atLocation "' + self.get_param("askomics.endpoint") + '" .\n'
else:
raise ValueError("askomics.endpoint does not exit.")
sparql_header = sqb.header_sparql_config('')
query_laucher.insert_data(ttl, self.graph, sparql_header)
开发者ID:askomics,项目名称:askomics,代码行数:28,代码来源:SourceFile.py
示例4: compare_file_to_database
def compare_file_to_database(self, headers):
""" Ask the database to compare the headers of a file to convert to the corresponding class in the database """
curr_entity = headers[0]
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
sparql_template = self.get_template_sparql(self.ASKOMICS_get_class_info_from_abstraction_queryFile)
query = sqb.load_from_file(sparql_template, {"#nodeClass#": curr_entity}).query
results = ql.process_query(query)
if results == []:
return [], headers, []
bdd_relations, new_headers, missing_headers, present_headers = [], [], [], []
for result in results:
bdd_relation = result["relation"].replace(self.get_param("askomics.prefix"), "").replace("has_", "")
bdd_relations.append(bdd_relation)
if bdd_relation not in headers:
self.log.warning('Relation "%s" not found in tables columns: %s.', bdd_relation, repr(headers))
missing_headers.append(bdd_relation)
for header in headers:
if header != curr_entity:
if header not in bdd_relations:
self.log.info('Adding column "%s".', header)
new_headers.append(header)
elif header not in missing_headers:
present_headers.append(header)
return missing_headers, new_headers, present_headers
开发者ID:odameron,项目名称:askomics,代码行数:26,代码来源:SourceFileConvertor.py
示例5: deleteMoState
def deleteMoState(self,urimo):
self.log.debug(' ***** Delete module '+urimo+' on TPS ***** ')
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
ql.execute_query(sqb.prepare_query(
"""
DELETE WHERE { GRAPH <"""+self.graph_modules+"""> { <"""+urimo+"""> ?p ?o } }
"""
).query)
开发者ID:ofilangi,项目名称:askomics,代码行数:10,代码来源:ModulesManager.py
示例6: empty_database
def empty_database(self):
"""
Delete all triples in the triplestore
"""
self.log.debug("=== DELETE ALL TRIPLES ===")
sqb = SparqlQueryBuilder(self.settings, self.request.session)
ql = QueryLauncher(self.settings, self.request.session)
ql.execute_query(sqb.get_delete_query_string().query)
开发者ID:Piezoid,项目名称:askomics,代码行数:11,代码来源:ask_view.py
示例7: test_print_ids
def test_print_ids(self):
from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder
request = testing.DummyRequest()
sqb = SparqlQueryBuilder(self.settings, request.session)
graph = {'limit': 30, 'return_only_query': False, 'filter_cat': [], 'constraint': [{'type': 'node', 'id': 'entity1', 'uri': 'http://www.semanticweb.org/irisa/ontologies/2016/1/igepp-ontology#entity'}], 'filter_str': [{'id': 'entity1', 'value': 'xxxx'}], 'display': [{'id': 'entity1'}, {}], 'export': 0, 'filter_num': [], 'uploaded': ''}
query = sqb.load_from_query_json(graph).query
self.assertIn('?entity1 a :entity .\n\tFILTER (regex(str(?entity1), "xxxx", "i")) .', query)
开发者ID:odameron,项目名称:askomics,代码行数:12,代码来源:sparql_test.py
示例8: list_named_graphs
def list_named_graphs(self):
sqb = SparqlQueryBuilder(self.settings, self.request.session)
ql = QueryLauncher(self.settings, self.request.session)
res = ql.execute_query(sqb.get_list_named_graphs().query)
namedGraphs = []
for indexResult in range(len(res['results']['bindings'])):
namedGraphs.append(res['results']['bindings'][indexResult]['g']['value'])
return namedGraphs
开发者ID:cbettemb,项目名称:askomics,代码行数:12,代码来源:interface_tps.py
示例9: launch_query
def launch_query(self):
""" Converts the constraints table created by the graph to a sparql query, send it to the database and compile the results"""
data = {}
body = self.request.json_body
export = bool(int(body['export']))
sqb = SparqlQueryBuilder(self.settings, self.request.session)
return_only_query = bool(int(body['return_only_query']))
if body['uploaded'] != '':
if export:
query = body['uploaded'].replace('LIMIT 30', 'LIMIT 10000')
else:
query = body['uploaded']
else:
query = sqb.load_from_query_json(body).query
if return_only_query:
data['query'] = query
return data
ql = QueryLauncher(self.settings, self.request.session)
rb = ResultsBuilder(self.settings, self.request.session)
results = ql.process_query(query)
if export:
data['file'] = ql.format_results_csv(rb.build_csv_table(results))
else:
entity_name_list, entity_list_attributes = rb.organize_attribute_and_entity(results, body['constraint'])
data['results_entity_name'] = entity_name_list
data['results_entity_attributes'] = entity_list_attributes
data['results'] = [
{
k: res[k].replace(self.settings["askomics.prefix"], '')
for k in res.keys()
}
for res in results
]
self.log.debug("== results ==")
for elt in results:
self.log.debug(elt)
# data['query'] = query
return data
开发者ID:odameron,项目名称:askomics,代码行数:50,代码来源:ask_view.py
示例10: get_attributes_of
def get_attributes_of(self, uri):
"""
Get all attributes of a node class (identified by his uri). These
attributes are known thanks to the domain knowledge of your RDF database.
:param uri: Uri of the node class
:type uri: str
:return: All attributes of a node class
:rtype: Attribute list
"""
self.log.debug(" =========== TripleStoreExplorer:get_attributes_of ===========")
attributes = []
results = []
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
fragment = uri.rsplit('#', 1)[-1]
parent = fragment + str(self.get_new_id(fragment))
# Send a request to know all the neighbors of a node (from uri).
sparql_template = self.get_template_sparql(self.ASKOMICS_neighbor_query_file)
query = sqb.load_from_file(sparql_template, {
"nodeClass": '<%s>' % uri,
"neighborClass": "?nodeUri"
}).query
results = (ql.process_query(query))
for result in results:
neighbor_uri = result["relationUri"]
if 'nodeLabel' in result:
neighbor_label = result["nodeLabel"]
else:
neighbor_label = result["relationLabel"]
neighbor_id = neighbor_label + str(self.get_new_id(neighbor_label))
if self.has_setting(result["nodeUri"], 'attribute') or self.has_setting(neighbor_uri, 'attribute'):
attributes.append(
Attribute(neighbor_id,
neighbor_uri,
result["nodeUri"],
neighbor_label,
parent)
)
return attributes
开发者ID:Piezoid,项目名称:askomics,代码行数:48,代码来源:TripleStoreExplorer.py
示例11: delete_graph
def delete_graph(self):
"""
Delete triples from a list of graph
"""
self.log.debug("=== DELETE SELECTED GRAPHS ===")
sqb = SparqlQueryBuilder(self.settings, self.request.session)
ql = QueryLauncher(self.settings, self.request.session)
graphs = self.request.json_body['namedGraphs']
for graph in graphs:
self.log.debug("--- DELETE GRAPH : %s", graph)
ql.execute_query(sqb.get_drop_named_graph(graph).query)
#delete metadatas
ql.execute_query(sqb.get_delete_metadatas_of_graph(graph).query)
开发者ID:cbettemb,项目名称:askomics,代码行数:16,代码来源:ask_view.py
示例12: moStateOnTPS
def moStateOnTPS(self):
'''
check if module files state is saved on the TPS.
if not all modules files are saved with the unchecked status !
'''
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
results = ql.process_query(sqb.build_query_on_the_fly({
'select': '?uri ?module ?comment ?version ?graph ?state',
'from' : [self.graph_modules],
'query': '{\n'+
'?uri rdfs:label ?module .\n'+
'?uri rdfs:comment ?comment .\n'+
'?uri :module_version ?version .\n'+
'?uri :module_state ?state .\n'+
'OPTIONAL { ?uri :module_graph ?graph . } \n'+
'}\n'
}, True).query)
self.log.debug(' ***** module on TPS ***** ')
listMoOnTps = {}
for result in results:
result['checked'] = (result['state'] == "ok")
result['wait'] = (result['state'] == "wait")
listMoOnTps[result['module']] = 0
self.log.debug('module : '+result['module'])
#=======================*************** A ENLEVER *********=======================================
#pour debugger
#if result['wait'] :
# result['wait'] = False
#==============================================================
self.log.debug(' ***** check Available Modules ***** ')
requestAgain = False
for mo in self.moduleFiles:
self.log.debug(" --> module "+mo);
if mo not in listMoOnTps:
self.log.debug(" --====== > new module < =======");
self.importMoSate(self.moduleFiles[mo],'off')
requestAgain = True
if requestAgain :
return False
return results
开发者ID:ofilangi,项目名称:askomics,代码行数:47,代码来源:ModulesManager.py
示例13: get_metadatas
def get_metadatas(self):
"""
Create metadatas and insert them into AskOmics main graph.
"""
self.log.debug("====== INSERT METADATAS ======")
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
ttlMetadatas = "<" + self.metadatas['graphName'] + "> " + "prov:generatedAtTime " + '"' + self.metadatas['loadDate'] + '"^^xsd:dateTime .\n'
ttlMetadatas += "<" + self.metadatas['graphName'] + "> " + "dc:creator " + '"' + self.metadatas['username'] + '"^^xsd:string .\n'
ttlMetadatas += "<" + self.metadatas['graphName'] + "> " + "prov:wasDerivedFrom " + '"' + self.metadatas['fileName'] + '"^^xsd:string .\n'
ttlMetadatas += "<" + self.metadatas['graphName'] + "> " + "dc:hasVersion " + '"' + self.metadatas['version'] + '"^^xsd:string .\n'
ttlMetadatas += "<" + self.metadatas['graphName'] + "> " + "prov:describesService " + '"' + self.metadatas['server'] + '"^^xsd:string .'
sparqlHeader = sqb.header_sparql_config("")
ql.insert_data(ttlMetadatas, self.get_param("askomics.graph"), sparqlHeader)
开发者ID:cbettemb,项目名称:askomics,代码行数:17,代码来源:SourceFile.py
示例14: get_list_named_graphs
def get_list_named_graphs(self):
"""
Return a list with all the named graphs.
"""
self.log.debug("=== LIST OF NAMED GRAPHS ===")
sqb = SparqlQueryBuilder(self.settings, self.request.session)
ql = QueryLauncher(self.settings, self.request.session)
res = ql.execute_query(sqb.get_list_named_graphs().query)
namedGraphs = []
for indexResult in range(len(res['results']['bindings'])):
namedGraphs.append(res['results']['bindings'][indexResult]['g']['value'])
return namedGraphs
开发者ID:cbettemb,项目名称:askomics,代码行数:18,代码来源:ask_view.py
示例15: has_category
def has_category(self, entity, category, uri_category):
"""
Get different categories for a node class.
:param entity : Name of the entity associated with the node
:param uri: Name of the node
:type uri: str
:return: List of categories
:rtype: list
"""
self.log.debug(" =========== TripleStoreExplorer:has_category ===========[ entity:"+ entity + ", category:"+ category+"]")
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
sparql_template = self.get_template_sparql(self.ASKOMICS_has_category_query_file)
query = sqb.load_from_file(sparql_template, {"#nodeClass#": uri_category, "#category#" : category, "#entity#" : entity}).query
results = ql.process_query(query)
return [res["label"] for res in results]
开发者ID:odameron,项目名称:askomics,代码行数:19,代码来源:TripleStoreExplorer.py
示例16: existing_relations
def existing_relations(self):
"""
Fetch from triplestore the existing relations if entities of the same name exist
:return: a List of relation names
:rtype: List
"""
self.log.debug("existing_relations")
existing_relations = []
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
sparql_template = self.get_template_sparql(self.ASKOMICS_get_class_info_from_abstraction_queryFile)
query = sqb.load_from_file(sparql_template, {"nodeClass": self.headers[0]}).query
results = ql.process_query(query)
return existing_relations
开发者ID:cbettemb,项目名称:askomics,代码行数:19,代码来源:SourceFile.py
示例17: importMoSate
def importMoSate(self,mo,state):
'''
Import in the TPS all triplet necessary to defined an askomics module
'''
rdf = ":"+self.escape['entity'](mo['module'])+" rdfs:label " + self.escape['text'](mo['module'])+";\n"
rdf += " rdfs:comment " + self.escape['text'](mo['comment'])+";\n"
rdf += " :module_version " + self.escape['text'](mo['version'])+";\n"
rdf += " :module_state " + self.escape['text'](state)+""
if (state == 'ok'):
rdf += ";\n :module_graph " + '<'+mo['graph']+'>.\n'
else:
rdf += ".\n"
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
sh = sqb.header_sparql_config('')
ql.insert_data(rdf, self.graph_modules , sh)
开发者ID:ofilangi,项目名称:askomics,代码行数:19,代码来源:ModulesManager.py
示例18: load_data_from_file
def load_data_from_file(self, fp, urlbase):
"""
Load a locally created ttl file in the triplestore using http (with load_data(url)) or with the filename for Fuseki (with fuseki_load_data(fp.name)).
:param fp: a file handle for the file to load
:param urlbase:the base URL of current askomics instance. It is used to let triple stores access some askomics temporary ttl files using http.
:return: a dictionnary with information on the success or failure of the operation
"""
if not fp.closed:
fp.flush() # This is required as otherwise, data might not be really written to the file before being sent to triplestore
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
graphName = "askomics:graph:" + self.name + '_' + self.timestamp
self.metadatas['graphName'] = graphName
ttlNamedGraph = "<" + graphName + "> " + "rdfg:subGraphOf" + " <" + self.get_param("askomics.graph") + "> ."
sparqlHeader = sqb.header_sparql_config("")
ql.insert_data(ttlNamedGraph, self.get_param("askomics.graph"), sparqlHeader)
url = urlbase+"/ttl/"+os.path.basename(fp.name)
self.log.debug(url)
data = {}
try:
if self.is_defined("askomics.file_upload_url"):
queryResults = ql.upload_data(fp.name, graphName)
self.metadatas['server'] = queryResults.headers['Server']
self.metadatas['loadDate'] = self.timestamp
else:
queryResults = ql.load_data(url, graphName)
self.metadatas['server'] = queryResults.info()['server']
self.metadatas['loadDate'] = self.timestamp
data['status'] = 'ok'
except Exception as e:
self._format_exception(e, data=data)
finally:
if self.settings["askomics.debug"]:
data['url'] = url
else:
os.remove(fp.name) # Everything ok, remove temp file
self.get_metadatas()
return data
开发者ID:cbettemb,项目名称:askomics,代码行数:43,代码来源:SourceFile.py
示例19: build_sparql_query_from_json
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
开发者ID:ofilangi,项目名称:askomics,代码行数:20,代码来源:TripleStoreExplorer.py
示例20: has_setting
def has_setting(self, uri, setting):
"""
Look for a specific setting (see displaySetting in your domain knowledge) for a node class.
:param uri: Name of the node
:param setting: Name of your setting
:type uri: str
:type setting: str
:return: List of results found for a setting
:rtype: dict
"""
self.log.debug(" =========== TripleStoreExplorer:has_setting =========== [ uri:"+ uri + ", setting:"+ setting+"]")
sqb = SparqlQueryBuilder(self.settings, self.session)
ql = QueryLauncher(self.settings, self.session)
sparql_template = self.get_template_sparql(self.ASKOMICS_setting_query_file)
query = sqb.load_from_file(sparql_template, {"#nodeClass#": uri, "#setting#": setting}).query
results = ql.process_query(query)
return [res[setting] for res in results]
开发者ID:odameron,项目名称:askomics,代码行数:20,代码来源:TripleStoreExplorer.py
注:本文中的askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论