-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbias.js
63 lines (52 loc) · 1.45 KB
/
bias.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function tokenize(input) {
return $.map(input.replace('/ {2,}/', ' ')
.toLowerCase()
.split(' '), $.trim);
}
function getMatches(string, regex, index) {
index || (index = 1);
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index].trim());
}
return matches;
}
function bias(phrase) {
var tokens = tokenize(phrase),
coding = 0,
feminine_words = [],
masculine_words = [],
feminine_word_count = 0,
masculine_word_count = 0;
/*
create a cleaned up document in which to perform word stem searches.
*/
var doc = tokens.join(" ");
feminine_words = getMatches(doc, regex_feminine_coded_words, 1);
masculine_words = getMatches(doc, regex_masculine_coded_words, 1);
feminine_word_count = feminine_words.length;
masculine_word_count = masculine_words.length;
var coding_score = feminine_word_count - masculine_word_count;
if (coding_score === 0) {
if (feminine_word_count) {
coding = "neutral";
} else {
coding = "empty, no gendered words found";
}
} else if (coding_score > 3) {
coding = "strongly feminine-coded";
} else if (coding_score > 0) {
coding = "feminine-coded";
} else if (coding_score < -3) {
coding = "strongly masculine-coded";
} else {
coding = "masculine-coded";
}
return {
verdict: coding,
coding_score: coding_score,
feminine_words: feminine_words,
masculine_words: masculine_words
};
}