Triple Structuring
Understanding how to properly structure Triples is essential for building rich, queryable knowledge graphs. This guide covers techniques for creating well-designed semantic relationships.
Basic Triple Structureβ
{
"id": "did:ethr:mainnet:0x...",
"subject": "did:ethr:mainnet:0x...",
"predicate": "did:ethr:mainnet:0x...",
"object": "did:ethr:mainnet:0x...",
"metadata": {
"created": "2024-01-15T10:30:00Z",
"creator": "did:ethr:mainnet:0x...",
"confidence": 0.95
}
}
Triple Categoriesβ
1. Property Triplesβ
Describe attributes or characteristics of entities.
Example: "Ethereum is decentralized"
{
"subject": "did:ethr:mainnet:0x...", // Ethereum
"predicate": "did:ethr:mainnet:0x...", // is
"object": "did:ethr:mainnet:0x...", // decentralized
"type": "property"
}
2. Relationship Triplesβ
Connect entities through specific relationships.
Example: "Vitalik Buterin created Ethereum"
{
"subject": "did:ethr:mainnet:0x...", // Vitalik Buterin
"predicate": "did:ethr:mainnet:0x...", // created
"object": "did:ethr:mainnet:0x...", // Ethereum
"type": "relationship"
}
3. Classification Triplesβ
Establish hierarchical or categorical relationships.
Example: "Machine Learning is a subset of AI"
{
"subject": "did:ethr:mainnet:0x...", // Machine Learning
"predicate": "did:ethr:mainnet:0x...", // is a subset of
"object": "did:ethr:mainnet:0x...", // AI
"type": "classification"
}
Creating Triples Programmaticallyβ
Using the SDKβ
import { createAtomFromString, createTripleStatement } from '@0xintuition/sdk'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { sepolia } from 'viem/chains'
import { getEthMultiVaultAddressFromChainId } from '@0xintuition/sdk'
// Configure viem clients
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const walletClient = createWalletClient({ account, chain: sepolia, transport: http() })
const publicClient = createPublicClient({ chain: sepolia, transport: http() })
// Get MultiVault address
const multivaultAddress = getEthMultiVaultAddressFromChainId(sepolia.id)
// Create a Triple
const result = await createTripleStatement(
{ walletClient, publicClient, address: multivaultAddress },
subjectVaultId,
predicateVaultId,
objectVaultId
)
Best Practicesβ
1. Use Atomic Componentsβ
- Each component (subject, predicate, object) should be a focused Atom
- Avoid embedding complex data in individual components
- Leverage reusable Atoms for common concepts
2. Choose Clear Predicatesβ
- Use widely understood relationship terms
- Be specific but not overly verbose
- Consider standardizing on common predicates
3. Maintain Consistencyβ
- Follow naming conventions across related Triples
- Use consistent data types
- Align with community standards
4. Enable Composabilityβ
- Design Triples that can combine with others
- Consider how Triples might be queried together
- Think about nested Triple possibilities
Next Stepsβ
- Nested Triples - Learn how to create meta-claims and context
- Signal Fundamentals - Understand how to validate Triples