https://github.com/secretshardul/dgraph-shakespeare-data
https://github.com/secretshardul/dgraph-shakespeare-data
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/secretshardul/dgraph-shakespeare-data
- Owner: secretshardul
- License: apache-2.0
- Created: 2020-10-31T16:19:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-02T05:04:59.000Z (over 5 years ago)
- Last Synced: 2025-09-10T06:02:04.182Z (11 months ago)
- Size: 32.5 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Complete works of Shakespeare: GraphQL schema and DGraph RDF dump

This repository holds the GraphQL schema and RDF file needed to setup a Shakespeare database on Slash.
This project is split across 2 repositories:
1. [**dgraph-shakespeare-data**](https://github.com/secretshardul/dgraph-shakespeare-data) (current repository): Contains the RDF file and GraphQL schema needed to setup DGraph.
2. [**complete-shakespeare**](https://github.com/secretshardul/complete-shakespeare): Contains code for Alexa skill for Shakespeare which consumes data from DGraph.
## Demo video
[](https://youtu.be/CpnAH6ymal8)
## Architecture

## Visualized schema

## Steps to push data on Slash
1. [Create a new instance on Slash](https://slash.dgraph.io/).
2. Set the backend mode to flexible and generate an admin API key.
3. Copy schema from [`schema.graphql`](/schema.graphql) and save it in the Slash console.
4. Upload `sql.rdf` to Slash using **live loader**. The command should have the absolute path to this folder.
```sh
docker run -it --rm -v /path/to/dgraph-shakespeare-data/sql.rdf:/tmp/sql.rdf dgraph/dgraph:v20.07-slash \
dgraph live --slash_grpc_endpoint=:443 -f /tmp/sql.rdf -t
```
## How was the data obtained?
These steps are for documentatary purposes. The final `schema.graphql` and `sql.rdf` files have already been prepared.
1. Run a MySQL instance on localhost using XAMPP and PHPMyAdmin.
2. Create new database and import data from `shakespeare.sql`. This is an improved version of the dump provided by Open Source Shakespeare. Unnecessary tables were removed, fields were renamed and foreign keys were added.
3. Run the **SQL to Dgraph migration tool** to obtain `schema.txt` and `sql.rdf` files. Add necessary credentials in `config.properties` file.
```sh
dgraph migrate --config config.properties --output_schema schema.txt --output_data sql.rdf --host 192.168.64.2
```
4. By looking at the database, design a `schema.graphql` file as per needs. Add types, authorization, inverse relations and search as necessary.
5. Some regular expression transformations were performed on the generated `sql.rdf` file to support all access patterns- adding ``, reverse relations etc. For complete steps, look at my [blog post](https://discuss.dgraph.io/t/sql-migration-tool-shenanigans-and-solutions/11229).
## Future work
1. In the SQL data, Paragraph table does not have a foreign key for Chapter table. `Paragraph` and `Chapter` graphQL types are yet to be linked.
2. `Quotes` table was separate and not linked to `Works`, `Character` or any other table. The graphQL types are not linked yet.
## Credits
1. [Open source Shakespeare by George Mason University](https://www.opensourceshakespeare.org/downloads/): For making their SQL database open source.
2. [Terence Eden](https://github.com/edent/Open-Source-Shakespeare) and [Richard Morrison](): For improvements in the original SQL dump.
3. [DGraph Labs and DGraph developer community](https://dgraph.io/)