Skip to content

Commit

Permalink
Updated transcoded word lists and styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jonobr1 committed Nov 25, 2018
1 parent 01794b6 commit 60ca3fd
Show file tree
Hide file tree
Showing 5 changed files with 2,447 additions and 19 deletions.
2,319 changes: 2,318 additions & 1 deletion assets/latin-emoji.json

Large diffs are not rendered by default.

Binary file modified book/satyricon.indd
Binary file not shown.
33 changes: 26 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@
<html>
<head>
<meta charset="utf-8">
<title>Cena Trimalchionis</title>
<title>PERDITIS 🏺INVENTIS</title>
<link rel="stylesheet" href="https://use.typekit.net/uhv1skr.css">
<style>
* { margin: 0; padding: 0; }
span {
margin-right: 5px;
}
h1,
h2,
h1, h2,
div.chapter {
padding: 10px;
padding: 0 40px;
}
body {
font-family: mrs-eaves, times, serif;
font-size: 20px;
line-height: 40px;
font-weight: 400;
font-style: normal;
max-width: 710px;
}
h1, div.chapter {
margin-top: 40px;
}
h1, h2, h3, h4, h5, h6 {
font-family: mrs-eaves-roman-petite-caps, sans-serif;
font-weight: 400;
font-style: normal;
letter-spacing: 1px;
text-transform: lowercase;
text-align: center;
margin-bottom: 10px;
}
</style>
</head>
Expand Down Expand Up @@ -64,6 +81,8 @@ <h2>By <span id="author"></span></h2>
}

var contents = chapter.body;
// TODO: Insert carriage returns in here somehow. That's important
// for the final piece.
var words = contents.join('\n').split(/[\s]/);
var domElement = document.createElement('div');

Expand Down
10 changes: 9 additions & 1 deletion merge-emoji-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ function format(emojis) {
var result = [];
for (var name in emojis) {
var keywords = emojis[name];
var wordlist = [];
keywords = _.uniq(keywords.split(' | '));
wordlist = keywords;
// for (var j = 0; j < keywords.length; j++) {
// var keyword = keywords[j].toLowerCase();
// var words = keyword.split(/\s/i);
// wordlist = wordlist.concat(words);
// }
result.push({
emoji: name,
keywords: _.uniq(keywords.split(' | '))
keywords: _.uniq(wordlist)
});
}
console.log(result);
Expand Down
104 changes: 94 additions & 10 deletions transcode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var fs = require('fs');
var path = require('path');
var Fuse = require('fuse.js');
var _ = require('underscore');

var settings = {
Expand All @@ -11,13 +10,6 @@ var emojis = fetch('./assets/emoji-fuse-list.json');
var translations = fetch('./assets/word-translations.json');
var errors = fetch('./assets/word-translation-errors.json');

var fuse = new Fuse(emojis, {
threshold: 0.01,
distance: 5,
findAllMatches: true,
keys: ['keywords']
});

var transcodes = lookup(translations);

fs.writeFileSync(path.resolve(__dirname, './assets/latin-emoji.json'), JSON.stringify(transcodes), settings.encoding);
Expand All @@ -34,18 +26,19 @@ function lookup(list) {
var query;

if (_.isBoolean(english)) {
query = fuse.search(latin);
query = search(latin);
} else {
if (english.length <= 3) {
console.log('Unable to assign emoji for such a small word');
continue;
}
query = fuse.search(english);
query = search(english);
}

if (query.length > 0) {
emoji = query[0].emoji;
result[latin] = emoji;
cycle(query[0]);
console.log('Assigned', latin, 'to', query);
} else {
console.log('Unable to assign', latin, 'to an emoji');
Expand All @@ -57,6 +50,97 @@ function lookup(list) {

}

/**
* Many of the Emojis have similar definitions like the generic "object"
* assignment. So if emojis have the same score the one in the list
* will always show up first. In this case if an emoji is selected,
* then push it back to the end of the Emojis list in order to let other
* Emojis inhabit the text.
*/
function cycle(obj) {
var index = obj.index;
var item = emojis.splice(index, 1)[0];
if (item) {
emojis.push(item);
}
}

function search(word) {

var query = [];

for (var i = 0; i < emojis.length; i++) {

var emoji = emojis[i];
var keywords = emoji.keywords;
var score = compare(word, keywords);

if (score > 0) {
var item = _.clone(emoji);
item.score = score;
item.index = i;
query.push(item);
}

}

query = query.sort(function(a, b) {
return b.score - a.score;
});

return query;

}

function compare(word, keywords) {

var score = 0;
var amount = 0;

for (var i = 0; i < keywords.length; i++) {

var keyword = keywords[i];

if (keyword.length < 3) {
continue;
}

var subwords = keyword.split(/\s/);

// Only return perfect matches
if (word === keyword) {

score += 1;
amount++;

} else if (subwords.length > 1) {

var matched = false;

for (var j = 0; j < subwords.length; j++) {

var subword = subwords[j];

if (word === subword) {
score += 0.5;
matched = true;
}

}

if (matched) {
amount += subwords.length;
}

}

}

// "Normalize" the score
return score / amount;

}

function fetch(filename) {
var uri = path.resolve(__dirname, filename);
var result = fs.readFileSync(uri, settings);
Expand Down

0 comments on commit 60ca3fd

Please sign in to comment.