Building Profanity Filters: clbuttic sh!t

50
BUILDING PROFANITY FILTERS clbuttic sh!t

Transcript of Building Profanity Filters: clbuttic sh!t

Page 1: Building Profanity Filters: clbuttic sh!t

BUILDING PROFANITY FILTERSclbuttic sh!t

Page 2: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

INTERNET CENSORSHIP

childrenreligionsexual

https://en.wikipedia.org/wiki/Censorship

Page 3: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

WHY FILTERING GOOD

ETHNICITY

PROTECTS

CHILDREN

RELIGIONSEXUAL ORIENTATION

Page 4: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

WHY FILTERING BADlack of trust to your users

their willing to break rules

Page 5: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

Page 6: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

COCK

Page 7: Building Profanity Filters: clbuttic sh!t

LET’S BUILD FILTER!

Framework Days. IT Saturday. 5.09.2015

filter =list of dirty words +

list of replacements +filter rule

Page 8: Building Profanity Filters: clbuttic sh!t

– George Carlin, 1972

Shit, piss, fuck, cunt, cocksucker, motherfucker, and tits.

“Seven Words You Can Never Say on Television”

Framework Days. IT Saturday. 5.09.2015

Page 9: Building Profanity Filters: clbuttic sh!t

FILTER RULES

Framework Days. IT Saturday. 5.09.2015

1. search by entry

psss…

Page 10: Building Profanity Filters: clbuttic sh!t

RANGE OF WORD

Framework Days. IT Saturday. 5.09.2015

NSRange range = [text rangeOfString:badWord options:NSCaseInsensitiveSearch];

BOOL hasDirtyWord = [text localizedCaseInsensitiveContainsString:badWord];

Page 11: Building Profanity Filters: clbuttic sh!t

RANGE OF WORD

Framework Days. IT Saturday. 5.09.2015

- (NSArray * )rangesOfBadWordsWithSpaceInString:(NSString * )text { __block NSMutableArray * result = [NSMutableArray array];

[self.listOfBadWordsWithSpace enumerateObjectsUsingBlock:^(NSString * badWord, NSUInteger idx, BOOL * stop) {

NSRange range = [text rangeOfString:badWord options:NSCaseInsensitiveSearch]; while (range.location != NSNotFound) { [result addObject:[NSValue valueWithRange:range]]; NSRange nextRange = NSMakeRange(range.location + 1, [text length] - range.location - 1); range = [text rangeOfString:badWord options:NSCaseInsensitiveSearch range:nextRange]; } }];

return result; }

Page 12: Building Profanity Filters: clbuttic sh!t

SEARCH BY ENTRY

Framework Days. IT Saturday. 5.09.2015

Get your ass down here! The grass around the creek was new, giving it a velvety look. Dusty, his heartless assassin, had found his mate.

Page 13: Building Profanity Filters: clbuttic sh!t

SEARCH BY ENTRY

Framework Days. IT Saturday. 5.09.2015

Get your ass down here! The grass around the creek was new, giving it a velvety look. Dusty, his heartless assassin, had found his mate.

Page 14: Building Profanity Filters: clbuttic sh!t

SEARCH BY ENTRY

Framework Days. IT Saturday. 5.09.2015

Get your ass down here! The grass around the creek was new, giving it a velvety look. Dusty, his heartless assassin, had found his mate.

Page 15: Building Profanity Filters: clbuttic sh!t

FALSE POSITIVES

Framework Days. IT Saturday. 5.09.2015

Page 16: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

Get your ass down here! The grass around the creek was new, giving it a velvety look. Dusty, his heartless assassin, had found his mate.

FALSE POSITIVES

Page 17: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

assart

assault

association

assurance

‘ASS’ WORDSharassment

hassel

hourglass

impassable

pass

passion

piassaba

preassign1250 words found

http://www.morewords.com/contains/ass/

Page 18: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

ass → butt

REPLACEMENT RULES…

Page 19: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

classic → clbuttic

…FAILS

Page 20: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

Page 21: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

Constitution → Consbreastution

AND FAILS AGAIN…

medieval → medireview

Tyson Gay → Tyson Homosexual

Page 22: Building Profanity Filters: clbuttic sh!t

FILTER RULES

Framework Days. IT Saturday. 5.09.2015

1. search by entry

2. search whole word don’t u know me?

Page 23: Building Profanity Filters: clbuttic sh!t

SEARCH WHOLE WORD

Framework Days. IT Saturday. 5.09.2015

NSString * scanned; if ([scanner scanCharactersFromSet:wordCharacters intoString:&scanned]) {

if ([wordSet containsObject:[scanned lowercaseString]]) {

NSRange range = NSMakeRange(scanner.scanLocation - scanned.length, scanned.length); [result addObject:[NSValue valueWithRange:range]]; } }

NSSet * badWordsSet = [NSMutableSet setWithArray:self.listOfBadWords];

NSScanner * scanner = [NSScanner scannerWithString:text]; NSCharacterSet * wordCharacters = [NSCharacterSet alphanumericCharacterSet];

Page 24: Building Profanity Filters: clbuttic sh!t

SEARCH WHOLE WORD

Framework Days. IT Saturday. 5.09.2015

Get your ass down here! The grass around the creek was new, giving it a velvety look. Dusty, his heartless assassin, had found his mate.

Page 25: Building Profanity Filters: clbuttic sh!t

SPACE!

Framework Days. IT Saturday. 5.09.2015

AND OTHER PUNCTUATION

Page 26: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

