bravey
Version:
A simple JavaScript NLP-like library to help you creating your own bot.
173 lines (131 loc) • 14.2 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3> </h3>
<section>
<article><h2>Welcome to Bravey!</h2><p>Bravey is a simple JavaScript <a href="https://en.wikipedia.org/wiki/Natural_language_processing">NLP</a>-like library for conversational interfaces that can be used with Node.js or browser.
It's built for help you on joining the conversational interfaces bandwagon, so it should be easy enough to use, integrate and understand, so you can spice up your <a href="https://en.wikipedia.org/wiki/Internet_bot">bots</a> or start creating your own.</p>
<p>Bravey was thought with simplicity in mind: it supports a number of processors, mostly based on <a href="https://en.wikipedia.org/wiki/Naive_Bayes_spam_filtering">bayesian filters</a>, with different features and accuracy and some customizable entity recognizers based on regular expressions chaining.</p>
<h3>Installation</h3><h4>Via NPM</h4><p>Add Bravey to your project with your usual...</p>
<pre class="prettyprint source"><code>npm install bravey</code></pre><p>... and your're ready to go.</p>
<pre class="prettyprint source lang-javascript"><code>var Bravey = require("bravey");
var nlp = new Bravey.Nlp.Fuzzy();
nlp.addDocument("I want a pizza!", "pizza", { fromFullSentence: true, expandIntent: true });
nlp.addDocument("I want some pasta!", "pasta", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("Want pizza, please").intent);
// "pizza"</code></pre><h4>Via SCRIPT tag</h4><p>Include the <code>bravey.js</code> or <code>bravey.min.js</code> you can find into the <code>build/</code> directory in your web page. It will be available after the page loading.</p>
<pre class="prettyprint source lang-html"><code><html>
<head>
<script src="bravey.js"></script>
</head>
<body onload="test()">
What you want is... <span id='product'></span>!
</body>
<script>
function test() {
var nlp = new Bravey.Nlp.Fuzzy();
nlp.addDocument("I want a pizza!", "pizza", { fromFullSentence: true, expandIntent: true });
nlp.addDocument("I want some pasta!", "pasta", { fromFullSentence: true, expandIntent: true });
document.getElementById("product").innerHTML=nlp.test("Want pizza, please").intent;
}
</script>
</html></code></pre><h3>Getting started</h3><p>You can basically use Bravey from a single object.</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addDocument("I want a pizza!", "pizza", { fromFullSentence: true, expandIntent: true });
nlp.addDocument("I want some pasta!", "pasta", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("Want pizza, please").intent);
// "pizza"</code></pre><p>You can extract some features from a sentence:</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addEntity(new Bravey.NumberEntityRecognizer("quantity"));
nlp.addDocument("I want 2 pizzas!", "pizza", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("Want 3 pizzas, please").entitiesIndex.quantity.value);
// 3</code></pre><p>And some of them have language support too, like in english...</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addEntity(new Bravey.NumberEntityRecognizer("quantity"));
nlp.addEntity(new Bravey.Language.EN.TimeEntityRecognizer("delivery_time"));
nlp.addDocument("I want 2 pizzas at 12!", "pizza", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("Deliver 3 pizzas for 2pm, please").entitiesIndex);
// { delivery_time: { value: "14:00:00" }, quantity: { value:3 } }</code></pre><p>... or italian.</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addEntity(new Bravey.NumberEntityRecognizer("quantity"));
nlp.addEntity(new Bravey.Language.IT.TimeEntityRecognizer("delivery_time"));
nlp.addDocument("Vorrei 2 pizze per le 3!", "pizza", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("Consegnami 3 pizze per le 2 del pomeriggio!").entitiesIndex);
// { delivery_time: { value: "14:00:00" }, quantity: { value: 3 }}</code></pre><p>... or even portuguese.</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addEntity(new Bravey.NumberEntityRecognizer("quantity"));
nlp.addEntity(new Bravey.Language.PT.TimeEntityRecognizer("delivery_time"));
nlp.addDocument("Quero 2 pizzas para 3:00!", "pizza", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("Me veja 3 pizzas para 2 da tarde!").entitiesIndex);
// { delivery_time: { value: "14:00:00" }, quantity: { value: 3 }}</code></pre><p>That's it!</p>
<h3>Training Bravey</h3><p>You can leave to Bravey intent and entity guessing...</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addDocument("I want a pizza!", "pizza", { fromFullSentence: true, expandIntent: true });
nlp.addDocument("I want some pasta!", "pasta", { fromFullSentence: true, expandIntent: true });
console.log(nlp.test("A pizza, please").intent);
// "pizza"</code></pre><p>Or be more specific:</p>
<pre class="prettyprint source lang-javascript"><code>var nlp = new Bravey.Nlp.Fuzzy();
nlp.addIntent("order_food", [{ entity: "food_name", id: "food_type" }, { entity: "number", id: "quantity" }]);
nlp.addIntent("order_drink", [{ entity: "drink_name", id: "drink_type" }]);
var drinks = new Bravey.StringEntityRecognizer("drink_name");
drinks.addMatch("coke", "coke");
drinks.addMatch("coke", "cola");
drinks.addMatch("mojito", "mojito");
drinks.addMatch("mojito", "moito");
nlp.addEntity(drinks);
var food = new Bravey.StringEntityRecognizer("food_name");
food.addMatch("pizza", "pizza");
food.addMatch("pizza", "pizzas");
food.addMatch("pasta", "pasta");
nlp.addEntity(food);
nlp.addEntity(new Bravey.NumberEntityRecognizer("number"));
nlp.addDocument("I want {number} {food_name}!", "order_food");
nlp.addDocument("I want {drink_name}!", "order_drink");
console.log(nlp.test("Want a moito, please"));
// { intent: "order_drink", entitiesIndex: { drink_type: { value: "mojito" } } }
console.log(nlp.test("I'd like 2 pizzas"));
// { intent: "order_food", entitiesIndex: { food_type: { value: "pizza" }, quantity: { value: 2 } } }
console.log(nlp.test("I'd like some pasta"));
// { intent: "order_food", entitiesIndex: { food_type: { value: "pasta" } } }</code></pre><p>Have a look to the documentation for more ways for training NLP!</p>
<h2>Samples</h2><p>Bravey includes a bunch of samples - you can find them into the "samples" directory.</p>
<h3>Browser samples</h3><p>The "browser" subdirectory contains some samples you can test with your own browser. Most of them are runnable serving the project directory with any web server.</p>
<h4>Playground sample</h4><p>The "playground" sample quickly explains how most of the conversational interfaces NLP technologies works in English and allow you to play and visually configure a Bravey hinstance. Everything works in your browser so any server side scripting language is needed.</p>
<p><img src="doc-static/images/sample-playground.png" alt="Playground sample"></p>
<h4>Opendata sample</h4><p>The "opendata" sample show you how to search a database as-you-type using Bravey. In this case you'll search the Regione Lombardia's museum database opendata in Italian. This example uses a snapshot of that database, so any server side scripting language is needed.</p>
<p><img src="doc-static/images/sample-opendata.png" alt="Opendata sample"></p>
<h4>Adapter sample</h4><p>The "adapter" sample loads a Api.ai package via AJAX and allow you to prepare a query in a NLP-like way using Bravey. No server side scripting language is needed for this example.</p>
<p><img src="doc-static/images/sample-adapter.png" alt="Adapter sample"></p>
<h4>Chatterbox sample</h4><p>"Chatterbox" is a collection of bots built around Bravey. These samples are using a simple custom-built chat UI library called "Chatterbox" which simulates web chatrooms with single or multiple contacts you can use standalone or embed in your own site.
Some of these bots needs a PHP webproxy, which is shipped together with Chatterbox, in order to work properly. No database is needed, so just make sure you've PHP support (5.6.10+) if you want all the demos to work.</p>
<p><img src="doc-static/images/sample-chatterbox.png" alt="Chatterbox sample"></p>
<h3>Node.js samples</h3><p>You can find more exampes into the "nodejs" directory. These examples uses Bravey from Node.js and are invoked from command line.</p>
<h2>Adapter (command line) sample</h2><p>The "adapterCommandLine" example simply replicate the Adapter example within a Node.js hinstance.</p>
<p><img src="doc-static/images/sample-adaptercommandline.png" alt="Adapter (command line) sample"></p>
<h2>Adapter (server) sample</h2><p>The "adapterServer" example uses the Node.js built-in web server in order to serve a single hinstance of Bravey and replies in Api.ai format.</p>
<p><img src="doc-static/images/sample-adapterserver.png" alt="Adapter (server) sample"></p></article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Bravey.ApiAiAdapter.html">ApiAiAdapter</a></li><li><a href="Bravey.ContextManager.html">ContextManager</a></li><li><a href="Bravey.DocumentClassifier.html">DocumentClassifier</a></li><li><a href="Bravey.EMailEntityRecognizer.html">EMailEntityRecognizer</a></li><li><a href="Bravey.Filter.BasicFilter.html">BasicFilter</a></li><li><a href="Bravey.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.EN.DateEntityRecognizer.html">DateEntityRecognizer</a></li><li><a href="Bravey.Language.EN.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.EN.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.Language.EN.Stemmer.html">Stemmer</a></li><li><a href="Bravey.Language.EN.TimeEntityRecognizer.html">TimeEntityRecognizer</a></li><li><a href="Bravey.Language.EN.TimePeriodEntityRecognizer.html">TimePeriodEntityRecognizer</a></li><li><a href="Bravey.Language.IT.DateEntityRecognizer.html">DateEntityRecognizer</a></li><li><a href="Bravey.Language.IT.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.IT.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.Language.IT.Stemmer.html">Stemmer</a></li><li><a href="Bravey.Language.IT.TimeEntityRecognizer.html">TimeEntityRecognizer</a></li><li><a href="Bravey.Language.IT.TimePeriodEntityRecognizer.html">TimePeriodEntityRecognizer</a></li><li><a href="Bravey.Language.PT.DateEntityRecognizer.html">DateEntityRecognizer</a></li><li><a href="Bravey.Language.PT.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.PT.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.Language.PT.Stemmer.html">Stemmer</a></li><li><a href="Bravey.Language.PT.TimeEntityRecognizer.html">TimeEntityRecognizer</a></li><li><a href="Bravey.Language.PT.TimePeriodEntityRecognizer.html">TimePeriodEntityRecognizer</a></li><li><a href="Bravey.Nlp.Fuzzy.html">Fuzzy</a></li><li><a href="Bravey.Nlp.Sequential.html">Sequential</a></li><li><a href="Bravey.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.RegexEntityRecognizer.html">RegexEntityRecognizer</a></li><li><a href="Bravey.SessionManager.InMemorySessionManager.html">InMemorySessionManager</a></li><li><a href="Bravey.StringEntityRecognizer.html">StringEntityRecognizer</a></li><li><a href="Bravey.Text.RegexMap.html">RegexMap</a></li></ul><h3>Namespaces</h3><ul><li><a href="Bravey.html">Bravey</a></li><li><a href="Bravey.Data.html">Data</a></li><li><a href="Bravey.Date.html">Date</a></li><li><a href="Bravey.File.html">File</a></li><li><a href="Bravey.Filter.html">Filter</a></li><li><a href="Bravey.Language.html">Language</a></li><li><a href="Bravey.Language.EN.html">EN</a></li><li><a href="Bravey.Language.IT.html">IT</a></li><li><a href="Bravey.Language.PT.html">PT</a></li><li><a href="Bravey.Nlp.html">Nlp</a></li><li><a href="Bravey.SessionManager.html">SessionManager</a></li><li><a href="Bravey.Text.html">Text</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>