Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nlp-router

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nlp-router

associate metadata or calls with patterns of speech and analysis using NLP

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

nlp-router

A means to associate metadata or calls with patterns of speech so that when text is analyzed, a match is provided (along with a level of confidence) so that the program can determine a course of action in response.

Build Status Coverage Status Version npm npm Downloads Dependencies

Designed for use with deftly-bot but generic enough to be used with other approaches. Deftly's declarative resource approach coupled with the initialization process performs the router's initialization which may seem otherwise tedious.

Consider stealing the code (modlo, fount, deftly) to provide your own means of creating a way to associate patterns of speech with methods to be dispatched on matches.

What problem it attempts to solve

Observations of support and operational tooling that makes use of chat interfaces is that it is very difficult to remember specific command patterns and incantations.

This leads not only to command misses and frequent command list invocations (littering the common channel) but can have unintended outcomes.

By utilizing natural speech processing the focus can be on specific keywords, synonyms and possible patterns for a valid request. This follows the paradigm, "be liberal in what you accept".

Chat interfaces are far more welcoming and powerful when they don't expect people to provide explicit/perfect incantations and punish them for omissions, transpositions, and typos.

What it is not

A typical "router" pattern that can be plugged into an HTTP or message dispatch stack directly.

Patterns of Speech

This same table is available in a single document here

TagDescriptionExample
,Comma,
:Mid-sent punctuation:,;
.Sent-final punctuation., !, ?
"quote"
(Left paren(
)Right paren)
#Pound sign#
CCCoordinating conjunctionand, but, or
CDCardinal numberone, two, 1, 2
DTDeterminerthe, some
EXExistential therethere
FWForeign wordmon dieu
INPrepositionof, in, by
JJAdjectivebig
JJRAdjective comparitivebigger
JJSAdjective superlativebiggest
LSList item maker1, One
MDModalcan, should
NNNoun, singular or massdog
NNPProper noun, singularEdingburgh
NNPSProper noun, pluralSmiths
NNSNoun, pluraldogs
PDTPredeterminerall, both
POSPossessive ending's
PPPersonal pronounI, you, she
PRP$Possessive pronounmy, one's
RBAdverbquickly, not
RBRAdverb, comparativefaster
RBSAdverb, superlativefastest
RPParticleup, off
SYMSymbol%, +, &
TO'to'to
UHInterjectionoh, oops
VBVerb, base formeat
VBDVerb, past tenseate
VBGVerb, gerundeating
VBNVerb, past parteaten
VBPVerb, presenteat
VBZVerb, presenteats
WDTWh-determinerwhich, that
WPWh pronounwho, what
WP$Possessive-Whwhose
WRBWh-adverbhow, where

API

The API supports adding, retrieving, changing the value of, and evaluating rule definitions.

addRule (name, definition, value)

Adds a rule to the router and returns a promise that either resolves to the current rank for the rule or rejects with validation errors.

const rank = router.addRule(
  'checkStatus', 
  {}
  engine.checkStatus
)

// rank is the current order of the rule provided

changeValue (name, value)

Changes the value associated with the rule.

router.changeValue('myRule', engine.someNewMethod)

deleteRule (name)

Returns an array with a boolean indicating whether a matching rule was deleted and an integer indicating the number of rules left in the router.

const [deleted, remaining] = router.deleteRule('myRule')

getRule (name)

Returns the rule definition for the name. undefined is returned if the name does not match.

const rule = router.getRule('myRule')

getRank (name)

Returns the current rank for the rule. If the rule name does not match an existing rule, a -1 is returned.

const rank = router.getRank('myRule')

evaluate (sentence)

Evaluates a sentence for a potential match and, if there is a match, returns data extracted from the sentence as well as the value. If no match is found, undefined is returned.

const match = router.evaluate('my voice is my passport verify me')
// match will have the properties `data` and `value`

// it's more likely that you'd want to feed the match into a 
// dispatcher, but YMMV
match.value(match.data.values)

data returned in match

The data returned in the match will contain the properties:

  • sentiment - 'positive'|'neutral'|'mixed'|'negative'
  • confidence - %
  • degree - %
  • dirtiness - %
  • ordered - true|false
  • politeness - %
  • tense - 'past'|'present'
  • tokens - the full token array extracted during sentence analysis
  • type - 'declarative'|'imperative'|'interrogative'
  • values - a hash of name/value pairs extracted

Each token has the following properties:

  • abbreviation - true|false
  • acronym - true|false
  • alt - alternate text for the tag's value
  • entity - either undefined or a hash with the following details:
    • alt - alternate text content
    • value - the value of the entity detected
    • type - 'unknown'|'email'|'ip'|etc.
  • plural - true|false
  • pos - part of speech tag,
  • value - text content for the tag,
  • verb - true|false

Keywords

FAQs

Package last updated on 13 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc