GithubHelp home page GithubHelp logo

profanity-hindi's Introduction

profanity-hindi

Author : Suraj Kumar Jha

This is a small nodejs module for dealing with profanity in english and hindi. This Module has functionalities for detecting bad words and cleaning them. Technologies used : Nodejs

Installation

just run - npm install profanity-hindi

Requirements

It internally uses lodash , will be automatically installed

Code Example

function maskBadWords()
var profanity = require("profanity-hindi");
var message = "hi asshole you are a bitch chutiya";
var cleaned = profanity.maskBadWords(message);
console.log(cleaned); // hi ******* you are a ***** *******
function isMessageDirty()
var profanity = require("profanity-hindi");
var message = "hi asshole you are a bitch chutiya";
var isDirty = profanity.isMessageDirty(message);
console.log(isDirty);
// prints true

var message = "hi there. How are you";
var isDirty = profanity.isMessageDirty(message);
console.log(isDirty);
// prints false
function addWords()
var profanity = require("profanity-hindi");
 var newWords = ["this", "dumbness"];
 profanity.addWords(newWords); // this will add the new words 
 to the dictionary of bad words. This function optionally
 returns the entire dictionary of bad words.
function removeWords()
var profanity = require("profanity-hindi");
 var newWords = ["this", "dumbness"];
 profanity.removeWords(newWords); // this will remove the new words 
 from the dictionary of bad words. This function optionally
 returns the entire dictionary of bad words.

Unit Tests

Run command : npm test

Contributors

Suraj Kumar Jha

License

MIT License

profanity-hindi's People

Contributors

surajjha avatar

Stargazers

Utkarsh Bhardwaj avatar  avatar Nitin Kale avatar Swaroop Jaikumar Rajwal avatar Rohit Kushwaha avatar Sid avatar  avatar Ahmed Noor E Alam avatar Vivek Iyer avatar John Michael Ferraris avatar Neha Singh avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

profanity-hindi's Issues

Remove word feature does not working

Remove word feature does not working because badworddictionary again created of itself when checking for isDirty word.
Updated code should be --:

`/**

  • Created by surajkumar on 16/12/16.
    */
    var _ = require("lodash");
    var hindiBadWords = require("./data/hindi-bad-words");
    var englishBadWords = require("./data/english-bad-words");
    var badWordsDictionary = _.merge(hindiBadWords, englishBadWords, userDefinedWords);
    var userDefinedWords = {};

var profanity = {};

profanity.maskBadWords = function(message, maskWith) {
if (!message || typeof message !== "string") {
throw new Error("message passed to the function must be a string");
}
var cleanedMessage = message.split(" ").map(function(word) {
if (profanity.isMessageDirty(word)) {
if (maskWith && maskWith !== null && typeof maskWith === "string") {
return word.replace(/./g, maskWith)
}
return word.replace(/./g, "*")
}
return word;
}).join(" ");
return cleanedMessage;
};

profanity.isMessageDirty = function(message) {
if (!message || typeof message !== "string") {
throw new Error("message passed to the function must be a string");
}
var messageWords = message.split(" ");

badWordsDictionary = _.transform(badWordsDictionary, function(result, val, key) {

    result[key.toLowerCase()] = val;
});
var flag = false;
for (var i = 0; i < messageWords.length; i++) {
    if (badWordsDictionary.hasOwnProperty(messageWords[i].trim().toLowerCase())) {
        flag = true;
        break;
    }
}
return flag;

};

var alreadyExists = function(word, wordList) {
if (!word || !wordList) return false;
return !!(wordList.hasOwnProperty(word))
};

profanity.addWords = function(wordList) {
if (!wordList) return badWordsDictionary;
if (typeof wordList === "string" && !alreadyExists(wordList, badWordsDictionary)) {
userDefinedWords[wordList.trim()] = 1;
}
if (wordList.constructor === Array) {
wordList.map(function(word) {
if (typeof word === "string" && !(alreadyExists(word, badWordsDictionary))) {
userDefinedWords[word.trim()] = 1;
}
});
}
badWordsDictionary = _.merge(badWordsDictionary, userDefinedWords);
userDefinedWords = {};
return badWordsDictionary;
};

profanity.removeWords = function(wordList) {
if (!wordList) return badWordsDictionary;
if (typeof wordList === "string" && alreadyExists(wordList, badWordsDictionary))
delete badWordsDictionary[wordList.trim()];
if (wordList.constructor === Array) {
wordList.map(function(word) {
if (typeof word === "string" && alreadyExists(word, badWordsDictionary))
delete badWordsDictionary[word.trim()];
});
}
return badWordsDictionary;
};

module.exports = profanity;`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.