├── .gitignore ├── spam-detect.js ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /spam-detect.js: -------------------------------------------------------------------------------- 1 | const BayesClassifier = require('bayes-classifier'); 2 | 3 | var classifier = new BayesClassifier() 4 | var storedClassifier = require('./store.json'); 5 | classifier.restore(storedClassifier) 6 | 7 | module.exports.detect = function(str) { 8 | var ans = classifier.classify(str); 9 | return ans; 10 | } 11 | 12 | module.exports.getResults = function(str){ 13 | var ans = classifier.getClassifications(str); 14 | return ans; 15 | } 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spam-detection 2 | 3 | Small package based on Naive Bayes classifier to classify messages as spam or ham. 4 | 5 | # Install 6 | ``` 7 | npm install spam-detection 8 | 9 | ``` 10 | # Usage 11 | ``` 12 | const spamcheck = require('spam-detection'); 13 | 14 | const ans = spamcheck.detect('hello how are you') // invoke detect method 15 | 16 | console.log(ans); // ham 17 | 18 | const result = spamcheck.getResults('hello how are you') 19 | 20 | console.log(result); // [ { label: 'ham', value: 0.01866475233309404 }, 21 | { label: 'spam', value: 0.0030509691313711416 } ] 22 | ``` 23 | # License 24 | 25 | ISC 26 | 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spam-detection", 3 | "version": "1.0.3", 4 | "description": "Small package to check spam text and messages", 5 | "main": "spam-detect.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": ["spam-detection", "spam check", "spam detection", "spam","text-spam", "machine learning", "bayes-classifier","nlp","NLP","detect spam","check", "ham"], 10 | "repository": { 11 | "type" : "git", 12 | "url" : "https://github.com/harshitkohli1997/spam-detection" 13 | }, 14 | "homepage": "https://github.com/harshitkohli1997/spam-detection/blob/master/README.md", 15 | "author": "hk", 16 | "license": "ISC", 17 | "dependencies": { 18 | "bayes-classifier": "0.0.5" 19 | } 20 | } 21 | --------------------------------------------------------------------------------