Skip to content

Commit

Permalink
fix ing verbs
Browse files Browse the repository at this point in the history
  • Loading branch information
notwaldorf committed Jun 14, 2017
1 parent 96f3d02 commit b31e772
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
23 changes: 20 additions & 3 deletions emoji-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ function getAllEmojiForWord(originalWord) {
// Maybe this is a singular word but the word is the plural?
// Don't do this for single letter since that will pluralize crazy things.
let maybePlural = (word.length == 1) ? '' : word + 's';
let maybeVerbed = (word.indexOf('ing') == -1) ? '' : word.substr(0, word.length-3);

let maybeVerbedSimple = '';
let maybeVerbedVowel = '';
let maybeVerbedDoubled = '';

if (word.indexOf('ing') !== -1) {
let verb = word.substr(0, word.length - 3);
// eating -> eat
maybeVerbedSimple = verb;
// dancing -> dance
maybeVerbedVowel = verb + 'e';
// running -> run
maybeVerbedDoubled = verb.substr(0, verb.length - 1);
}

// Go through all the things and find the first one that matches.
let useful = [];
Expand All @@ -64,13 +77,17 @@ function getAllEmojiForWord(originalWord) {

for (let emoji in allEmoji) {
let words = allEmoji[emoji].keywords;
// TODO: omg refactor this one day, please. Why is this even. Why.
if (word == allEmoji[emoji].char ||
emoji == word || (emoji == word + '_face') ||
emoji == maybeSingular || emoji == maybePlural || emoji == maybeVerbed ||
emoji == maybeSingular || emoji == maybePlural ||
emoji == maybeVerbedSimple || emoji == maybeVerbedVowel || emoji == maybeVerbedDoubled ||
(words && words.indexOf(word) >= 0) ||
(words && words.indexOf(maybeSingular) >= 0) ||
(words && words.indexOf(maybePlural) >= 0) ||
(words && words.indexOf(maybeVerbed) >= 0)) {
(words && words.indexOf(maybeVerbedSimple) >= 0) ||
(words && words.indexOf(maybeVerbedVowel) >= 0) ||
(words && words.indexOf(maybeVerbedDoubled) >= 0)) {
// If it's a two letter word that got translated to a flag, it's 99% of the
// time incorrect, so stop doing that.
if (!(word.length <= 3 && allEmoji[emoji].category == 'flags')) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moji-translate",
"version": "1.0.6",
"version": "1.0.7",
"description": "A library that translates english words to emoji",
"main": "emoji-translate.js",
"scripts": {
Expand Down
35 changes: 24 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,40 @@ test('translate', function (t) {
t.end();
});

test('annoying translations', function(t) {
test('punctuation', function(t) {
// Exclamation marks should be preserved
t.equal(2, translate.translate('YES! victory!').match(/!/g).length);
t.equal(null, translate.translate('YES! victory!', true).match(/!/g));
t.end();
});

test('flags', function(t) {
// these should not be flags.
t.equal('im', translate.translate('im').trim());
t.equal('in', translate.translate('in').trim());

// t.equal('is', translate.translate('is').trim());
// t.equal('am', translate.translate('am').trim());
// YES should not have a flag.
t.equal(-1, translate.getAllEmojiForWord('yes').indexOf('🇾🇪'));
t.end();
});

// hi should work
t.notEqual('hi', translate.translate('hi').trim());
test('hard coded words', function(t) {
t.notEqual('i am', translate.translate('i am').trim());
t.notEqual('she he is', translate.translate('she he is').trim());
t.notEqual('we they are', translate.translate('we they are').trim());
t.end();
});

// YES should not have a flag.
t.equal(-1, translate.getAllEmojiForWord('yes').indexOf('🇾🇪'));

// Exclamation marks should be preserved
t.equal(2, translate.translate('YES! victory!').match(/!/g).length);
t.equal(null, translate.translate('YES! victory!', true).match(/!/g));
test('ing verbs', function(t) {
// English sucks. Dance+ing = dancing, run+ing = running, eat+ing = eating;
t.notEqual('saving', translate.translate('saving').trim());
t.notEqual('running', translate.translate('running').trim());
t.notEqual('eating', translate.translate('eating').trim());
t.end();
});

test('omg what is real', function(t) {
t.notEqual('hi', translate.translate('hi').trim());
t.notEqual('', translate.translate('welcome back, emoji robot! ready to take over the world?', true));
t.end();
});

0 comments on commit b31e772

Please sign in to comment.