-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added function returning most relevant emoji to a given input
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters