Skip to content

Commit

Permalink
Merge pull request #71 from microsoft/master
Browse files Browse the repository at this point in the history
Fetch Upstream fork
  • Loading branch information
samhickey25 authored Apr 19, 2023
2 parents b03280c + 47ace20 commit 17de6bb
Show file tree
Hide file tree
Showing 513 changed files with 6,306 additions and 6,637 deletions.
2 changes: 1 addition & 1 deletion .NET/Build.CI.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ IF %ERRORLEVEL% NEQ 0 (

ECHO.
ECHO # Restoring NuGet dependencies
CALL "buildtools\nuget" restore
CALL !MSBuild! Microsoft.Recognizers.Text.sln /t:Restore

set configuration=Release
ECHO.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public static class NumbersDefinitions
public static readonly Dictionary<string, string> AmbiguityFiltersDict = new Dictionary<string, string>
{
{ @"十", @"十足" },
{ @"伍", @"队伍" },
{ @"伍", @"队伍|入伍|退伍|伍仁" },
{ @"肆", @"放肆|肆意|肆无忌惮" },
{ @"陆", @"大陆|陆地|登陆|海陆" },
{ @"拾", @"拾取|拾起|收拾|拾到|朝花夕拾" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static class DateTimeDefinitions
public const string LunchRegex = @"\blunchtime\b";
public const string NightRegex = @"\b(mid)?night\b";
public const string CommonDatePrefixRegex = @"^[\.]";
public static readonly string LessThanOneHour = $@"(?<lth>(a\s+)?quarter|three quarter(s)?|half( an hour)?|{BaseDateTime.DeltaMinuteRegex}(\s+(minutes?|mins?))|{DeltaMinuteNumRegex}(\s+(minutes?|mins?)))";
public static readonly string LessThanOneHour = $@"(?<lth>(a\s+)?quarter|three quarter(s)?|half( an hour)?|{BaseDateTime.DeltaMinuteRegex}(\s+(minutes?|mins?)|(?=\s+past))|{DeltaMinuteNumRegex}(\s+(minutes?|mins?)|(?=\s+past)))";
public static readonly string WrittenTimeRegex = $@"(?<writtentime>{HourNumRegex}\s+{MinuteNumRegex}(\s+(minutes?|mins?))?)";
public static readonly string TimePrefix = $@"(?<prefix>{LessThanOneHour}\s+(past|to))";
public static readonly string TimeSuffix = $@"(?<suffix>{AmRegex}|{PmRegex}|{OclockRegex})";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public static class DateTimeDefinitions
public const string AmRegex = @"\b(?<am>((((la|alla|verso|per|della|di|in)\s+(la\s+)?)?(mattinata|mattina))|(((il|al|verso|per|del|di)\s+(il\s+)?)?(mattino))))\b";
public const string LunchRegex = @"\b(ora di pranzo)\b";
public const string NightRegex = @"\b(mezzanotte|notte)\b";
public static readonly string LessThanOneHour = $@"(?<lth>(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}(\s+(minut[oi]|min))?|{DeltaMinuteNumRegex}(\s+(minut[oi]|min))|(?<=(e|meno)\s+){DeltaMinuteNumRegex}))";
public static readonly string LessThanOneHour = $@"(?<lth>(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex}))";
public static readonly string EngTimeRegex = $@"(?<engtime>{HourNumRegex}\s+e\s+({MinuteNumRegex}|(?<tens>venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex}))";
public static readonly string TimePrefix = $@"(?<prefix>(e\s+{LessThanOneHour}|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']|meno {LessThanOneHour}))";
public static readonly string TimePrefix = $@"(?<prefix>((e|meno)\s+{LessThanOneHour}(\s+(minut[oi]|min))?|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']))";
public static readonly string TimeSuffix = $@"(?<suffix>{AmRegex}|{PmRegex}|{OclockRegex})";
public static readonly string BasicTime = $@"\b(?<basictime>{EngTimeRegex}|{HourNumRegex}|{BaseDateTime.HourRegex}:{BaseDateTime.MinuteRegex}(:{BaseDateTime.SecondRegex})?|{BaseDateTime.HourRegex})";
public const string MidnightRegex = @"(?<midnight>mezzanotte|mezza notte)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static class DateTimeDefinitions
public static readonly string DateExtractor6 = $@"(?<=\b(en|el)\s+){MonthNumRegex}[\-\.]{DayRegex}{BaseDateTime.CheckDecimalRegex}\b(?!\s*[/\\\.]\s*\d+)";
public static readonly string DateExtractor7 = $@"\b(?<!\d[.,]){MonthNumRegex}\s*/\s*{DayRegex}((\s+|\s*,\s*|\s+d[eo]\s+){DateYearRegex})?\b{BaseDateTime.CheckDecimalRegex}(?!\s*[/\\\.]\s*\d+)";
public static readonly string DateExtractor8 = $@"(?<=\b(en|el)\s+){DayRegex}[\\\-]{MonthNumRegex}{BaseDateTime.CheckDecimalRegex}\b(?!\s*[/\\\.]\s*\d+)";
public static readonly string DateExtractor9 = $@"\b({WeekDayRegex}\s+)?(?<!\d[.,]){DayRegex}\s*/\s*{MonthNumRegex}((\s+|\s*,\s*|\s+d[eo]\s+){DateYearRegex})?\b{BaseDateTime.CheckDecimalRegex}(?!\s*[/\\\.]\s*\d+)";
public static readonly string DateExtractor9 = $@"\b({WeekDayRegex}\s+)?(?<!\d[.,]){DayRegex}\s*(/|\bdel\b)\s*{MonthNumRegex}((\s+|\s*,\s*|\s+d[eo]\s+){DateYearRegex})?\b{BaseDateTime.CheckDecimalRegex}(?!\s*[/\\\.]\s*\d+)";
public static readonly string DateExtractor10 = $@"\b(?<!\d[.,])(({YearRegex}\s*[/\\\-\.]\s*({MonthNumRegex}|{MonthRegex})\s*[/\\\-\.]\s*{DayRegex}(?!\s*[/\\\-\.]\s*\d+))|({MonthRegex}\s*[/\\\-\.]\s*{BaseDateTime.FourDigitYearRegex}\s*[/\\\-\.]\s*{DayRegex})|({DayRegex}\s*[/\\\-\.]\s*{BaseDateTime.FourDigitYearRegex}\s*[/\\\-\.]\s*{MonthRegex}))";
public const string HourRegex = @"\b(?<!\d[,.])(?<hour>2[0-4]|[0-1]?\d)";
public const string HourNumRegex = @"\b(?<hournum>cero|una|dos|tres|cuatro|cinco|seis|siete|ocho|nueve|diez|once|doce)\b";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net462;net6.0</TargetFrameworks>
<LangVersion>9</LangVersion>
<!-- Disable GenerateAssemblyInfo to use the existing AssemblyInfo.cs -->
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.RegularExpressions;

using Microsoft.Recognizers.Definitions.Arabic;
using Microsoft.Recognizers.Text.Choice.Extractors;

namespace Microsoft.Recognizers.Text.Choice.Arabic
{
public class ArabicBooleanExtractorConfiguration : IBooleanExtractorConfiguration
public class ArabicBooleanExtractorConfiguration : BaseBooleanExtractorConfiguration
{
public static readonly Regex TrueRegex =
new Regex(ChoiceDefinitions.TrueRegex, RegexOptions.Singleline | RegexOptions.RightToLeft);

public static readonly Regex FalseRegex =
new Regex(ChoiceDefinitions.FalseRegex, RegexOptions.Singleline | RegexOptions.RightToLeft);

public static readonly Regex TokenRegex =
new Regex(ChoiceDefinitions.TokenizerRegex, RegexOptions.Singleline | RegexOptions.RightToLeft);

public static readonly IDictionary<Regex, string> MapRegexes = new Dictionary<Regex, string>()
{
{ TrueRegex, Constants.SYS_BOOLEAN_TRUE },
{ FalseRegex, Constants.SYS_BOOLEAN_FALSE },
};

public ArabicBooleanExtractorConfiguration(bool onlyTopMatch = true)
: base(
trueRegex: ChoiceDefinitions.TrueRegex,
falseRegex: ChoiceDefinitions.FalseRegex,
tokenRegex: ChoiceDefinitions.TokenizerRegex,
options: RegexOptions.Singleline | RegexOptions.RightToLeft,
allowPartialMatch: false,
maxDistance: 2,
onlyTopMatch)
{
this.OnlyTopMatch = onlyTopMatch;
}

Regex IBooleanExtractorConfiguration.TrueRegex => TrueRegex;

Regex IBooleanExtractorConfiguration.FalseRegex => FalseRegex;

IDictionary<Regex, string> IChoiceExtractorConfiguration.MapRegexes => MapRegexes;

Regex IChoiceExtractorConfiguration.TokenRegex => TokenRegex;

public bool AllowPartialMatch => false;

public int MaxDistance => 2;

public bool OnlyTopMatch { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.RegularExpressions;

using Microsoft.Recognizers.Definitions.Bulgarian;
using Microsoft.Recognizers.Text.Choice.Extractors;

namespace Microsoft.Recognizers.Text.Choice.Bulgarian
{
public class BulgarianBooleanExtractorConfiguration : IBooleanExtractorConfiguration
public class BulgarianBooleanExtractorConfiguration : BaseBooleanExtractorConfiguration
{
public static readonly Regex TrueRegex =
new Regex(ChoiceDefinitions.TrueRegex, RegexOptions.Singleline);

public static readonly Regex FalseRegex =
new Regex(ChoiceDefinitions.FalseRegex, RegexOptions.Singleline);

public static readonly Regex TokenRegex =
new Regex(ChoiceDefinitions.TokenizerRegex, RegexOptions.Singleline);

public static readonly IDictionary<Regex, string> MapRegexes = new Dictionary<Regex, string>()
{
{ TrueRegex, Constants.SYS_BOOLEAN_TRUE },
{ FalseRegex, Constants.SYS_BOOLEAN_FALSE },
};

public BulgarianBooleanExtractorConfiguration(bool onlyTopMatch = true)
: base(
trueRegex: ChoiceDefinitions.TrueRegex,
falseRegex: ChoiceDefinitions.FalseRegex,
tokenRegex: ChoiceDefinitions.TokenizerRegex,
options: RegexOptions.Singleline,
allowPartialMatch: false,
maxDistance: 2,
onlyTopMatch)
{
this.OnlyTopMatch = onlyTopMatch;
}

Regex IBooleanExtractorConfiguration.TrueRegex => TrueRegex;

Regex IBooleanExtractorConfiguration.FalseRegex => FalseRegex;

IDictionary<Regex, string> IChoiceExtractorConfiguration.MapRegexes => MapRegexes;

Regex IChoiceExtractorConfiguration.TokenRegex => TokenRegex;

public bool AllowPartialMatch => false;

public int MaxDistance => 2;

public bool OnlyTopMatch { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.RegularExpressions;

using Microsoft.Recognizers.Definitions.Chinese;
using Microsoft.Recognizers.Text.Choice.Extractors;

namespace Microsoft.Recognizers.Text.Choice.Chinese
{
public class ChineseBooleanExtractorConfiguration : IBooleanExtractorConfiguration
public class ChineseBooleanExtractorConfiguration : BaseBooleanExtractorConfiguration
{
public static readonly Regex TrueRegex =
new Regex(ChoiceDefinitions.TrueRegex, RegexOptions.Singleline);

public static readonly Regex FalseRegex =
new Regex(ChoiceDefinitions.FalseRegex, RegexOptions.Singleline);

public static readonly Regex TokenRegex =
new Regex(ChoiceDefinitions.TokenizerRegex, RegexOptions.Singleline);

public static readonly IDictionary<Regex, string> MapRegexes = new Dictionary<Regex, string>()
{
{ TrueRegex, Constants.SYS_BOOLEAN_TRUE },
{ FalseRegex, Constants.SYS_BOOLEAN_FALSE },
};

public ChineseBooleanExtractorConfiguration(bool onlyTopMatch = true)
: base(
trueRegex: ChoiceDefinitions.TrueRegex,
falseRegex: ChoiceDefinitions.FalseRegex,
tokenRegex: ChoiceDefinitions.TokenizerRegex,
options: RegexOptions.Singleline,
allowPartialMatch: false,
maxDistance: 2,
onlyTopMatch)
{
this.OnlyTopMatch = onlyTopMatch;
}

Regex IBooleanExtractorConfiguration.TrueRegex => TrueRegex;

Regex IBooleanExtractorConfiguration.FalseRegex => FalseRegex;

IDictionary<Regex, string> IChoiceExtractorConfiguration.MapRegexes => MapRegexes;

Regex IChoiceExtractorConfiguration.TokenRegex => TokenRegex;

public bool AllowPartialMatch => false;

public int MaxDistance => 2;

public bool OnlyTopMatch { get; }
}
}
26 changes: 18 additions & 8 deletions .NET/Microsoft.Recognizers.Text.Choice/ChoiceRecognizer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Microsoft.Recognizers.Text.Choice.Arabic;
using Microsoft.Recognizers.Text.Choice.Bulgarian;
using Microsoft.Recognizers.Text.Choice.Chinese;
using Microsoft.Recognizers.Text.Choice.Dutch;
using Microsoft.Recognizers.Text.Choice.English;
using Microsoft.Recognizers.Text.Choice.Extractors;
using Microsoft.Recognizers.Text.Choice.French;
using Microsoft.Recognizers.Text.Choice.German;
using Microsoft.Recognizers.Text.Choice.Hindi;
Expand All @@ -21,23 +23,23 @@ namespace Microsoft.Recognizers.Text.Choice
{
public class ChoiceRecognizer : Recognizer<ChoiceOptions>
{
public ChoiceRecognizer(string targetCulture, ChoiceOptions options = ChoiceOptions.None, bool lazyInitialization = false)
: base(targetCulture, options, lazyInitialization)
public ChoiceRecognizer(string targetCulture, ChoiceOptions options = ChoiceOptions.None, bool lazyInitialization = false, int timeoutInSeconds = 0)
: base(targetCulture, options, lazyInitialization, timeoutInSeconds)
{
}

public ChoiceRecognizer(string targetCulture, int options, bool lazyInitialization = false)
: this(targetCulture, GetOptions(options), lazyInitialization)
public ChoiceRecognizer(string targetCulture, int options, bool lazyInitialization = false, int timeoutInSeconds = 0)
: this(targetCulture, GetOptions(options), lazyInitialization, timeoutInSeconds)
{
}

public ChoiceRecognizer(ChoiceOptions options = ChoiceOptions.None, bool lazyInitialization = true)
: base(null, options, lazyInitialization)
public ChoiceRecognizer(ChoiceOptions options = ChoiceOptions.None, bool lazyInitialization = true, int timeoutInSeconds = 0)
: base(null, options, lazyInitialization, timeoutInSeconds)
{
}

public ChoiceRecognizer(int options, bool lazyInitialization = true)
: this(null, GetOptions(options), lazyInitialization)
public ChoiceRecognizer(int options, bool lazyInitialization = true, int timeoutInSeconds = 0)
: this(null, GetOptions(options), lazyInitialization, timeoutInSeconds)
{
}

Expand All @@ -53,6 +55,14 @@ public IModel GetBooleanModel(string culture = null, bool fallbackToDefaultCultu
return GetModel<BooleanModel>(culture, fallbackToDefaultCulture);
}

protected override List<Type> GetRelatedTypes()
{
return new List<Type>()
{
typeof(BaseBooleanExtractorConfiguration),
};
}

protected override void InitializeConfiguration()
{
RegisterModel<BooleanModel>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.RegularExpressions;

using Microsoft.Recognizers.Definitions.Dutch;
using Microsoft.Recognizers.Text.Choice.Extractors;

namespace Microsoft.Recognizers.Text.Choice.Dutch
{
public class DutchBooleanExtractorConfiguration : IBooleanExtractorConfiguration
public class DutchBooleanExtractorConfiguration : BaseBooleanExtractorConfiguration
{
public static readonly Regex TrueRegex =
new Regex(ChoiceDefinitions.TrueRegex, RegexOptions.Singleline);

public static readonly Regex FalseRegex =
new Regex(ChoiceDefinitions.FalseRegex, RegexOptions.Singleline);

public static readonly Regex TokenRegex =
new Regex(ChoiceDefinitions.TokenizerRegex, RegexOptions.Singleline);

public static readonly IDictionary<Regex, string> MapRegexes = new Dictionary<Regex, string>()
{
{ TrueRegex, Constants.SYS_BOOLEAN_TRUE },
{ FalseRegex, Constants.SYS_BOOLEAN_FALSE },
};

public DutchBooleanExtractorConfiguration(bool onlyTopMatch = true)
: base(
trueRegex: ChoiceDefinitions.TrueRegex,
falseRegex: ChoiceDefinitions.FalseRegex,
tokenRegex: ChoiceDefinitions.TokenizerRegex,
options: RegexOptions.Singleline,
allowPartialMatch: false,
maxDistance: 2,
onlyTopMatch)
{
this.OnlyTopMatch = onlyTopMatch;
}

Regex IBooleanExtractorConfiguration.TrueRegex => TrueRegex;

Regex IBooleanExtractorConfiguration.FalseRegex => FalseRegex;

IDictionary<Regex, string> IChoiceExtractorConfiguration.MapRegexes => MapRegexes;

Regex IChoiceExtractorConfiguration.TokenRegex => TokenRegex;

public bool AllowPartialMatch => false;

public int MaxDistance => 2;

public bool OnlyTopMatch { get; }
}
}
Loading

0 comments on commit 17de6bb

Please sign in to comment.