#VS2017 – Utilizando Microsoft.Recognizers para reconocer y resolver números, unidades y fecha / hora; en múltiples idiomas

Buenas!

Durante la sesión del Global Azure Bootcamp, uno de los temas que comente fue que estamos en un momento donde es muy simple agregar capacidades de lenguaje natural a nuestras aplicaciones. Por lo general, lo primero que solemos pensar es utilizar LUIS para esto, sin embargo, existen situaciones donde podemos ahorrarnos una llamada HTTP y realizar el análisis “en local”. Para esto existe Microsoft.Recognizers

Como lo mejor es dejar que el código se explique por si mismo, he aquí una porción de código directamente desde el repositorio de Github que explica algunos de los escenarios cubiertos para reconocer números, unidades de medida, fechas, etc. (ver referencias)

using Microsoft.Recognizers.Text;
using Microsoft.Recognizers.Text.DateTime;
using Microsoft.Recognizers.Text.Number;
using Microsoft.Recognizers.Text.NumberWithUnit;
using Microsoft.Recognizers.Text.Sequence;
// Use English for the Recognizers culture
var culture = Culture.English;
// Number recognizer will find any number from the input
// E.g "I have two apples" will return "2".
NumberRecognizer.RecognizeNumber(query, culture);
// Ordinal number recognizer will find any ordinal number
// E.g "eleventh" will return "11".
NumberRecognizer.RecognizeOrdinal(query, culture);
// Percentage recognizer will find any number presented as percentage
// E.g "one hundred percents" will return "100%"
NumberRecognizer.RecognizePercentage(query, culture);
// Number Range recognizer will find any cardinal or ordinal number range
// E.g. "between 2 and 5" will return "(2,5)"
NumberRecognizer.RecognizeNumberRange(query, culture);
// Age recognizer will find any age number presented
// E.g "After ninety five years of age, perspectives change" will return "95 Year"
NumberWithUnitRecognizer.RecognizeAge(query, culture);
// Currency recognizer will find any currency presented
// E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar"
NumberWithUnitRecognizer.RecognizeCurrency(query, culture);
// Dimension 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"
NumberWithUnitRecognizer.RecognizeDimension(query, culture);
// Temperature recognizer will find any temperature presented
// E.g "Set the temperature to 30 degrees celsius" will return "30 C"
NumberWithUnitRecognizer.RecognizeTemperature(query, culture);
// Datetime recognizer This model will find any Date even if its write in coloquial language
// E.g "I'll go back 8pm today" will return "2017-10-04 20:00:00"
DateTimeRecognizer.RecognizeDateTime(query, culture);
// PhoneNumber recognizer will find any phone number presented
// E.g "My phone number is ( 19 ) 38294427."
SequenceRecognizer.RecognizePhoneNumber(query, culture);
//IP recognizer will find any Ipv4/Ipv6 presented
// E.g "My Ip is 8.8.8.8"
SequenceRecognizer.RecognizeIpAddress(query, culture);
//Boolean recognizer will find yes/no like responses, including emoji –
// E.g "yup, I need that" will return "True"
ChoiceRecognizer.RecognizeBoolean(query, culture);

view raw
MsRecognizers.cs
hosted with ❤ by GitHub

Es muy interesante a la par que útil, y al día de la fecha soporta los lenguajes Chino, Inglés, Francés, Español y Portugués.

Saludos @ Toronto

El Bruno

References

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.