npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nl3

v0.0.3

Published

nl3 - natural language triples

Downloads

33

Readme

nl3 - Natural Language Triples

nl3 is a natural language triple library, used for parsing triples from plain english. Currently nl3 is best at generating triples from simple short phrases that contain the Subject, Predicate and Object in order.

What is a triple?

A triple is a data structure that represents a Subject, Predicate and Object or S P O.

More Information

  • https://en.wikipedia.org/wiki/Triplestore
  • https://en.wikipedia.org/wiki/Resource_Description_Framework

TLDR;

var nl3 = require('nl3')({
/**
* Specifies valid triples in plain english ex: 'Subject Predicate Object'.
* All values will be singularized.
* @type {Array}
*/
  grammar: [
    'users message users'
  ],
/**
* Extend your vocabulary by mapping word stems to existing predicates.
* @type {Object}
*/
  vocabulary: {
    msg: 'message',     // user bob msgs user tom
    messag: 'message',  // user bob messaged user jill
    contact: 'message'  // user bob contacted user bill
  }
});

The client returned is able to parse these queries.

nl3.parse('user jack msg user jill');
nl3.parse('user jack msgs user jill');
nl3.parse('user jack messaged user jill');
nl3.parse('user jack contacted user jill');
nl3.parse('user jack contacts user jill');

All of which will have the same output.

{
  subject: {
    type: 'user',
    value: 'jack'
  },
  predicate: {
    value: 'message'
  },
  object: {
    type: 'user',
    value: 'jill'
  }
}

Installation

$ npm install nl3 --save

Development Scripts

Before running any development scripts, be sure to first install the dev modules.

$ npm install nl3 --save --dev

Build Documentation

Outputs code documentation files to the ./doc/api folder.

$ npm run doc

Static Analysis

Outputs static analysis files to the ./doc/analysis folder.

$ npm run analyze

Test + Coverage

Outputs code coverage files to the ./doc/coverage folder.

$ npm run test

CURRENT COVERAGE REPORT

codecov.io

API

nl3(options)

Create an nl3 instance.

parameters:

  • options {Object} The options for the nl3 client.
  • options.grammar {Array} An array of valid grammar in the format of 'S P O'.
  • options.vocabulary {Array} An object mapping the phonetic root of an object to a predicate.

returns: a new instance of the nl3 client.

Example

var nl3 = require('nl3')({
/**
* Specify valid triples in plain english ex: 'Subject Predicate Object'.
* The Subject, Predicate and Object will be will be singularized, if presented in any tense.
* @type {Array}
*/
  grammar: [
    'users message users'
  ],
/**
* Extend the vocabulary of your predicates by mapping word stems to existing predicates within your grammar.
* @type {Object}
*/
  vocabulary: {
    msg: 'message',     // user bob msgs user tom
    messag: 'message',  // user bob messaged user jill
    contact: 'message'  // user bob contacted user bill
  }
});

nl3.parse( text )

parameters:

  • text: {String} A string containing a S P O phrase in plain english. returns: A triple containing the results of of the parsed Subject Predicate and Object.

Example


var nl3 = require('nl3')({
  grammar: [
    'users message users'
  ],
  vocabulary: {
    contact: 'message', // user bob contacted user bill
  }
});

function print (description, triple) {
  console.log(
    description + ' =', JSON.stringify(triple, null, '  ');
  );
};

print( 'user jack contacts user jill', nl3.parse('user jack contacts user jill') );

print( 'users who message user jill', nl3.parse('users who message user jill') );

returns:


user jack contacts user jill = {
  "subject": {
    "type": "user",
    "value": "jack"

  },
  "predicate": {
    "value": "message"
  },
  "object": {
    "type": "user",
    "value": "jill"
  }
}
users who message user jill = {
  "subject": {
    "type": "user"
  },
  "predicate": {
    "value": "message"
  },
  "object": {
    "type": "user",
    "value": "jill"
  }
}

vNext

Support for natural random order queries, these are not in (SPO) order, such as messages that user bob created (OSP), created messages by user jill (POS), created by user jill messages (PSO), (SO) user jills messages, (OS) messages for user jill.


  nl3.parse('messages from user 42');
  nl3.parse('messages by user 32');

The Backlog

  • Support for misspelled subjects & objects ( nearest neighbor )

Discuss

Chat channel:

Questions or comments can also be posted on the nl3 Github issues page.

Maintainers

Hector Gray (Twitter: @defstream)

Contribute

Pull Requests welcome. Please make sure all tests pass:

$ npm test

Please submit Github issues for any feature enhancements, bugs or documentation problems.

License

MIT