when I try to use jena-fuseki in Python IDE, I use SPARQLWrapper,the code is 
like this:
# encoding=utf-8

from SPARQLWrapper import SPARQLWrapper, JSON
from collections import OrderedDict

class JenaFuseki:
def __init__(self, endpoint_url='http://localhost:3030/dscout/query'):
self.sparql_conn = SPARQLWrapper(endpoint_url)

def get_sparql_result(self, query):
self.sparql_conn.setQuery(query)
self.sparql_conn.setReturnFormat(JSON)
return self.sparql_conn.query().convert()

@staticmethod
def parse_result(query_result):

try:
query_head = query_result['head']['vars']
            query_results = list()
for r in query_result['results']['bindings']:
temp_dict = OrderedDict()
for h in query_head:
temp_dict[h] = r[h]['value']
                query_results.append(temp_dict)
return query_head, query_results
except KeyError:
return None, query_result['boolean']

def print_result_to_string(self, query_result):
query_head, query_result = self.parse_result(query_result)

if query_head is None:
if query_result is True:
print ('Yes')
else:
print ('False')
print()
else:
for h in query_head:
print (h, ' '*5,)
print()
for qr in query_result:
for _, value in qr.iteritems():
print (value, ' ',)
print()

def get_sparql_result_value(self, query_result):
query_head, query_result = self.parse_result(query_result)
if query_head is None:
return query_result
else:
values = list()
for qr in query_result:
for _, value in qr.items():
values.append(value)
return values

# TODO test
if __name__ == '__main__':
fuseki = JenaFuseki()
my_query = """
    PREFIX : <http://dsc.nlp-bigdatalab.org:8086/>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

    SELECT * WHERE {
    :老年膀胱癌 rdf:type ?o.
    }
        """
result = fuseki.get_sparql_result(my_query)
    fuseki.print_result_to_string(result)
but I get this after running the code above:
Traceback (most recent call last):
  File 
"D:/zhou/Pycharms/KGQA-medicine-v1/kgqa/KB_query/jena_sparql_endpoint.py", line 
102, in <module>
    result = fuseki.get_sparql_result(my_query)
  File 
"D:/zhou/Pycharms/KGQA-medicine-v1/kgqa/KB_query/jena_sparql_endpoint.py", line 
22, in get_sparql_result
    return self.sparql_conn.query().convert()
  File 
"D:\ZhouProgram\Anaconda3\envs\pytorch\lib\site-packages\SPARQLWrapper\Wrapper.py",
 line 687, in query
    return QueryResult(self._query())
  File 
"D:\ZhouProgram\Anaconda3\envs\pytorch\lib\site-packages\SPARQLWrapper\Wrapper.py",
 line 663, in _query
    raise EndPointNotFound(e.read())
SPARQLWrapper.SPARQLExceptions.EndPointNotFound: EndPointNotFound: it was 
impossible to connect with the endpoint in that address, check if it is 
correct. 


Response:
b'Error 404: Not Found\n'


Process finished with exit code 1
 I think the main reason is that I have not grasped the code. so, may I get a 
similar tutorial about this?
but It is better for me to get the direct answer that explains why it does not 
work
thanks very much

Reply via email to