Recipe Search Parser
An algorithms for transforming natural language search into categories. Allows the users input to be formatted into categories and then used as system for filtering and grouping.
Installation
Using npm
npm install recipe-search-parser
Using yarn
yarn add recipe-search-parser
Usage
Import the main class
import SearchParser from "recipe-search-parser";
const searchParser = new SearchParser();
Stringify
The searchParser.stringify(data)
takes four parameters
- query: the normal text the user searched for
- categories: the category in which the item is
- include: list of ingredients that the result should include
- exclude: list of ingredients that the result should exclude
const query = "cake with chocolate"
const category = "sweet"
const include = ["sugar", "flour"]
const exclude = ["salt"]
searchParser.stringify({
query,
category,
include,
exclude
})
// Return: cake-with-cholocate-categoria-sweet-con-sugar-flour-senza-salt
Parse
The searchParser.parse(data)
takes one parameter URL
. The string is then parsed and formatted into query, category, include and exclude.
const URL = "cake-with-cholocate-categoria-sweet-con-sugar-flour-senza-salt"
searchParser.parse(URL)
// Return: {
// query: "cake with chocolate",
// category: "sweet",
// include: ["sugar", "flour"],
// exclude: ["salt"]
Contribute
You are welcome to contribute!