Get your a s s down here! You'd probably fire my a.s.s the first day on the job. You've covered my a_s_s every time I screwed up.

PUNCTUATION

Page 27: Building Profanity Filters: clbuttic sh!t

Framework Days. IT Saturday. 5.09.2015

Get your a s s down here! You'd probably fire my a.s.s the first day on the job. You've covered my a_s_s every time I screwed up.

PUNCTUATION

Page 28: Building Profanity Filters: clbuttic sh!t

FILTER RULES

Framework Days. IT Saturday. 5.09.2015

1. search by entry

2. search whole word

3. handle punctuation

don’t tell anyone…

Page 29: Building Profanity Filters: clbuttic sh!t

1337 59341<

Framework Days. IT Saturday. 5.09.2015

Page 30: Building Profanity Filters: clbuttic sh!t

L33T SPEAK

Framework Days. IT Saturday. 5.09.2015

HOW MANY DIFFERENTSPELLINGS HAS ONE WORD?

Page 31: Building Profanity Filters: clbuttic sh!t

BITCH

Framework Days. IT Saturday. 5.09.2015

Page 32: Building Profanity Filters: clbuttic sh!t

B1TCH

Framework Days. IT Saturday. 5.09.2015

I → 1

BITCH

Page 33: Building Profanity Filters: clbuttic sh!t

B!TCH

Framework Days. IT Saturday. 5.09.2015

I → !

BITCH B1TCH

Page 34: Building Profanity Filters: clbuttic sh!t

BI+CH

Framework Days. IT Saturday. 5.09.2015

T → +

BITCH B1TCH B!TCH

Page 35: Building Profanity Filters: clbuttic sh!t

I3ITCH

Framework Days. IT Saturday. 5.09.2015

B → I3

BITCH B1TCH B!TCH BI+CH

Page 36: Building Profanity Filters: clbuttic sh!t

BITCH B!TCH B1TCH 8ITCH ßITCH

13ITCH L3ITCH BI7CH BI+CH BI†CH

BIT[H BIT¢H BIT<H BITC# BITC:

B1T¢H 8!†C# 8ITC/-/ 817[# (3][+(:

Framework Days. IT Saturday. 5.09.2015

Page 37: Building Profanity Filters: clbuttic sh!t

FILTER RULES

Framework Days. IT Saturday. 5.09.2015

1. search by entry

2. search whole word

3. handle punctuation

4. handle l33t speak

my name is…

Page 38: Building Profanity Filters: clbuttic sh!t

SCUNTHORPE PROBLEM

Framework Days. IT Saturday. 5.09.2015

https://en.wikipedia.org/wiki/Scunthorpe_problem

Page 39: Building Profanity Filters: clbuttic sh!t

NICE TITSIn 2007, the Royal Society for the Protection of Birds blocked ornithological terms such as cock (male bird) and tit, shag and booby from its discussion forums

Framework Days. IT Saturday. 5.09.2015

Page 40: Building Profanity Filters: clbuttic sh!t

FILTER RULES

Framework Days. IT Saturday. 5.09.2015

1. search by entry

2. search whole word

3. handle punctuation

4. handle l33t speak

5. remember about exceptions

blue-footed booby!

Page 41: Building Profanity Filters: clbuttic sh!t

TEXT FILTERING ON IOS

Framework Days. IT Saturday. 5.09.2015

words dictionary (boobs, b00bs,

b00b5)

whole word scan NSScanner, NSSet

Page 42: Building Profanity Filters: clbuttic sh!t

TEXT FILTERING ON IOS

Framework Days. IT Saturday. 5.09.2015

phrases dictionary (b o o b s, b.o.o.b.s,

b!o!o!bs)

substring scan rangeOfString

Page 43: Building Profanity Filters: clbuttic sh!t

TEXT FILTERING ON IOS

Framework Days. IT Saturday. 5.09.2015

words dictionary (boobs, b00bs,

b00b5)

whole word scan NSScanner, NSSet

phrases dictionary (b o o b s, b.o.o.b.s,

bo!obs)

substring scan rangeOfString+

Page 44: Building Profanity Filters: clbuttic sh!t

HOW FAST IS IT?

Framework Days. IT Saturday. 5.09.2015

time,

sec

onds

0

0,1

0,2

0,3

0,4

user text, characters count

1000 5000 10000 20000

range scanner both dirty words dictionary

contains 455 words

Page 45: Building Profanity Filters: clbuttic sh!t

LIVE FILTERING

Framework Days. IT Saturday. 5.09.2015

use RAC and run filter every time user inputs character

Page 46: Building Profanity Filters: clbuttic sh!t

IMPROVE FILTERING• Keep dictionary up to date

• Whitelist

• Levenshtein distance

• Soundex functions (where a word sounds like another)

• Naive bayesian inference filtering of phrases/terms

Framework Days. IT Saturday. 5.09.2015

Page 47: Building Profanity Filters: clbuttic sh!t

POST-MODERATION

Framework Days. IT Saturday. 5.09.2015

alive moderatorssolid community

flag abuse

Page 48: Building Profanity Filters: clbuttic sh!t

DIRTY WORDS• list of dirty words in different languages

https://github.com/shutterstock/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words

• list of dirty words i’ve used

https://gist.github.com/vixentael/5ce4168e3e94d9686405

Framework Days. IT Saturday. 5.09.2015

Page 50: Building Profanity Filters: clbuttic sh!t

THANK YOU FOR WATCHING!

Framework Days. IT Saturday. 5.09.2015