overlap of words in a sentence or phrase to determine whether they are referring to the same context
npm install word-overlap#word-overlap
    
> Check the number of words overlapping between 2 phrases or sentences
Used in cases to check whether 2 titles / sentences / phrases are referring to the same context. E.g. 2 event names.
##Install
1. with npm
``js`
npm install word-overlap
main.js
- with browserify
1. in file
`js
// in main.js
var overlap = require('word-overlap');
var sentence1 = 'The Hitchhikings Meetup in Betelgeuse by Ford Prefect';
var sentence2 = 'The hitchhikings meetups by the hitchhikers';
var reply = overlap(sentence1, sentence2, {
ignoreCase: true,
minWordLength: 2,
ignoreCommonWords: true
});
console.log(reply);
`index.html
- in file
`html`
build.js
- make the file
`shell`
browserify main.js -o build.js --exclude WNdb --exclude lapack
##Usage
`js
var overlap = require('word-overlap');
var sentence1 = 'The Hitchhikings Meetup in Betelgeuse by Ford Prefect';
var sentence2 = 'The hitchhikings meetups by the hitchhikers';
`
###simple case
`js`
overlap(sentence1, sentence2);
// [ 'The', 'by' ]
###option: ignore case
`js`
overlap(sentence1, sentence2, {
ignoreCase: true
});
// [ 'the', 'hitchhikings', 'by' ]
###option: min word length
`js`
overlap(sentence1, sentence2, {
ignoreCase: true,
minWordLength: 2
});
// [ 'the', 'hitchhiking', 'by' ]
###option: ignore default common words
Common words by default include: *a, an, the, this, that, there, it, in, on, for, not, your, you, at,
to, is, us, out, by, I*
`js`
overlap(sentence1, sentence2, {
ignoreCase: true,
minWordLength: 2,
ignoreCommonWords: true
});
// [ 'hitchhikings' ]
###option: ignore number
Ignore numbers such as: 5e3, 0xff, -1.1, 0, 1, 1.1, 10, 10.10, 100, '-1.1', etc.
`js`
sentence1 = 'Welcome to 2015';
sentence2 = '2015 Meetup for the year';
console.log(overlap(sentence1, sentence2, {
ignoreNumber: true
}));
// [ ]
###option: add your common words to ignore
`js`
overlap(sentence1, sentence2, {
ignoreCase: true,
minWordLength: 2,
ignoreCommonWords: true,
common: [ 'hitchhikings' ]
});
// [ ]
###option: depluralize words
`js`
overlap(sentence1, sentence2, {
ignoreCase: true,
minWordLength: 2,
ignoreCommonWords: true,
depluralize: true
});
// [ 'hitchhiking', 'meetup' ]
###option: depluralize words with plurals to ignore
`js`
overlap(sentence1, sentence2, {
ignoreCase: true,
minWordLength: 2,
ignoreCommonWords: true,
depluralize: true,
ignorePlurals: [ 'hitchhikings' ]
});
// [ 'hitchhikings', 'meetup' ]
###option: stemming
`js
var sentence1 = 'A programming course in SmallTalk';
var sentence2 = 'Have you programmed in SmallTalk?';
overlap(sentence1, sentence2, {
stemming: true,
ignoreCommonWords: true
});
// [ 'program', 'smalltalk' ]
`
Try out the examples in file example.js with the command node example.js
##Contribute
Please see CONTRIBUTING.md for details.
##Versioning
This repository follows the Semantic Versioning guidelines:
1. For patches, run grunt bumpgrunt bump:minor
- For minor release, run grunt bump:major`
- For major release, run
##License
(C) Sayanee Basu 2014, released under an MIT license