Developer Hub
Relation ProtocolRelation ONE APIRelation Graph API
English
English
  • Overview
  • QUICK START
    • Deploy a Semantic SBT contract leveraging Relation Protocol
    • Deploying query services using Graph Indexer
  • KEY CONCEPTS
    • RDF
    • Semantic SBTs
    • Social Graph
  • Architecture
  • Schema Standard
    • Overview
    • How schemas limit smart contracts
    • Store schema
    • List of schemas
  • Contract Open Standard
    • Overview
    • Identity
      • Name Service
    • Relationship
      • Follow
      • Dao
    • Publication
      • Content
      • Privacy Content
  • Open Standard API
    • Introduction
    • EIP-6239
    • Business Interface
      • Identity
      • Relationship
      • Publication
  • Graph Indexer
    • Definition and usage
    • Listen to events
    • To parse RDF data
    • To build a social graph
  • Integrations
    • Quick start
    • Construct a social graph with Relation Protocol
    • List of resources
    • NameService contract guide
    • Follow contract guide
    • Dao contract guide
    • Content contract guide
    • PrivacyContent contract guide
  • Relation Name Service
    • Name Service Api
  • Use Case
  • APPENDIX
    • Deploy a contract using Hardhat
    • SemanticSBT Deployment tool
Powered by GitBook
On this page
  • To use Neptune
  • To use Jena
  • To use Neo4j
  1. Graph Indexer

To build a social graph

Last updated 2 years ago

This protocol supports all graph databases conforming to the RDF specification.

We can have a simple social graph by importing the RDF data constructed from the last chapter.

To use Neptune

Steps:

  1. Composite the sparql constructed from the last chapter into an "insert" command in Neptune:

update=PREFIX : <http://relationlabs.ai/entity/>
PREFIX p: <http://relationlabs.ai/property/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
INSERT DATA {GRAPH <http://relationlabs.ai/relationship> {
:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe a :Soul;
    p:name "Alice" .
:Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e a :Soul;
    p:name "Bob" .
:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe p:following :Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e .
}}
  1. Call the Neptune service interface to save RDF:

curl -X POST --data-binary 'update=PREFIX : <http://relationlabs.ai/entity/>
PREFIX p: <http://relationlabs.ai/property/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
INSERT DATA {GRAPH <http://relationlabs.ai/relationship> {
:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe a :Soul;
    p:name "Alice" .
:Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e a :Soul;
    p:name "Bob" .
:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe p:following :Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e .  }}' https://your-neptune-endpoint:port/sparql

By now we have indexed the data Alice follow Bob into the graph database. We can query the data via the Neptune service interface:

curl -X POST --data-binary 'query=select * where {
?s a :Soul;
  p:name "Alice".
?s p:following ?f .} limit 10' https://your-neptune-endpoint:port/sparql

To use Jena

docker run -p 3030:3030 -e ADMIN_PASSWORD=pw123 stain/jena-fuseki

If successful, please visit http://localhost:3030/ using the account "admin" and password "pw123".

  1. First please create a dataset:

  1. Then import the data from the last step into the graph database.

PREFIX : <http://relationlabs.ai/entity/>
PREFIX p: <http://relationlabs.ai/property/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe a :Soul;
    p:name "Alice" .

:Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e a :Soul;
    p:name "Bob" .

:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe p:following :Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e .
  1. Finally, switch to the Query tag to query which people Alice has followed:

PREFIX : <http://relationlabs.ai/entity/>
PREFIX p: <http://relationlabs.ai/property/>

SELECT * WHERE {
  ?me a :Soul;
	p:name "Alice";
    p:following ?following .
  ?following p:name ?name .
}
LIMIT 10

The query result is : Alice's address 0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe followed Bob's address 0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e.

To use Neo4j

docker run \
    -p 7474:7474 -p 7687:7687 \
    --name neo4j-neosemantics \
    neo4j:5.5.0
  1. Install plugins to support RDF

docker exec -it neo4j-neosemantics bash
cd plugins/
wget https://github.com/neo4j-labs/neosemantics/releases/download/5.5.0.0/neosemantics-5.5.0.0.jar
  1. Configure Plugin

Open file: conf/neo4j.conf and append dbms.unmanaged_extension_classes=n10s.endpoint=/rdf.

then restart Neo4j Service:

docker restart neo4j-neosemantics

Open Neo4j Browser: http://localhost:7474/browser/ Default login is username 'neo4j' and password 'neo4j'.

  1. Configure Graph

Execute the following commands in the Neo4j browser input box:

CALL n10s.graphconfig.init();

CREATE CONSTRAINT n10s_unique_uri FOR (r:Resource) REQUIRE r.uri IS UNIQUE;

CALL n10s.graphconfig.init( {  handleMultival: "ARRAY" })

CALL n10s.nsprefixes.add("e", "http://relationlabs.ai/entity/");
CALL n10s.nsprefixes.add("p", "http://relationlabs.ai/property/");
  1. Importing RDF Data

Execute the following commands in the Neo4j browser input box:

CALL n10s.rdf.import.inline("PREFIX : <http://relationlabs.ai/entity/>
PREFIX p: <http://relationlabs.ai/property/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe a :Soul;
    p:name \"Alice\" .

:Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e a :Soul;
    p:name \"Bob\" .

:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe p:following :Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e .","Turtle");
  1. Querying

Execute the following commands in the Neo4j browser input box:

MATCH (ss:Resource {p__name: ["Alice"]})-[:p__following]->(oo) RETURN ss, oo

is a fast and scalable graph database service. It can efficiently store and navigate highly interconnected data. Its query processing engine is optimized for leading graph query languages such as Apache TinkerPopâ„¢ Gremlin and W3C's RDF SPARQL. Neptune provides high performance via these open graph frameworks and standard APIs.

With we can build a social graph using users' behavioral data on the blockchain.

Launch a Neptune instance via the .

For demonstration purposes, we will use to launch a Jena service:

For demonstration purposes, we will use to launch a Neo4j service:

Amazon Neptune
Amazon Neptune
aws console
docker
docker
Figure 7-3 A simple social graph
Figure 7-4 Add a dataset
Figure 7-5 Create demo dataset
Figure 7-6 Upload RDF data
Figure 7-7 Select a file and upload
Figure 7-8 Query with SPARQL
Figure 7-9 Query result
Figure 7-10 To use Neo4j