2

I mean that I want to use rdflib to query WIkidata in my local computer, but rdflib.Graph() need to parse the namespace firstly.THerefore, How can I get the Wikidata NameSpace to use the rdflib local code?

zqhead
  • 21
  • 2
  • Sorry but you're going to need to further refine what you're actually after. I can't really make sense of "rdflib.Graph() need[s] to parse the namespace firstly". If you have a chunk of Wikidata in valid RDF, RDFlib can easily parse it into a Graph(). – Nicholas Car Aug 06 '20 at 03:47
  • Also, not really sure what "How can I get the Wikidata NameSpace to use the rdflib local code?" means! A namespace is a URI prefix that just is, it doesn't "use" anything. Perhaps you mean something like "how can I use another namespace for Wikidata data that I have stored locally"? – Nicholas Car Aug 06 '20 at 03:57
  • I guess he means something similar to what is feasable with dbpedia: graph = rdflib.Graph() graph.load('http://dbpedia.org/resource/Semantic_Web') so what happens if you do? graph = rdflib.Graph() graph.load('https://www.wikidata.org/???/Q54837') – ChrisDelClea Dec 24 '20 at 15:17

1 Answers1

0

I think the goal was:

from rdflib import Graph

g = Graph()
g.parse('wikidata-link')

or

g.load('wikidata-link')

I haven't spent much time on it, but here are my tryouts, just to kinda complete the question and maybe find an answer.

Some of the following possible versions have resulted in some kind of error ranging from, 'timeout', 'not well formed (invalid token)', Typeerrors, '.. not a valid NCName ...' up to missing plugin errors when getting 'text/html' or '.../json' back. I marked what worked and what didn't.

CODE SAMPLES I'VE TRIED

g.parse('https://www.wikidata.org/wiki/Special:EntityData/Q42.n3') #  WORKS
g.parse('https://www.wikidata.org/wiki/Special:EntityData/Q42.json') #  FAILS
g.parse('https://www.wikidata.org/wiki/Special:EntityData/Q42.ttl') #  WORKS
g.parse('https://www.wikidata.org/wiki/Special:EntityData/Q42.rdf') #  FAILS
g.parse('https://www.wikidata.org/wiki/Special:EntityData/Q64') #  FAILS
g.parse('https://www.wikidata.org/wiki/Q42') #  FAILS
g.load('https://www.wikidata.org/wiki/Special:EntityData/Q42.n3') #  FAILS
g.load('https://www.wikidata.org/wiki/Special:EntityData/Q42.json') #  FAILS
g.load('https://www.wikidata.org/wiki/Special:EntityData/Q42.ttl') #  FAILS
g.load('https://www.wikidata.org/wiki/Special:EntityData/Q42.rdf') #  FAILS
g.load('https://www.wikidata.org/wiki/Special:EntityData/Q42') #  FAILS
g.load('https://www.wikidata.org/wiki/Q42') #  FAILS

I tried these out based on Wikidata Access

VERSIONS USED

RDFLib 6.1.1 Python 3.10.1

Last additional thoughts

You could query wikidata via the endpoint and build your rdflib graph from there.