{"id":17091294,"url":"https://github.com/jhurliman/node-graph-suggestions","last_synced_at":"2025-04-12T22:35:29.711Z","repository":{"id":31078406,"uuid":"34637385","full_name":"jhurliman/node-graph-suggestions","owner":"jhurliman","description":"Provides \"people you should follow\" or other graph-based recommendations","archived":false,"fork":false,"pushed_at":"2015-04-27T05:40:00.000Z","size":144,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T01:42:18.847Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jhurliman.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-27T00:10:45.000Z","updated_at":"2021-10-01T00:31:44.000Z","dependencies_parsed_at":"2022-08-31T22:11:21.568Z","dependency_job_id":null,"html_url":"https://github.com/jhurliman/node-graph-suggestions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fnode-graph-suggestions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fnode-graph-suggestions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fnode-graph-suggestions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurliman%2Fnode-graph-suggestions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhurliman","download_url":"https://codeload.github.com/jhurliman/node-graph-suggestions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248642309,"owners_count":21138350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T13:58:10.843Z","updated_at":"2025-04-12T22:35:29.691Z","avatar_url":"https://github.com/jhurliman.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-graph-suggestions #\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nProvides \"people you should follow\" or other graph-based recommendations. By \ncalling the suggest method and providing two data fetching methods for looking \nup forward connections (ie \"users followed by a user\") and reverse connections \n(ie \"users following a user\") you can get back a list of suggested friends, \nproducts, or any other concept that can be represented as a graph.\n\n## Installation ##\n\nUse NPM to install:\n\n    npm install graph-suggestions\n\n## Usage ##\n\nA simple example showing the behavior of the forwardOnly option.\n\n```javascript\nvar suggestions = require('graph-suggestions');\n\nvar DATA_STORE = {\n  Andrew: { friends: [ 'Ben' ] },\n  Ben: { friends: [ 'Andrew', 'Chuck' ] },\n  Chuck: { friends: [ 'Ben' ] },\n  Dennis: { friends: [ 'Andrew' ] }\n};\n\nvar opts = { forwardOnly: true, forwardConnections: forwardFetcher };\nsuggestions.suggest('Andrew', opts, function(err, results) {\n  if (err) throw err;\n\n  // Forward-Only: [{\"nodeID\":\"Chuck\",\"score\":0.0625}]\n  console.log('Forward-Only: ' + JSON.stringify(results));\n});\n\nopts = { forwardConnections: forwardFetcher, reverseConnections: reverseFetcher };\nsuggestions.suggest('Andrew', opts, function(err, results) {\n  if (err) throw err;\n\n  // Bi-Directional: [{\"nodeID\":\"Dennis\",\"score\":0.111},{\"nodeID\":\"Chuck\",\"score\":0.0417}]\n  console.log('Bi-Directional: ' + JSON.stringify(results));\n});\n\nfunction forwardFetcher(nodeID, callback) {\n  var node = DATA_STORE[nodeID];\n  callback(null, node ? node.friends : []);\n}\n\nfunction reverseFetcher(nodeID, callback) {\n  var array = [];\n  for (var curNodeID in DATA_STORE) {\n    var node = DATA_STORE[curNodeID];\n    if (node.friends.indexOf(nodeID) !== -1)\n      array.push(curNodeID);\n  }\n  callback(null, array);\n}\n```\n\n## Additional Notes ##\n\nThe algorithm used under the hood is [Personalized PageRank](http://nlp.stanford.edu/projects/pagerank.shtml). Starting from a given node, the graph is traversed a given number of degrees outward (defaulting to three). There are many great resources online describing PageRank and Personalized PageRank, but a quick summary is that nodes will be scored based on your likelihood to stumble upon them on a random walk through your local graph. A `forwardOnly` setting (defaulting off) toggles whether this random walk can follow directed edges in the reverse direction or not. If you have an undirected graph such as a Facebook-style symmetric friendship graph, you'll want to set `forwardOnly` to true to avoid redundant work.\n\nThe implementation is based on a [blog post](http://blog.echen.me/2012/07/31/edge-prediction-in-a-social-graph-my-solution-to-facebooks-user-recommendation-contest-on-kaggle/) by Edwin Chen detailing a solution for Facebook's user recommendation challenge.\n\n## License ##\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/graph-suggestions.svg?style=flat\n[npm-url]: https://npmjs.org/package/graph-suggestions\n[travis-image]: https://img.shields.io/travis/jhurliman/node-graph-suggestions.svg?style=flat\n[travis-url]: https://travis-ci.org/jhurliman/node-graph-suggestions\n[coveralls-image]: https://img.shields.io/coveralls/jhurliman/node-graph-suggestions.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/jhurliman/node-graph-suggestions?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/graph-suggestions.svg?style=flat\n[downloads-url]: https://npmjs.org/package/graph-suggestions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhurliman%2Fnode-graph-suggestions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhurliman%2Fnode-graph-suggestions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhurliman%2Fnode-graph-suggestions/lists"}