Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-candles-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphprotocol/grc-20": minor
---

rename ranks to ranking and vote value to score
28 changes: 14 additions & 14 deletions examples/ranks/create-ordinal-rank.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Example: Creating an Ordinal Rank with grc-20-ts
* Example: Creating an Ordinal Ranking with grc-20-ts
*
* This example demonstrates how to use the `createRank` function to create
* an ordinal (ordered) rank in the Knowledge Graph.
* This example demonstrates how to use the `createRanking` function to create
* an ordinal (ordered) ranking in the Knowledge Graph.
*/

import { IdUtils, Rank } from '@graphprotocol/grc-20';
import { IdUtils, Ranking } from '@graphprotocol/grc-20';

// For this example, we'll generate some entity IDs to represent items we want to rank.
// In a real application, these would be existing entity IDs from your Knowledge Graph.
Expand All @@ -14,30 +14,30 @@ const movie2Id = IdUtils.generate();
const movie3Id = IdUtils.generate();

// =============================================================================
// Example 1: Creating an Ordinal Rank (Ordered List)
// Example 1: Creating an Ordinal Ranking (Ordered List)
// =============================================================================
// Ordinal ranks are used when you want to rank items by position (1st, 2nd, 3rd, etc.)
// Ordinal rankings are used when you want to rank items by position (1st, 2nd, 3rd, etc.)
// The position is derived from the array order - no need to specify position values!

const ordinalRankResult = Rank.createRank({
const ordinalRankingResult = Ranking.createRanking({
name: 'My Favorite Movies of 2024',
description: 'A ranked list of my top movies this year',
rankType: 'ORDINAL',
rankingType: 'ORDINAL',
votes: [
{ entityId: movie1Id }, // 1st place
{ entityId: movie2Id }, // 2nd place
{ entityId: movie3Id }, // 3rd place
],
});

console.log('=== Ordinal Rank Example ===');
console.log('Rank ID:', ordinalRankResult.id);
console.log('Number of operations:', ordinalRankResult.ops.length);
console.log('Vote entity IDs:', ordinalRankResult.voteIds);
console.log('=== Ordinal Ranking Example ===');
console.log('Ranking ID:', ordinalRankingResult.id);
console.log('Number of operations:', ordinalRankingResult.ops.length);
console.log('Vote entity IDs:', ordinalRankingResult.voteIds);

// The ops array contains all the operations needed to create this rank:
// The ops array contains all the operations needed to create this ranking:
console.log('\nOperations breakdown:');
for (const op of ordinalRankResult.ops) {
for (const op of ordinalRankingResult.ops) {
if (op.type === 'createEntity') {
console.log(` - createEntity`);
} else if (op.type === 'createRelation') {
Expand Down
34 changes: 17 additions & 17 deletions examples/ranks/create-weighted-rank.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Example: Creating a Weighted Rank with grc-20-ts
* Example: Creating a Weighted Ranking with grc-20-ts
*
* This example demonstrates how to use the `createRank` function to create
* a weighted (scored) rank in the Knowledge Graph.
* This example demonstrates how to use the `createRanking` function to create
* a weighted (scored) ranking in the Knowledge Graph.
*/

import { IdUtils, Rank } from '@graphprotocol/grc-20';
import { IdUtils, Ranking } from '@graphprotocol/grc-20';

// For this example, we'll generate some entity IDs to represent items we want to rank.
// In a real application, these would be existing entity IDs from your Knowledge Graph.
Expand All @@ -14,30 +14,30 @@ const restaurant2Id = IdUtils.generate();
const restaurant3Id = IdUtils.generate();

// =============================================================================
// Example 1: Creating a Weighted Rank (Scored List)
// Example 1: Creating a Weighted Ranking (Scored List)
// =============================================================================
// Weighted ranks are used when you want to assign numeric scores to items.
// Weighted rankings are used when you want to assign numeric scores to items.
// Useful for ratings, reviews, or any scenario where magnitude matters.

const weightedRankResult = Rank.createRank({
const weightedRankingResult = Ranking.createRanking({
name: 'Restaurant Ratings',
description: 'My restaurant reviews',
rankType: 'WEIGHTED',
rankingType: 'WEIGHTED',
votes: [
{ entityId: restaurant1Id, value: 90 }, // Can use any number and scale as needed
{ entityId: restaurant2Id, value: 65 },
{ entityId: restaurant3Id, value: 50 },
{ entityId: restaurant1Id, score: 90 }, // Can use any number and scale as needed
{ entityId: restaurant2Id, score: 75 },
{ entityId: restaurant3Id, score: 50.67 }, // You can also use decimal numbers
],
});

console.log('\n=== Weighted Rank Example ===');
console.log('Rank ID:', weightedRankResult.id);
console.log('Number of operations:', weightedRankResult.ops.length);
console.log('Vote entity IDs:', weightedRankResult.voteIds);
console.log('\n=== Weighted Ranking Example ===');
console.log('Ranking ID:', weightedRankingResult.id);
console.log('Number of operations:', weightedRankingResult.ops.length);
console.log('Vote entity IDs:', weightedRankingResult.voteIds);

// The ops array contains all the operations needed to create this rank:
// The ops array contains all the operations needed to create this ranking:
console.log('\nOperations breakdown:');
for (const op of weightedRankResult.ops) {
for (const op of weightedRankingResult.ops) {
if (op.type === 'createEntity') {
console.log(` - createEntity`);
} else if (op.type === 'createRelation') {
Expand Down
6 changes: 3 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export * as IdUtils from './src/id-utils.js';
export * as Ipfs from './src/ipfs.js';
export { Position } from './src/position.js';
/**
* This module provides utility functions for working with ranks in the Knowledge Graph.
* Ranks allow ordering or scoring entities within a collection.
* This module provides utility functions for working with rankings in the Knowledge Graph.
* Rankings allow ordering or scoring entities within a collection.
*/
export * as Rank from './src/ranks/index.js';
export * as Ranking from './src/ranks/index.js';

/**
* This module provides utility functions for working with Graph URIs in TypeScript.
Expand Down
Loading
Loading