Skip to content

Instantly share code, notes, and snippets.

@SharpCoder
Created March 17, 2015 15:11
Show Gist options
  • Save SharpCoder/42f2ca1c2a1863aa8cf1 to your computer and use it in GitHub Desktop.
Save SharpCoder/42f2ca1c2a1863aa8cf1 to your computer and use it in GitHub Desktop.
moby posi nodejs
var dictionary = {};
module.exports = {
init: function(callback) {
var fs = require('fs');
fs.readFile('./moby/mobyposi.i', 'utf8', function( err, data ) {
var text = data.toString('utf8');
var word = '', cat = '';
var left = false;
// Iterate over the list.
for ( var i = 0; i < text.length; i++ ) {
// Get the double byte.
var a = text.charCodeAt(i);
// Check if it's a delimiter.
if ( a == 13 ) {
// End of line
dictionary[word] = cat;
word = '';
cat = '';
left = false;
} else if ( a == 65533 ) {
left = true;
} else if ( left ) {
cat += text[i];
} else {
word += text[i];
}
}
// callback
if ( callback )
callback.call(this, null, dictionary);
});
},
get: function( word ) {
return dictionary[word];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment