python - How can I properly serialize wikidata SPARQL queries answers? -


i have following example of querying wikidata via python's sparqlwrapper:

import rdflib, urllib sparqlwrapper import sparqlwrapper, json, xml, turtle, rdf, n3  rdflib import graph, namespace, uriref, rdf#, rdfs, literal      def graph_full(uri, f)     sparql = sparqlwrapper('https://query.wikidata.org/sparql')     sparql.setquery('''     prefix entity: <http://www.wikidata.org/entity/>      select ?predicate ?object {         <'''+urllib.unquote(uri).encode("utf8")+'''> ?predicate ?object .     } limit 100     ''')      sparql.setreturnformat(n3)     results = sparql.query().convert()     #print results.serialize()      print type(results)     g = graph()     g.parse(results)     print g      #g.serialize(f, format="n3")  if __name__ == '__main__':     graph_full("entity:q76", "wikidata/output.nt") 

i want serialize result of sparql query , save file. seems throw following error:

exception: unexpected type '<type 'instance'>' source    '<xml.dom.minidom.document instance @ 0x7fa11e3715a8>' 

using similar code against dbpedia sparql endpoints throws no erros.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -