From 40367241768ead1bd56b88b0cccd91dc0c3fe6a1 Mon Sep 17 00:00:00 2001 From: Martin Battaglino Date: Mon, 1 Feb 2021 17:01:57 -0300 Subject: [PATCH 1/4] Decrease end value following C# and TS --- .../recognizers/text/number/models/AbstractNumberModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java b/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java index 95101a3496..2800810056 100644 --- a/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java +++ b/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java @@ -54,7 +54,7 @@ public List parse(String query) { return new ModelResult( o.getText(), o.getStart(), - o.getStart() + o.getLength(), + o.getStart() + o.getLength() - 1, getModelTypeName(), sortedMap ); From fa196377dfc88407e23331012360900619048f19 Mon Sep 17 00:00:00 2001 From: Martin Battaglino Date: Wed, 3 Feb 2021 11:47:12 -0300 Subject: [PATCH 2/4] Add code comment before return --- .../recognizers/text/number/models/AbstractNumberModel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java b/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java index 2800810056..7bd67756ff 100644 --- a/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java +++ b/Java/libraries/recognizers-text-number/src/main/java/com/microsoft/recognizers/text/number/models/AbstractNumberModel.java @@ -51,6 +51,7 @@ public List parse(String query) { SortedMap sortedMap = new TreeMap(); sortedMap.put(ResolutionKey.Value, o.getResolutionStr()); + // We decreased the end property by 1 in order to keep parity with other platforms (C#/JS). return new ModelResult( o.getText(), o.getStart(), From a410019c3d34d29ab209173489a981c4a8429177 Mon Sep 17 00:00:00 2001 From: Martin Battaglino Date: Wed, 3 Feb 2021 12:57:38 -0300 Subject: [PATCH 3/4] Separate logic to be tested correctly in NumberTest --- .../text/tests/number/NumberTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java b/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java index 4b4109d164..ac1423d8b2 100644 --- a/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java +++ b/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java @@ -1,5 +1,6 @@ package com.microsoft.recognizers.text.tests.number; +import com.microsoft.recognizers.text.ExtendedModelResult; import com.microsoft.recognizers.text.ModelResult; import com.microsoft.recognizers.text.number.NumberOptions; import com.microsoft.recognizers.text.number.NumberRecognizer; @@ -7,11 +8,14 @@ import com.microsoft.recognizers.text.tests.DependencyConstants; import com.microsoft.recognizers.text.tests.NotSupportedException; import com.microsoft.recognizers.text.tests.TestCase; +import org.javatuples.Pair; +import org.junit.Assert; import org.junit.AssumptionViolatedException; import org.junit.runners.Parameterized; import java.util.Collection; import java.util.List; +import java.util.stream.IntStream; public class NumberTest extends AbstractTest { @@ -25,6 +29,36 @@ public NumberTest(TestCase currentCase) { super(currentCase); } + @Override + protected void recognizeAndAssert(TestCase currentCase) { + + // parse + List results = recognize(currentCase); + + // assert + assertResultsNumber(currentCase, results); + } + + public static void assertResultsNumber(TestCase currentCase, List results) { + + List expectedResults = readExpectedResults(ExtendedModelResult.class, currentCase.results); + Assert.assertEquals(getMessage(currentCase, "\"Result Count\""), expectedResults.size(), results.size()); + + IntStream.range(0, expectedResults.size()) + .mapToObj(i -> Pair.with(expectedResults.get(i), results.get(i))) + .forEach(t -> { + ExtendedModelResult expected = t.getValue0(); + T actual = t.getValue1(); + + Assert.assertEquals(getMessage(currentCase, "typeName"), expected.typeName, actual.typeName); + Assert.assertEquals(getMessage(currentCase, "text"), expected.text, actual.text); + + // Number and NumberWithUnit are supported currently. + Assert.assertEquals(getMessage(currentCase, "start"), expected.start, actual.start); + Assert.assertEquals(getMessage(currentCase, "end"), expected.end, actual.end); + }); + } + @Override public List recognize(TestCase currentCase) { From 8f6a0da111345f8538d637e9acf452e7324d249c Mon Sep 17 00:00:00 2001 From: Martin Battaglino Date: Wed, 3 Feb 2021 13:25:52 -0300 Subject: [PATCH 4/4] Add validation for value --- .../recognizers/text/tests/number/NumberTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java b/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java index ac1423d8b2..c6bcc9856d 100644 --- a/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java +++ b/Java/tests/src/test/java/com/microsoft/recognizers/text/tests/number/NumberTest.java @@ -13,7 +13,9 @@ import org.junit.AssumptionViolatedException; import org.junit.runners.Parameterized; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.stream.IntStream; @@ -36,10 +38,10 @@ protected void recognizeAndAssert(TestCase currentCase) { List results = recognize(currentCase); // assert - assertResultsNumber(currentCase, results); + assertResultsNumber(currentCase, results, new ArrayList() {{ add("value");}}); } - public static void assertResultsNumber(TestCase currentCase, List results) { + public static void assertResultsNumber(TestCase currentCase, List results, List testResolutionKeys) { List expectedResults = readExpectedResults(ExtendedModelResult.class, currentCase.results); Assert.assertEquals(getMessage(currentCase, "\"Result Count\""), expectedResults.size(), results.size()); @@ -56,6 +58,10 @@ public static void assertResultsNumber(TestCase currentC // Number and NumberWithUnit are supported currently. Assert.assertEquals(getMessage(currentCase, "start"), expected.start, actual.start); Assert.assertEquals(getMessage(currentCase, "end"), expected.end, actual.end); + + for (String key : testResolutionKeys) { + Assert.assertEquals(getMessage(currentCase, key), expected.resolution.get(key), actual.resolution.get(key)); + } }); }