Querying the DKG
Last updated
Was this helpful?
Last updated
Was this helpful?
If you're just getting started with querying the OriginTrail Decentralized Knowledge Graph (DKG), don't worry — you're in the right place! We use the SPARQL query language to interact with the DKG. At first, SPARQL might seem confusing (we've all been there), but once you get the hang of it, it's actually much simpler than it looks — and incredibly powerful.
Paranets are isolated environments within the DKG where participants can publish and query data privately or publicly. Within a paranet, a Knowledge Collection (KC) groups together multiple Knowledge Assets (KAs). A KC acts as a container that maintains a set of KAs, each of which represents a distinct set of information, assertions, or metadata. You can read more about these concepts .
Relationships:
A Paranet contains multiple Knowledge Collections (KCs).
Each KC contains multiple Knowledge Assets (KAs).
Each KA is stored in its own named graph .
Before diving into queries, here’s a quick overview of the most important RDF connections you'll encounter in the DKG:
<current:graph> dkg:hasNamedGraph <KaGraph> - This tells us which Knowledge Asset graphs are currently considered valid and active. You’ll use this to filter for the current version of a KA.
<metadata:graph> <KcUal> dkg:hasNamedGraph <KaGraph> - This connection links a Knowledge Collection (KC) to one or more Knowledge Assets (KAs). It’s used when looking up KAs via their KC metadata (e.g. publisher, timestamp).
<metadata:graph> <KcUal> dkg:hasKnowledgeAsset <KaUAL> - This links the KC to the KA’s Universal Asset Locator (UAL). While it doesn’t point to the named graph directly, it’s important for referencing and versioning KAs.
<> dkg:hasNamedGraph <KaGraph> - This is used when querying inside a paranet. The paranet graph stores references to all associated KAs within that scope. You can use it to restrict queries to a specific environment.
Paranet in which we are searching for the KAs: did:dkg:hardhat1:31337/0xd5724171c2b7f0aa717a324626050bd05767e2c6/3/1
This is the go-to pattern for querying across currently active KAs.
Happy querying! You've got this. 🚀
Want to dive deeper into SPARQL? Check out this awesome guide:.