Created
March 17, 2015 15:11
-
-
Save SharpCoder/42f2ca1c2a1863aa8cf1 to your computer and use it in GitHub Desktop.
moby posi nodejs
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
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