Skip to content

Commit

Permalink
Merge pull request #8 from marcellobarile/develop
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
marcellobarile authored Oct 29, 2021
2 parents 56f8e53 + fa4103b commit e9deb3f
Show file tree
Hide file tree
Showing 249 changed files with 321,155 additions and 3,626 deletions.
32 changes: 18 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"rules": {
"curly": [2, "multi-line"],
"eol-last": [2],
"indent": [2, 4],
"quotes": [2, "single"],
"linebreak-style": [2, "unix"],
"max-len": [2, 120, 4],
"semi": [2, "always"],
"strict": [2, "never"]
},
"env": {
"node": true
},
"extends": "eslint:recommended"
"rules": {
"curly": [2, "multi-line"],
"eol-last": [2],
"indent": [2, 2],
"quotes": [2, "single"],
"max-len": [2, 120, 4],
"semi": [2, "always"],
"strict": [2, "never"],
"no-console": 0
},
"parserOptions": {
"ecmaVersion": 2018
},
"env": {
"node": true,
"es6": true
},
"extends": "eslint:recommended"
}
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* MacOS */
.DS_Store

/* NPM */
/node_modules
npm*

/* Code Coverage */
coverage
.nyc_output

/* Other */
.notes.txt
/utils
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
179 changes: 91 additions & 88 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ var path = require('path');

// File paths
var AFINN_PATH = path.resolve(__dirname, 'languages');
var EMOJI_PATH = path.resolve(__dirname, 'emojis/Emoji_Sentiment_Data_v1.0.csv');
var EMOJI_PATH = path.resolve(
__dirname,
'emojis/Emoji_Sentiment_Data_v1.0.csv'
);
var RESULT_PATH = path.resolve(__dirname, 'output/build-{lang}.json');

/**
Expand All @@ -14,42 +17,42 @@ var RESULT_PATH = path.resolve(__dirname, 'output/build-{lang}.json');
* @return {void}
*/
function processEmoji(hash, callback) {
// Read file
fs.readFile(EMOJI_PATH, 'utf8', function (err, data) {
if (err) return callback(err);
// Read file
fs.readFile(EMOJI_PATH, 'utf8', function (err, data) {
if (err) return callback(err);

// Split data by new line
data = data.split(/\n/);

// Iterate over dataset and add to hash
for (var i in data) {
var line = data[i].split(',');

// Validate line
if (i == 0) continue; // Label
if (line.length !== 9) continue; // Invalid

// Establish sentiment value
var emoji = String.fromCodePoint(line[1]);
var occurences = line[2];
var negCount = line[4];
var posCount = line[6];
var score = posCount / occurences - negCount / occurences;
var sentiment = Math.floor(5 * score);

// Validate score
if (Number.isNaN(sentiment)) continue;
if (sentiment === 0) continue;

// Add to hash
hash[emoji] = {
coeff: sentiment,
lang: '*',
};
}

// Split data by new line
data = data.split(/\n/);

// Iterate over dataset and add to hash
for (var i in data) {
var line = data[i].split(',');

// Validate line
if (i == 0) continue; // Label
if (line.length !== 9) continue; // Invalid

// Establish sentiment value
var emoji = String.fromCodePoint(line[1]);
var occurences = line[2];
var negCount = line[4];
var posCount = line[6];
var score = (posCount / occurences) - (negCount / occurences);
var sentiment = Math.floor(5 * score);

// Validate score
if (Number.isNaN(sentiment)) continue;
if (sentiment === 0) continue;

// Add to hash
hash[emoji] = {
coeff: sentiment,
lang: '*'
};
}

callback(null, hash);
});
callback(null, hash);
});
}

/**
Expand All @@ -59,65 +62,65 @@ function processEmoji(hash, callback) {
* @return {void}
*/
function processAFINN(hash, callback) {
var initialHash = Object.assign({}, hash);

fs.readdirSync(AFINN_PATH).forEach(function(file) {
if (file.indexOf('AFINN') < 0) {
return;
}

var filePath = AFINN_PATH + '/' + file;
var lang = file.match(/AFINN-(.*)\.json/);
var langHash = Object.assign({}, initialHash);

if (fs.lstatSync(filePath).isDirectory()) {
return;
}

var jsonContent = JSON.parse(
fs.readFileSync(filePath, 'utf8')
);

for(var i in jsonContent) {
if (i.length > 1) {
var index = i.toLowerCase();
var obj = {
coeff: jsonContent[i],
lang: lang[1]
};
langHash[index] = obj;
hash[index] = obj;
}
}

var langHashStr = JSON
.stringify(langHash)
.replace(/\s(?=([^"]*"[^"]*")*[^"]*$)/, '');

fs.writeFile(
RESULT_PATH.replace('{lang}', lang[1]),
langHashStr,
function (err) {
if (err) return callback(err);
}
);
});
var initialHash = Object.assign({}, hash);

fs.readdirSync(AFINN_PATH).forEach(function (file) {
if (file.indexOf('AFINN') < 0) {
return;
}

var filePath = AFINN_PATH + '/' + file;
var lang = file.match(/AFINN-(.*)\.json/);
var langHash = Object.assign({}, initialHash);

if (fs.lstatSync(filePath).isDirectory()) {
return;
}

var jsonContent = JSON.parse(fs.readFileSync(filePath, 'utf8'));

for (var i in jsonContent) {
if (i.length > 1) {
var index = i.toLowerCase();
var obj = {
coeff: jsonContent[i],
lang: lang[1],
};
langHash[index] = obj;
hash[index] = obj;
}
}

var langHashStr = JSON.stringify(langHash).replace(
/\s(?=([^"]*"[^"]*")*[^"]*$)/,
''
);

callback(null, hash);
fs.writeFile(
RESULT_PATH.replace('{lang}', lang[1]),
langHashStr,
function (err) {
if (err) return callback(err);
}
);
});

callback(null, hash);
}

// Execute build process
async.waterfall([
async.waterfall(
[
function (cb) {
cb(null, {});
cb(null, {});
},
processEmoji,
processAFINN
], function(err, result) {
processAFINN,
],
function (err, result) {
if (err) throw new Error(err);
process.stderr.write(
'Complete: ' +
Object.keys(result).length +
' entries.\n'
'Complete: ' + Object.keys(result).length + ' entries.\n'
);
});
}
);
2,619 changes: 2,618 additions & 1 deletion build/languages/AFINN-af.json

Large diffs are not rendered by default.

2,849 changes: 2,848 additions & 1 deletion build/languages/AFINN-am.json

Large diffs are not rendered by default.

3,838 changes: 3,837 additions & 1 deletion build/languages/AFINN-ar.json

Large diffs are not rendered by default.

2,570 changes: 2,569 additions & 1 deletion build/languages/AFINN-az.json

Large diffs are not rendered by default.

2,800 changes: 2,799 additions & 1 deletion build/languages/AFINN-be.json

Large diffs are not rendered by default.

2,881 changes: 2,880 additions & 1 deletion build/languages/AFINN-bg.json

Large diffs are not rendered by default.

2,656 changes: 2,655 additions & 1 deletion build/languages/AFINN-bn.json

Large diffs are not rendered by default.

2,819 changes: 2,818 additions & 1 deletion build/languages/AFINN-bs.json

Large diffs are not rendered by default.

2,816 changes: 2,815 additions & 1 deletion build/languages/AFINN-ca.json

Large diffs are not rendered by default.

2,826 changes: 2,825 additions & 1 deletion build/languages/AFINN-ceb.json

Large diffs are not rendered by default.

3,230 changes: 3,229 additions & 1 deletion build/languages/AFINN-co.json

Large diffs are not rendered by default.

2,857 changes: 2,856 additions & 1 deletion build/languages/AFINN-cs.json

Large diffs are not rendered by default.

2,549 changes: 2,548 additions & 1 deletion build/languages/AFINN-cy.json

Large diffs are not rendered by default.

2,873 changes: 2,872 additions & 1 deletion build/languages/AFINN-da.json

Large diffs are not rendered by default.

2,807 changes: 2,806 additions & 1 deletion build/languages/AFINN-de.json

Large diffs are not rendered by default.

2,858 changes: 2,857 additions & 1 deletion build/languages/AFINN-el.json

Large diffs are not rendered by default.

Loading

0 comments on commit e9deb3f

Please sign in to comment.