Skip to content

Commit

Permalink
Better example.
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszdziuk committed Nov 5, 2013
1 parent ea33bf2 commit d8d380e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
19 changes: 17 additions & 2 deletions examples/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ if (!word) {
program.help();
}

wordnet.lookup(word, function(err, definition) {
wordnet.lookup(word, function(err, definitions) {

if (err) {
console.log('An error occured: %s', err);
return;
}

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

/* Definitions */
definitions.forEach(function(definition) {

console.log(' type : %s', definition.meta.synsetType);
var words = '';
definition.meta.words.forEach(function(word) {
words += word.word + ' ';
});
console.log(' words: %s', words.trim());
console.log(' %s', definition.glossary);

console.log();

});

});
29 changes: 27 additions & 2 deletions lib/wordnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ var _extensions = [
'verb'
];

/**
* Synset types map
*
* @type {Object}
*/

var _synsetTypeMap = {
'n': 'noun',
'v': 'verb',
's': 'adjective',
's': 'adjective satellite',
'r': 'adverb'
};

/**
* Index lookup
*
Expand Down Expand Up @@ -129,7 +143,7 @@ function parseDataLine(line, callback) {
var meta = {};
meta.synsetOffset = parseInt(metadata.shift(), 10);
meta.lexFilenum = parseInt(metadata.shift(), 10);
meta.synsetType = metadata.shift();
meta.synsetType = _synsetTypeMap[metadata.shift()];
meta.wordCount = parseInt(metadata.shift(), 16);
meta.words = [];

Expand All @@ -141,9 +155,20 @@ function parseDataLine(line, callback) {
});
}

/* Parse the pointers */
meta.pointerCount = parseInt(metadata.shift(), 10);
meta.pointers = [];
for (var pointerIdx = 0; pointerIdx < meta.pointerCount; pointerIdx++) {
meta.pointers.push({
pointerSymbol: metadata.shift(),
synsetOffset: parseInt(metadata.shift(), 10),
pos: metadata.shift(),
sourceTargetHex: metadata.shift()
});
}

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

Expand Down

0 comments on commit d8d380e

Please sign in to comment.