Skip to content

sub0709/bottom-up-category

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bottom-up-category

Installation

npm install @sub0709/bottom-up-category

usage

const bottom_up_category = require('bottom-up-category');

let keywords = {
	'Health' : ['football', 'basketball'],
	'Style' : ['hair', 'trend'],
	'Digital' : ['computer', 'tv', 'camera'],
	'Shopping' : ['ebay', 'paypal', 'amazon']
};

let categories = bottom_up_category(keywords);

let category = categories.match('You got that James Dean daydream look in your eye');
console.log(category);	//no matched. result : null

category = categories.match('hair');
console.log(category);	//'hair' matched. result : Style

category = categories.match('amazon.com: Online Shopping for Electronics, Apparel');
console.log(category);	//no matched. result : null

category = categories.match('amazon.com: Online Shopping for Electronics, Apparel', function(text, sub_category) {
	return text.indexOf(sub_category) > -1;
});
console.log(category);	//'amazon' matched. result : Shopping

category = categories.match('Scores & Fixtures - Football - BBC Sport', function(text, sub_category) {
	let pattern = RegExp(sub_category, 'i');
	return text.match(pattern);
});
console.log(category);	//'Football' matched. result : Health

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published