Skip to content

Commit

Permalink
docs(*): complete documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayaksaxena committed Mar 28, 2018
1 parent f4ebba3 commit 7d30adf
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 205 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Use [npm](https://www.npmjs.com/package/wink-lemmatizer) to install:
// Load wink-lemmatizer
var lemmatize = require( 'wink-lemmatizer' );

// Lemmatize adjectives
lemmatize.adjective( 'farthest' );
// -> 'far'
lemmatize.adjective( 'coolest' );
// -> 'cool'
lemmatize.adjective( 'easier' );
// -> 'easy'

// Lemmatize nouns
lemmatize.noun( 'knives' );
// -> 'knife'
Expand All @@ -34,14 +42,6 @@ lemmatize.verb( 'pushes' );
// -> 'push'
lemmatize.verb( 'suggesting' );
// -> 'suggest'

// Lemmatize adjectives
lemmatize.verb( 'farthest' );
// -> 'far'
lemmatize.verb( 'coolest' );
// -> 'cool'
lemmatize.verb( 'easier' );
// -> 'easy'
```

### Documentation
Expand Down
24 changes: 13 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ <h3>Getting Started</h3>
<pre class='hljs'><span class="hljs-comment">// Load wink-lemmatizer</span>
<span class="hljs-keyword">var</span> lemmatize = <span class="hljs-built_in">require</span>( <span class="hljs-string">'wink-lemmatizer'</span> );

<span class="hljs-comment">// Lemmatize adjectives</span>
lemmatize.adjective( <span class="hljs-string">'farthest'</span> );
<span class="hljs-comment">// -&gt; 'far'</span>
lemmatize.adjective( <span class="hljs-string">'coolest'</span> );
<span class="hljs-comment">// -&gt; 'cool'</span>
lemmatize.adjective( <span class="hljs-string">'easier'</span> );
<span class="hljs-comment">// -&gt; 'easy'</span>

<span class="hljs-comment">// Lemmatize nouns</span>
lemmatize.noun( <span class="hljs-string">'knives'</span> );
<span class="hljs-comment">// -&gt; 'knife'</span>
Expand All @@ -107,15 +115,7 @@ <h3>Getting Started</h3>
lemmatize.verb( <span class="hljs-string">'pushes'</span> );
<span class="hljs-comment">// -&gt; 'push'</span>
lemmatize.verb( <span class="hljs-string">'suggesting'</span> );
<span class="hljs-comment">// -&gt; 'suggest'</span>

<span class="hljs-comment">// Lemmatize adjectives</span>
lemmatize.verb( <span class="hljs-string">'farthest'</span> );
<span class="hljs-comment">// -&gt; 'far'</span>
lemmatize.verb( <span class="hljs-string">'coolest'</span> );
<span class="hljs-comment">// -&gt; 'cool'</span>
lemmatize.verb( <span class="hljs-string">'easier'</span> );
<span class="hljs-comment">// -&gt; 'easy'</span></pre>
<span class="hljs-comment">// -&gt; 'suggest'</span></pre>
<h3>Documentation</h3>
<p>Check out the <a href="http://winkjs.org/wink-lemmatizer/">lemmatizer API documentation</a> to learn more.</p>
<h3>Need Help?</h3>
Expand Down Expand Up @@ -223,7 +223,8 @@ <h3 class='fl m0' id='verb'>
</div>


<p>Conjugates a <code>verb</code> to it's base form (VB).</p>
<p>Conjugates a <code>verb</code> to it's base form (VB). It also has an alias
<code>lemmatizeVerb</code> to maintain API level compatibility with preivious version.</p>


<div class='pre p1 fill-light mt0'>verb(verb: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></div>
Expand Down Expand Up @@ -301,7 +302,8 @@ <h3 class='fl m0' id='noun'>
</div>


<p>Converts the input <code>noun</code> to it's singular form.</p>
<p>Converts the input <code>noun</code> to it's singular form. It also has an alias
<code>lemmatizeNoun</code> to maintain API level compatibility with preivious version.</p>


<div class='pre p1 fill-light mt0'>noun(noun: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></div>
Expand Down
85 changes: 0 additions & 85 deletions src/lemmatize-nnx.js

This file was deleted.

89 changes: 0 additions & 89 deletions src/lemmatize-vbx.js

This file was deleted.

62 changes: 50 additions & 12 deletions src/wink-lemmatizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,30 @@
// General Public License along with “wink-lemmatizer”.
// If not, see <http://www.gnu.org/licenses/>.

// Load adjective/noun/verb exceptions.
const adjectiveExceptions = require( 'wink-lexicon/src/wn-adjective-exceptions.js' );
const verbExceptions = require( 'wink-lexicon/src/wn-verb-exceptions.js' );
const nounExceptions = require( 'wink-lexicon/src/wn-noun-exceptions.js' );
const verbExceptions = require( 'wink-lexicon/src/wn-verb-exceptions.js' );
// Load all words (base form),
const words = require( 'wink-lexicon/src/wn-words.js' );
// and their senses.
const senseMap = require( 'wink-lexicon/src/wn-word-senses.js' );
// The name space.
const lemmatize = Object.create( null );

// The following code is an adaptation of [WordNet's Morphy](https://wordnet.princeton.edu/documentation/morphy7wn):

// ### isAdjective
/**
* @private
* Checks the word in base form is an adjective or not using wordnet senses.
*
* @param {string} word — that needs to be tested for adjective.
* @return {boolean} `true` if word is a valid adjective otherwise `false.`
* @example
* isAdjective( 'lat' );
* // -> false
*/
var isAdjective = function ( word ) {
const index = words[ word ];
if ( index === undefined ) return false;
Expand All @@ -35,7 +52,7 @@ var isAdjective = function ( word ) {
if ( senses[ k ] < 2 ) return true;
}
return false;
};
}; // isAdjective()

// ### lemmatizeAdjective
/**
Expand All @@ -58,9 +75,19 @@ lemmatize.adjective = function ( adjective ) {
lemma += 'e';
if ( isAdjective( lemma ) ) return lemma;
return adjective;
};

}; // adjective()

// ### isVerb
/**
* @private
* Checks the word in base form is a verb or not using wordnet senses.
*
* @param {string} word — that needs to be tested for verb.
* @return {boolean} `true` if word is a valid verb otherwise `false.`
* @example
* isVerb( 'eat' );
* // -> true
*/
var isVerb = function ( word ) {
const index = words[ word ];
if ( index === undefined ) return false;
Expand All @@ -69,12 +96,13 @@ var isVerb = function ( word ) {
if ( senses[ k ] > 28 && senses[ k ] < 44 ) return true;
}
return false;
};
}; // isVerb()

// ### lemmatizeVerb
/**
*
* Conjugates a `verb` to it's base form (VB).
* Conjugates a `verb` to it's base form (VB). It also has an alias
* `lemmatizeVerb` to maintain API level compatibility with preivious version.
*
* @param {string} verb — that needs to be conjugated to base form.
* @return {string} the base form of `verb`.
Expand All @@ -99,7 +127,7 @@ lemmatize.verb = function ( verb ) {
if ( isVerb( lemma ) ) return lemma;
}
return verb;
};
}; // verb()

const nounRegexes = [
{ replace: /s$/, by: '' },
Expand All @@ -113,6 +141,17 @@ const nounRegexes = [
{ replace: /ies$/, by: 'y' }
];

// ### isNoun
/**
* @private
* Checks the word in base form is a noun or not using wordnet senses.
*
* @param {string} word — that needs to be tested for noun.
* @return {boolean} `true` if word is a valid noun otherwise `false.`
* @example
* isAdjective( 'house' );
* // -> true
*/
var isNoun = function ( word ) {
const index = words[ word ];
if ( index === undefined ) return false;
Expand All @@ -121,12 +160,13 @@ var isNoun = function ( word ) {
if ( senses[ k ] > 2 && senses[ k ] < 29 ) return true;
}
return false;
};
}; // isNoun()

// ### lemmatizeNoun
/**
*
* Converts the input `noun` to it's singular form.
* Converts the input `noun` to it's singular form. It also has an alias
* `lemmatizeNoun` to maintain API level compatibility with preivious version.
*
* @param {string} noun — that needs to be lemmatized.
* @return {string} the singular of `noun`.
Expand All @@ -146,13 +186,11 @@ lemmatize.noun = function ( noun ) {
}

return noun;
};
}; // noun()

// Create alias to maintain backwards compatibility.
lemmatize.lemmatizeNoun = lemmatize.noun;
lemmatize.lemmatizeVerb = lemmatize.verb;
lemmatize.lemmatizeAdjective = lemmatize.adjective;

module.exports = lemmatize;

// console.log( lemmatize.verb( 'lates') )

0 comments on commit 7d30adf

Please sign in to comment.