diff --git a/.gitignore b/.gitignore index e656afe21..4a3725b23 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,8 @@ **/dist/ **/.env.local +# The data persisted from running samples should not end up in the repo +**/samples/**/data/ + # TypeScript build cache manifests *.tsbuildinfo \ No newline at end of file diff --git a/samples/README.md b/samples/README.md index 4699fe97a..365d239ce 100644 --- a/samples/README.md +++ b/samples/README.md @@ -10,3 +10,11 @@ sample data and shows how to configure Graph Explorer to connect to it automatically with a default connection. [Air Routes](./air_routes/readme.md) + +## Social Network with Blazegraph + +This sample uses Blazegraph as the RDF database pre-loaded with sample social +network data and shows how to configure Graph Explorer to connect to it +automatically with a default connection. + +[Blazegraph](./blazegraph/readme.md) diff --git a/samples/blazegraph/README.md b/samples/blazegraph/README.md new file mode 100644 index 000000000..a5ec6c167 --- /dev/null +++ b/samples/blazegraph/README.md @@ -0,0 +1,53 @@ +# Blazegraph Sample + +| Database | Query Language | Data Source | +| ------------ | -------------- | ----------- | +| [Blazegraph] | [SPARQL] | Sample RDF | + +[Blazegraph]: https://blazegraph.com/ +[SPARQL]: https://www.w3.org/TR/sparql11-overview/ + +This sample uses Blazegraph as the RDF database pre-loaded with sample social +network data and shows how to configure Graph Explorer to connect to it +automatically with a default connection. + +> [!NOTE] +> The data is not persisted between restarts of the Docker container. + +## Sample Data + +The sample includes a small social network with: + +- 4 people (Alice, Bob, Charlie, Diana) +- 3 organizations (TechCorp, Startup, Nonprofit) +- Relationships showing who knows whom and where people work + +## Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) installed on your machine +- [Docker Compose](https://docs.docker.com/compose/install/) installed on your + machine + +## Running Sample + +1. Clone or download this repository +2. Navigate to the `samples/blazegraph` directory + ``` + cd samples/blazegraph + ``` +3. Run the following command to start both services + ``` + docker compose up + ``` +4. Wait for both services to start (Blazegraph will load sample data + automatically) +5. Open the browser and navigate to: + [http://localhost:8080/explorer](http://localhost:8080/explorer) + +## Stopping the Sample + +To stop the services, press `Ctrl+C` in the terminal or run: + +``` +docker compose down +``` diff --git a/samples/blazegraph/docker-compose.yml b/samples/blazegraph/docker-compose.yml new file mode 100644 index 000000000..71d25740a --- /dev/null +++ b/samples/blazegraph/docker-compose.yml @@ -0,0 +1,35 @@ +version: "3.9" + +services: + database: + image: openkbs/blazegraph:latest + restart: unless-stopped + environment: + - JAVA_OPTS=-Xmx2g + volumes: + - ./init:/init + - ./data:/var/blazegraph + command: + bash -c "java -server -Xmx2g -jar blazegraph.jar & /init/load-data.sh && + wait" + working_dir: /home/developer/blazegraph/ + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9999/blazegraph"] + interval: 30s + timeout: 5s + retries: 3 + + graph-explorer: + image: public.ecr.aws/neptune/graph-explorer:latest + ports: + - "8090:80" + environment: + - HOST=localhost + - PUBLIC_OR_PROXY_ENDPOINT=http://localhost:8090 + - GRAPH_TYPE=sparql + - USING_PROXY_SERVER=true + - PROXY_SERVER_HTTPS_CONNECTION=false + - GRAPH_CONNECTION_URL=http://database:9999/blazegraph + depends_on: + database: + condition: service_healthy diff --git a/samples/blazegraph/init/load-data.sh b/samples/blazegraph/init/load-data.sh new file mode 100755 index 000000000..a56380594 --- /dev/null +++ b/samples/blazegraph/init/load-data.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +MARKER_FILE="/var/blazegraph/.data_loaded" + +# If the marker file exists, skip loading +if [ -f "$MARKER_FILE" ]; then + echo "Sample data already loaded — skipping." + exit 0 +fi + +# Wait for Blazegraph to become available +echo "Waiting for Blazegraph to start..." +until curl -s http://localhost:9999/blazegraph >/dev/null; do + sleep 2 +done + +echo "Blazegraph is up! Loading sample.ttl..." + +# Load the RDF data into the default namespace (kb) +curl -s -X POST \ + -H 'Content-Type: text/turtle' \ + --data-binary @/init/sample-data.ttl \ + "http://localhost:9999/blazegraph/namespace/kb/sparql" \ + -o /dev/null + +# Create a marker so we know data has been loaded +touch "$MARKER_FILE" +echo "✅ Data loaded successfully and marker file created." diff --git a/samples/blazegraph/init/sample-data.ttl b/samples/blazegraph/init/sample-data.ttl new file mode 100644 index 000000000..d092f7681 --- /dev/null +++ b/samples/blazegraph/init/sample-data.ttl @@ -0,0 +1,42 @@ +@prefix ex: . +@prefix foaf: . +@prefix rdf: . +@prefix rdfs: . + +# People +ex:alice a foaf:Person ; + foaf:name "Alice Johnson" ; + foaf:age 30 ; + foaf:knows ex:bob, ex:charlie ; + foaf:worksFor ex:techcorp . + +ex:bob a foaf:Person ; + foaf:name "Bob Smith" ; + foaf:age 25 ; + foaf:knows ex:alice, ex:diana ; + foaf:worksFor ex:startup . + +ex:charlie a foaf:Person ; + foaf:name "Charlie Brown" ; + foaf:age 35 ; + foaf:knows ex:alice, ex:diana ; + foaf:worksFor ex:techcorp . + +ex:diana a foaf:Person ; + foaf:name "Diana Prince" ; + foaf:age 28 ; + foaf:knows ex:bob, ex:charlie ; + foaf:worksFor ex:nonprofit . + +# Organizations +ex:techcorp a foaf:Organization ; + foaf:name "TechCorp Inc." ; + rdfs:label "Technology Corporation" . + +ex:startup a foaf:Organization ; + foaf:name "Innovative Startup" ; + rdfs:label "Startup Company" . + +ex:nonprofit a foaf:Organization ; + foaf:name "Community Nonprofit" ; + rdfs:label "Non-profit Organization" .