Arquivos
NodeCopterHack/node_modules/nearest-neighbor/package.json
T
David Henderson 61412dad39 added package
2013-08-10 15:13:36 +01:00

41 linhas
6.4 KiB
JSON

{
"author": {
"name": "Alexander Schuch",
"url": "http://schuch.me"
},
"name": "nearest-neighbor",
"description": "Nearest neighbor algorithm to find the most similar object within an array of objects.",
"version": "0.0.3",
"homepage": "https://github.com/aschuch/node-nearest-neighbor",
"repository": {
"type": "git",
"url": "https://github.com/aschuch/node-nearest-neighbor.git"
},
"engines": {
"node": ">=0.8.0"
},
"main": "lib/nearest-neighbor.js",
"dependencies": {},
"devDependencies": {
"coffee-script": "*",
"should": "*"
},
"scripts": {
"test": "coffee test/test.coffee"
},
"keywords": [
"nearest neighbor",
"k-nearest neighbor",
"similarity"
],
"license": "MIT",
"readme": "# Node Nearest Neighbor\n\n[Nearest neighbor](http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm) algorithm to find the most similar object within an array of objects.\n\n\n## Installation\n\n```bash\n$ npm install nearest-neighbor\n```\n\n## Usage\n\n```javascript\nvar nn = require('nearest-neighbor');\nnn.findMostSimilar(query, items, fields, function(nearestNeighbor, probability) {\n console.log(nearestNeighbor);\n console.log(probability);\n});\n```\n\n```items``` is an array of objects that acts as the haystack that should be searched for the most similar ```query``` object. The ```fields``` array includes all the keys of the object the similarity should be calculated of and a comparison method to perform the similarity check. The callback returns the most similar object from the ```items``` array and the probability of the match between 1 and 0.\n\n### Example\n\n```javascript\nnn = require('nearest-neighbor');\n\nvar items = [\n { name: \"Bill\", age: 10, pc: \"Mac\", ip: \"68.23.13.8\" },\n { name: \"Alice\", age: 22, pc: \"Windows\", ip: \"193.186.11.3\" },\n { name: \"Bob\", age: 12, pc: \"Windows\", ip: \"56.89.22.1\" }\n];\n\nvar query = { name: \"Bob\", age: 12, pc: \"Windows\", ip: \"68.23.13.10\" };\n\nvar fields = [\n { name: \"name\", measure: nn.comparisonMethods.word },\n { name: \"age\", measure: nn.comparisonMethods.number, max: 100 },\n { name: \"pc\", measure: nn.comparisonMethods.word }, \n { name: \"ip\", measure: nn.comparisonMethods.ip }\n];\n\nnn.findMostSimilar(query, items, fields, function(nearestNeighbor, probability) {\n console.log(query);\n console.log(nearestNeighbor);\n console.log(probability);\n});\n```\n\n#### Output\n\nThe most similar object from the ```items``` array compared to the ```query``` object and the probability ([0..1]) of the match found.\n\n```javascript\n{ name: 'Bob', age: 12, pc: 'Windows', ip: '68.23.13.10' }\n{ name: 'Bob', age: 12, pc: 'Windows', ip: '56.89.22.1' }\n0.9764705882352941\n```\n\n### Comparison Methods\n\nThere are some basic comparison methods shipped with this module. Every comparison method has two parameters and returns a number between 1 and 0.\na is the current item from the ```items``` array\nb is always the ```query``` object\n\n```javascript\n// example comparison function\nfunction(a, b) {\n return 0.5;\n};\n```\n\nThe predefined comparison functions are available through the ```nn.comparisonMethods``` object. E.g. ```nn.comparisonMethods.exact```. \n\n* **exact**: Checks if a and b have the exact same value (using ```===```).\n* **word**: Calculates the similarity of two words.\n* **wordArray**: Calculates the similarity of an array of words.\n* **ip**: Calculates the similarity of two IP addresses.\n* **ipArray**: Calculates the similarity of an array of IP addresses.\n* **number**: Calculates the similarity two numbers.\n\n\n### Add your custom comparison method\n\nYou can also roll your own comparison method if you like.\nJust add your custom method to the ```nn.comparisonMethods``` object.\n\n```javascript\n// define items and query as shown before\n\nnn.comparisonMethods.custom = function(a, b) {\n\t// compare something...\n\tvar value = ...\n \treturn value; // between 0 and 1\n};\n\n// then use your custom method for one of the comparison fields\nvar fields = [\n { name: \"name\", measure: nn.comparisonMethods.custom },\n { name: \"age\", measure: nn.comparisonMethods.number, max: 100 },\n { name: \"pc\", measure: nn.comparisonMethods.word }, \n { name: \"ip\", measure: nn.comparisonMethods.ip }\n];\n\n// use nn.findMostSimilar as shown before\n```\n\n## Tests\n\n```bash\n$ npm test\n\n{ name: 'Bob', age: 12, pc: 'Windows', ip: '68.23.13.10' }\n{ name: 'Bob', age: 12, pc: 'Windows', ip: '56.89.22.1' }\n0.9764705882352941\n\nAll tests OK\n```\n\n## Contributors\n\nThanks to [Blago](http://stackoverflow.com/users/113999/blago) on StackOverflow for providing the initial draft/idea for the algorithm.\n\n## Contributing\n\n* Create something awesome, make the code better, add some functionality,\n whatever (this is the hardest part).\n* [Fork it](http://help.github.com/forking/)\n* Create new branch to make your changes\n* Commit all your changes to your branch\n* Submit a [pull request](http://help.github.com/pull-requests/)\n\n## Contact\n\nFeel free to get in touch.\n\n* Website: <http://schuch.me> \n* Twitter: [@schuchalexander](http://twitter.com/schuchalexander)\n\n## Licence\n\nCopyright (C) 2013 Alexander Schuch\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"readmeFilename": "README.md",
"_id": "nearest-neighbor@0.0.3",
"dist": {
"shasum": "7c9c826cd6ed7dc5da199677c2064ade15cfa83a"
},
"_from": "nearest-neighbor@",
"_resolved": "https://registry.npmjs.org/nearest-neighbor/-/nearest-neighbor-0.0.3.tgz"
}