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

@microsoft/recognizers-text-suite

v1.3.1

Published

recognizers-text-suite provides robust recognition and resolution of numbers, units, date/time, and more; expressed in multiple languages.

Downloads

288,439

Readme

Microsoft.Recognizers.Text for JavaScript

Getting Started

Recognizers are organized into groups and designed to be used in C#, Node.js, Python and Java to help you build great applications! To use the samples, install the recognizers-text-suite package, or clone our GitHub repository using Git.

Cloning and building the Repository

git clone https://github.com/Microsoft/Recognizers-Text.git
cd Recognizers-Text

You can choose between build the solution manually or through an automatized build.cmd file.

Manual Build

Open a terminal and run the following commands:

cd JavaScript
npm install
npm run build
npm run test

Automatized Build

Launch Build.cmd file.

Installation from NPM

-- Note: the initial versions of the packages are available with the @preview tag. --

Install all the Recognizer's by launching the following command:

  • Get all the Recognizers in a single module: npm install @microsoft/recognizers-text-suite

Or, if you prefer to use a single type of recognizer:

  • Get only the numbers Recognizer's features: npm install @microsoft/recognizers-text-number

  • Get only the numbers with units Recognizer's features: npm install @microsoft/recognizers-text-number-with-unit

  • Get only the date and time Recognizer's features: npm install @microsoft/recognizers-text-date-time

  • Get only the sequence Recognizer's features: npm install @microsoft/recognizers-text-sequence

  • Get only the choice Recognizer's features: npm install @microsoft/recognizers-text-choice

API Documentation

Once the proper package is installed, you'll need to reference the package:

var Recognizers = require('@microsoft/recognizers-text-suite');
var NumberRecognizers = require('@microsoft/recognizers-text-number');
var NumberWithUnitRecognizers = require('@microsoft/recognizers-text-number-with-unit');
var DateTimeRecognizers = require('@microsoft/recognizers-text-date-time');
var SequenceRecognizers = require('@microsoft/recognizers-text-sequence');
var ChoiceRecognizers = require('@microsoft/recognizers-text-choice');

Recognizer's Models

This is the preferred way if you need to parse multiple inputs based on the same context (e.g.: language and options):

var recognizer = new NumberRecognizers.NumberRecognizer(Recognizers.Culture.English);
var model = recognizer.getNumberModel();
var result = model.parse('Twelve');

Or, for less verbosity, you use the helper methods:

var result = Recognizers.recognizeNumber("Twelve", Recognizers.Culture.English);

Internally, both methods will cache the instance models to avoid extra costs.

Microsoft.Recognizers.Text.Number

  • Numbers

    This recognizer will find any number from the input. E.g. "I have two apples" will return "2".

    Recognizers.recognizeNumber('I have two apples', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberRecognizers.NumberRecognizer(Recognizers.Culture.English).getNumberModel()

  • Ordinal Numbers

    This recognizer will find any ordinal number. E.g. "eleventh" will return "11".

    Recognizers.recognizeOrdinal('eleventh', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberRecognizers.NumberRecognizer(Recognizers.Culture.English).getOrdinalModel()

  • Percentages

    This recognizer will find any number presented as percentage. E.g. "one hundred percents" will return "100%".

    Recognizers.recognizePercentage('one hundred percents', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberRecognizers.NumberRecognizer(Recognizers.Culture.English).getPercentageModel()

Microsoft.Recognizers.Text.NumberWithUnit

  • Ages

    This recognizer will find any age number presented. E.g. "After ninety five years of age, perspectives change" will return "95 Year".

    Recognizers.recognizeAge('After ninety five years of age, perspectives change', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberWithUnitRecognizers.NumberWithUnitRecognizer(Recognizers.Culture.English).getAgeModel()

  • Currencies

    This recognizer will find any currency presented. E.g. "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar".

    Recognizers.recognizeCurrency('Interest expense in the 1988 third quarter was $ 75.3 million', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberWithUnitRecognizers.NumberWithUnitRecognizer(Recognizers.Culture.English).getCurrencyModel()

  • Dimensions

    This recognizer will find any dimension presented. E.g. "The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours." will return "6 Mile".

    Recognizers.recognizeDimension('The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours.', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberWithUnitRecognizers.NumberWithUnitRecognizer(Recognizers.Culture.English).getDimensionModel()

  • Temperatures

    This recognizer will find any temperature presented. E.g. "Set the temperature to 30 degrees celsius" will return "30 C".

    Recognizers.recognizeTemperature('Set the temperature to 30 degrees celsius', Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new NumberWithUnitRecognizers.NumberWithUnitRecognizer(Recognizers.Culture.English).getTemperatureModel()

Microsoft.Recognizers.Text.DateTime

  • DateTime

    This recognizer will find any date, time, duration and date/time ranges, even if its write in colloquial language. E.g. "I'll go back 8pm today" will return "2017-10-04 20:00:00".

    Recognizers.recognizeDateTime("I'll go back 8pm today", Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new DateTimeRecognizers.DateTimeRecognizer(Recognizers.Culture.English).getDateTimeModel()

Microsoft.Recognizers.Text.Sequence

  • Phone Numbers

    This model will find any patter of symbols detected as a phone number, even if its write in coloquial language. E.g. "My phone number is 1 (877) 609-2233." will return "1 (877) 609-2233".

    Recognizers.recognizePhoneNumber("My phone number is 1 (877) 609-2233.", Culture.English)

    Or you can obtain a model instance using:

    new SequenceRecognizers.SequenceRecognizer(Culture.English).GetPhoneNumberModel()

  • IP Address

    This model will find any Ipv4/Ipv6 presented. E.g. "My Ip is 8.8.8.8".

    Recognizers.recognizeIpAddress("My Ip is 8.8.8.8")

    Or you can obtain a model instance using:

    new SequenceRecognizers.SequenceRecognizer(Culture.English).IpAddressModel()

Microsoft.Recognizers.Text.Choice

  • Booleans

    This recognizer will find any boolean value, even if its write with emoji. E.g. "👌 It's ok" will return "true".

    Recognizers.recognizeBoolean("👌 It's ok", Recognizers.Culture.English)

    Or you can obtain a model instance using:

    new ChoiceRecognizers.ChoiceRecognizer(Recognizers.Culture.English).getBooleanModel()

Samples

Start using recognizers!

Integration tips

The recognizers were designed to disjoint language's logic from the recognizer's core in order to grow without the obligation of change the supported platforms.

To achieve this, the recognizers contains the following folders:

  • Specs - Contains all the necessary tests that should be run on any improvements to the recognizers. It's divided by recognizer and supported language.
  • Patterns - Contains all the regular expressions that fulfill the recognizers logic. It's divided by supported language.