liveBook · Manning

Graph database

As explained in Natural Language Processing in Action, Second Edition

A graph database is a database system that stores entities and their relationships as graph structures for graph-oriented querying and analysis.

A graph database organizes facts as entities connected by relationships, making questions about linked information natural to query. Graph-oriented languages include SPARQL, Cypher, and AQL. section 11.9

Wikidata provides a concrete graph: entities use Q-IDs, relationships use property P-IDs, and SPARQL retrieves connected facts across many entities. Its graph contains more than 100 million data items. section 11.9

Finding coauthors through connected facts

A SPARQL query can start with Timnit Gebru, find a notable scholarly article, and follow its author property to retrieve Timnit Gebru, Margaret Mitchell, and Emily M. Bender. section 11.9

>>> def get_wikidata_qid(wikiarticle, wikisite="enwiki"):
...     WIKIDATA_URL='https://www.wikidata.org/w/api.php'
...     resp = requests.get(WIKIDATA_URL, timeout=5, params={
...         'action': 'wbgetentities',
...         'titles': wikiarticle,
...         'sites': wikisite,
...         'props': '',
...         'format': 'json'
...     }).json()
...     return list(resp['entities'])[0]

>>> tg_qid = get_wikidata_qid('Timnit Gebru')
>>> tg_qid
'Q59753117'

This Python helper resolves a Wikipedia article name to its Wikidata entity identifier, providing the starting point for graph queries. section 11.9

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains entity identifiers, property identifiers, and connected Wikidata queries, while deferring broader database trade-offs to exercises.
Examples
Uses Wikidata queries about Timnit Gebru, a scholarly article, its authors, and NetworkX-to-pandas graph traversal exercises.
What you can do after
Operate Wikidata’s REST API and SPARQLWrapper to retrieve entity identifiers, scholarly works, and connected authors.
How it connects
Connects graph databases to knowledge graphs, RDF, SPARQL, Cypher, AQL, relational databases, and network analysis.

Also explained in

Compare how 4 books explain graph database →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.