92 lines
3.0 KiB
C#
92 lines
3.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using Microsoft.Recognizers.Text;
|
|||
|
using Microsoft.Recognizers.Text.DateTime;
|
|||
|
using Microsoft.Recognizers.Text.Number;
|
|||
|
using Microsoft.Recognizers.Text.NumberWithUnit;
|
|||
|
using Microsoft.Recognizers.Text.Sequence;
|
|||
|
using Newtonsoft.Json;
|
|||
|
|
|||
|
namespace TextRecogniserDemo
|
|||
|
{
|
|||
|
enum AIMode {
|
|||
|
DateTime, Number, NumberRange,
|
|||
|
Age, Currency, Dimension,
|
|||
|
Temperature, PhoneNumber, IPAddress,
|
|||
|
URL, Mention, Hashtag
|
|||
|
}
|
|||
|
|
|||
|
class MainClass
|
|||
|
{
|
|||
|
public static void Main(string[] args)
|
|||
|
{
|
|||
|
Console.Error.WriteLine("Microsoft.Recognizers.Text Demo");
|
|||
|
Console.Error.WriteLine(" By Starbeammrainbowlabs");
|
|||
|
Console.Error.Write("Modes available: ");
|
|||
|
List<string> modes = new List<string>();
|
|||
|
foreach (AIMode next in Enum.GetValues(typeof(AIMode)))
|
|||
|
modes.Add(next.ToString());
|
|||
|
Console.Error.WriteLine(string.Join(", ", modes));
|
|||
|
|
|||
|
while (true) {
|
|||
|
Console.Error.Write("\u001b[1m\u001b[33mMode:\u001b[0m ");
|
|||
|
string modeText = Console.ReadLine();
|
|||
|
if (modeText == null) break;
|
|||
|
AIMode nextMode = (AIMode)Enum.Parse(typeof(AIMode), Regex.Replace(modeText, @"[^a-zA-Z]", ""), true);
|
|||
|
|
|||
|
|
|||
|
Console.Error.Write("\u001b[1m\u001b[32m>\u001b[0m ");
|
|||
|
string nextLine = Console.ReadLine();
|
|||
|
if (nextLine == null) break;
|
|||
|
|
|||
|
|
|||
|
List<ModelResult> result = null;
|
|||
|
switch (nextMode) {
|
|||
|
case AIMode.DateTime:
|
|||
|
result = DateTimeRecognizer.RecognizeDateTime(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Number:
|
|||
|
result = NumberRecognizer.RecognizeNumber(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Age:
|
|||
|
result = NumberWithUnitRecognizer.RecognizeAge(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Currency:
|
|||
|
result = NumberWithUnitRecognizer.RecognizeCurrency(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Dimension:
|
|||
|
result = NumberWithUnitRecognizer.RecognizeDimension(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Temperature:
|
|||
|
result = NumberWithUnitRecognizer.RecognizeTemperature(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.PhoneNumber:
|
|||
|
result = SequenceRecognizer.RecognizePhoneNumber(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.IPAddress:
|
|||
|
result = SequenceRecognizer.RecognizeIpAddress(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.URL:
|
|||
|
result = SequenceRecognizer.RecognizeURL(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Mention:
|
|||
|
result = SequenceRecognizer.RecognizeMention(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
case AIMode.Hashtag:
|
|||
|
result = SequenceRecognizer.RecognizeHashtag(nextLine, Culture.English);
|
|||
|
break;
|
|||
|
default:
|
|||
|
Console.Error.WriteLine($"Error: Unrecognised mode {nextMode}.");
|
|||
|
continue;
|
|||
|
}
|
|||
|
Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
|
|||
|
|
|||
|
Console.Error.WriteLine("\u001b[34m" + new string('-', Console.WindowWidth - 1) + "\u001b[0m");
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|