Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Profanity filter for multiple languages

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.21k
    Comment on it

    To check the profanity in the text for multilanguage, here we use WebPurify web service. This web service provide various callable methods including check, checkcount, replace, return etc. But here we are using the replace method (webpurify.live.replace) that will replace the profane word with a symbol we provide in the request url. Here is the documentation for the same to avail the services provided by this web service.

    For a particular language, we need to generate a request url by integration console that need to be send to its endpoint specifying a method and some arguments.

    Request url would be like 

    http://api1.webpurify.com/services/rest/?api_key=d20978a07f17f8edf5efffd815f40f85&method=webpurify.live.replace&replacesymbol=*&lang=de&format=json'

    where 

     

    for each registered user, there would be an api_key

    method defines the method we need to call

    replace symbol is the symbol with which we replace the profane word

    lang defines the language for which the profanity is intended to be checked

    format defines the response format

     

    Here is an example that implements the functionality to replace the profane words with symbol “*” for german language.

     

    Example

    Index.html

    <form class="comment-form" method="post">
    		<table>
    			 <tr>
    				<td>
    					<input type="text" id="comment">
    				</td>
    				<td>
    					<input type="button" id="go" value="GO">
    				</td>
    			</tr>
    		</table>
    </form>

     

    test.js

    $(document).on('click', '#go', function(){
    								
    			var apiBaseURL = 'http://api1.webpurify.com/services/rest/?api_key=d20978a07f17f8edf5efffd815f40f85&method=webpurify.live.replace&replacesymbol=*&lang=de&format=json';
    
    			var lang = 'de';
    			
        		$.ajax({
        			
        			type: "GET",
        			headers: {'Access-Control-Allow-Origin': '*'},
        			url: apiBaseURL+'&lang=de&text='+$('#comment').val(),
        			sync:true,
        			crossDomain: true,
        			
        			dataType:"jsonp",
        			success: function(response){
    	    			console.log("successful"+JSON.stringify(response));
    	    			console.log(JSON.stringify(response.rsp.text));
    	    			var replacedstring = JSON.stringify(response.rsp.text);
    	    			$('#comment').val(replacedstring.replace(/\"/g, ""));     
    	    			
        			}, 
        			error:function(e){
            			
        				alert("Error"+e);
        			}
        		});
    });

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: