sparqlwrapper

listOfDict to RDF conversion in python targeting Apache Jena Fuseki

…衆ロ難τιáo~ 提交于 2021-01-29 17:53:19
问题 To store some data in Apache Jena from python I'd like to have a generic conversion from a list of Dicts to RDF and possibly back on query. For the list of Dict to RDF part I tried implementing "insertListofDicts" (see below) and tested it with "testListOfDictInsert" (see below). The result is below which leads to a 400: Bad Request when tried with an Apache Jena Fuseki server. What needs to be fixed for simple string types - and may be for other primitive Python types to get this working?

How can i get the Fuseki API via SPARQLWrapper to properly report a detailed error message?

南楼画角 提交于 2021-01-29 05:40:49
问题 As outlined:in https://github.com/WolfgangFahl/DgraphAndWeaviateTest/blob/master/storage/sparql.py and https://github.com/WolfgangFahl/DgraphAndWeaviateTest/blob/master/tests/testSPARQL.py I tried to allow for a "round trip" operation between python list of dicts and Jena/SPARQL based storage. The approach performs very well for my usecase and after trying it out for a while i get into more details that need to be addressed. The stackoverflow question listOfDict to RDF conversion in python

URLError with SPARQLWrapper at sparql.query().convert()

和自甴很熟 提交于 2021-01-28 00:21:16
问题 I try a small python script to test my SPARQL request. However, just the next simple code doesn't work. from SPARQLWrapper import SPARQLWrapper, JSON import rdflib #connect to the sparql point sparql = SPARQLWrapper("http://localhost:3030/sparql") #SPARQL request sparql.setQuery(""" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX

How to query Wikidata for “also known as”

给你一囗甜甜゛ 提交于 2020-05-27 04:32:12
问题 I would like to know how to query Wikidata by using the alias ("also known as"). Right now I am trying SELECT ?item WHERE { ?item rdfs:aliases ?alias. FILTER(CONTAINS(?alias, "Angela Kasner"@en)) } LIMIT 5 This is simply a query that works if I replace rdfs:aliases by rdfs:labels . I am trying this, because Help:Aliases says that aliases are searchable in the same way as labels, but I can't find any other resource on that nor can I find an example. 回答1: This query might be helpful for someone

How to INSERT all triples from an RDFlib graph into another repository without iterating through every triple?

橙三吉。 提交于 2020-01-06 21:58:54
问题 This question is related to What URI to use for a Sesame repository while executing a SPARQL ADD query. I'm trying to INSERT all triples from a Sesame repository into another (Dydra). There are a couple of ways to do it, such as using SERVICE clause or Dydra's GUI. However, Dydra restricts the use of SERVICE and I want an efficient way to insert the data programmatically. This is the code I have right now: queryStringUpload = 'INSERT {?s ?p ?o} WHERE GRAPH %s {?s ?p ?o}' % dataGraph sparql =

Can't get INSERT to work in SPARQLWrapper

别说谁变了你拦得住时间么 提交于 2020-01-04 06:58:14
问题 I've been trying to get SPARQLWrapper to insert a simple triple into GraphDB with no success. I have no trouble with select queries. Here's Python test code that fails: db = sparqlw.SPARQLWrapper(endpoint) query = ''' INSERT {<http://example.com/123456789876> a owl:Thing .} WHERE {} ''' db.setQuery(query) db.method = sparqlw.POST db.setReturnFormat(sparqlw.JSON) db.queryType= sparqlw.INSERT result = db.query() It returns these errors: "urllib.error.HTTPError: HTTP Error 400: Bad Request" and

constructing graph using rdflib for the outputs from sparql 'SELECT' query with sparqlWrapper

廉价感情. 提交于 2019-12-24 05:59:46
问题 I am trying to construct a graph out of the results from SPARQL query. For the purpose of the query construction, I'm using SparqlWrapper and DBpedia as the knowledge base. from SPARQLWrapper import SPARQLWrapper, JSON from rdflib import Namespace, Graph, URIRef from rdflib.namespace import RDF, FOAF g = Graph() name = "Asturias" #labelName = URIRef("<http://dbpedia.org/resource/" + name +">") sparql = SPARQLWrapper("http://dbpedia.org/sparql") sparql.setQuery(""" PREFIX rdfs: <http://www.w3

constructing graph using rdflib for the outputs from sparql 'SELECT' query with sparqlWrapper

↘锁芯ラ 提交于 2019-12-24 05:59:21
问题 I am trying to construct a graph out of the results from SPARQL query. For the purpose of the query construction, I'm using SparqlWrapper and DBpedia as the knowledge base. from SPARQLWrapper import SPARQLWrapper, JSON from rdflib import Namespace, Graph, URIRef from rdflib.namespace import RDF, FOAF g = Graph() name = "Asturias" #labelName = URIRef("<http://dbpedia.org/resource/" + name +">") sparql = SPARQLWrapper("http://dbpedia.org/sparql") sparql.setQuery(""" PREFIX rdfs: <http://www.w3

How to create a parameterised query in SPARQLWrapper in python

∥☆過路亽.° 提交于 2019-12-24 00:44:32
问题 I am using the following sparql query using SPARQLWrapper as follows. from SPARQLWrapper import SPARQLWrapper, JSON sparql = SPARQLWrapper("http://live.dbpedia.org/sparql") sparql.setReturnFormat(JSON) sparql.setQuery(" ASK { dbc:Meteorological_concepts skos:broader{1,7} dbc:Medicine } ") results = sparql.query().convert() print(results['boolean']) This query returns False which is the correct output. I try to modify the aforementioned code by convering the query to a parameterised query (by