[Package Index | Mudlib Index | Effect Index]

File /obj/handlers/english_handler.c

English Handler

Written by Shaggy This handler is a collection of methods that attempt to evaluate how much like english a line of text is. Some tests might be more expensive than others but the general idea is to be much cheaper than a dictionary lookup. The general principle it to return a value that is closer to 100 the better the english with 50 being borderline (ie. likely to be gibberish). The returned value is thus a bit like a percentage chance that it is english.

Method index

Public Functions

These are functions that everyone can access.

FreqTest
int FreqTest(string line)

FreqTest is a routine that evaluates how like english a line of text is. It compares the frequency of the letters, spaces and non-letters to the typical number in English (taken from the am board archive). A typical sentence should give a percentage change of being english in the range 50-100. Short or unusual sentences can get borderline evaluations (<60) even if they are english.

Parameters:
line - line of text to evaluate

Returns:
percentage chance of being english 50-100 ok < 50 might be gibberish

Example:
"/obj/handlers/english_handler"->FreqTest("Short english sentence")
Returns: 75

"/obj/handlers/english_handler"->FreqTest("Sqeal spezzial sentenz")
Returns: 1

"/obj/handlers/english_handler"->FreqTest("eeeeeeee dfs fsfdsfddf")
Returns: 37

"/obj/handlers/english_handler"->FreqTest("too short");  
Returns: 59

"/obj/handlers/english_handler"->FreqTest("Don't like l33t sp33k neither");  
Returns: 36

"/obj/handlers/english_handler"->FreqTest("a small excursion to the
                                                    zoo should be permissible");
Returns: 83 

get_words
string * get_words(string category)

This method gets an array of words of the desired category.

Parameters:
category - The category of words. You can choose either sub categories like "greetings_weird" or full categories like "greetings". A list can be seen with query_word_categories()

Returns:
An array of the words matching the category.

See also:
query_word_categories .c

Example:
 string *words;

 words = ("/obj/handlers/english_handler")->get_words( "greetings", 1 );

 if( sizeof( words ) ) {
   add_respond_to_with( ({ "@say", words }), "greet $hname$" );
 }

ProfaneTest
int ProfaneTest(string strin)

ProfaneTest is a routine that evaluates how likely the text is to be profane/swearing/obscenity and so on. These are the sorts of things that would never be allowed as a player name. Spaces, non letters and repeating letters are worked around by this test.

Parameters:
line - line of text to evaluate

Returns:
percentage chance of being offensive: chances over 100% can be returned indicating greater likelihood of offense and/or more than one suspect word. If you want it as lily white as possible you should insist on 0.


query_word_categories
string * query_word_categories()

This method queries all the categories of words.

Returns:
An array of all word categories.

See also:
get_words .c


set_words
void set_words()