Skip to content

Commit

Permalink
Merge branch 'master' of github.com:julijonas/emojifier
Browse files Browse the repository at this point in the history
  • Loading branch information
dovito committed Jan 20, 2018
2 parents bbf719a + 2b4a2d7 commit b0959c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
30 changes: 30 additions & 0 deletions get_emoji.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
import {emojis} from './tag_emojis'

function getEmotionVector(jsonFile){
var inputVector = [];
const emotions = jsonFile[0].scores;
for (const value of Object.values(emotions)) {
inputVector.push(value);
}

return inputVector;
}

function getClosedEmoji(jsonFile){
const inputEmotion = getEmotionVector(jsonFile);
let minDistanceEmotion = Number.POSITIVE_INFINITY;
let closedEmoji;
let distanceSquared;

for (const [fileName,values] of Object.entries(emojis)) {
distanceSquared = 0;
for(let i = 0; i < 8; i++){
distanceSquared += Math.pow(values[i] - inputEmotion[i],2);
}
if(Math.sqrt(distanceSquared) < minDistanceEmotion){
closedEmoji = fileName;
minDistanceEmotion = Math.sqrt(distanceSquared);
}
}

return closedEmoji;
}
3 changes: 1 addition & 2 deletions tag_emojis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

const emojis = {
export const emojis = {
"001-embarrassed-4.png": [0, 0, 0, 0.3, 0.4, 0, 0, 0.3],
"002-sad-14.png": [0.2, 0.1, 0.1, 0.1, 0, 0, 0.5, 0],
"004-surprised-1.png": [0, 0, 0, 0.2, 0, 0, 0, 0.8],
Expand Down

0 comments on commit b0959c1

Please sign in to comment.