Skip to content

Commit

Permalink
Read data + more package info.
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszdziuk committed Nov 5, 2013
1 parent f572d3b commit ea33bf2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ wordnet.lookup(word, function(err, definition) {
return;
}

console.log('[%s]\n\n%s', word, definition);
console.log('[%s]\n\n', word, definition);

});
30 changes: 28 additions & 2 deletions lib/wordnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ function parseIndexLine(line, callback) {

function parseDataLine(line, callback) {

/* Split the glossary */
var parts = line.split('|');
var metadata = parts[0].split(' ');
var glossary = parts[1].trim();

/* Parse the metadata */
var meta = {};
meta.synsetOffset = parseInt(metadata.shift(), 10);
meta.lexFilenum = parseInt(metadata.shift(), 10);
meta.synsetType = metadata.shift();
meta.wordCount = parseInt(metadata.shift(), 16);
meta.words = [];

/* Parse the words */
for (var wordIdx = 0; wordIdx < meta.wordCount; wordIdx++) {
meta.words.push({
word: metadata.shift(),
lexId: parseInt(metadata.shift(), 16)
});
}

callback(null, {
meta: meta,
rest: metadata,
glossary: glossary
});

};

/**
Expand All @@ -140,8 +167,7 @@ function readData(definition, callback) {
fs.read(fd, buffer, 0, 1024, offset, function(err, bytesRead, buffer) {

var line = buffer.toString().split('\n')[0];
// parseDataLine(line, callback);
callback(null, line);
parseDataLine(line, callback);

});

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WordNet.js",
"version": "0.0.1",
"name": "wordnet",
"version": "0.1.0",
"description": "Node.js wrapper for WordNet DB",
"main": "./lib/wordnet.js",
"dependencies": {
Expand All @@ -9,6 +9,7 @@
"devDependencies": {
"commander": "~2.0.0"
},
"repository": "https://github.com/dariuszdziuk/wordnet",
"author": "Dariusz Dziuk <me@dariuszdziuk.com>",
"license": "MIT"
}

0 comments on commit ea33bf2

Please sign in to comment.