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..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,10 +51,11 @@ 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(), - o.getStart() + o.getLength(), + o.getStart() + o.getLength() - 1, getModelTypeName(), sortedMap ); 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..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 @@ -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,16 @@ 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.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.stream.IntStream; public class NumberTest extends AbstractTest { @@ -25,6 +31,40 @@ public NumberTest(TestCase currentCase) { super(currentCase); } + @Override + protected void recognizeAndAssert(TestCase currentCase) { + + // parse + List results = recognize(currentCase); + + // assert + assertResultsNumber(currentCase, results, new ArrayList() {{ add("value");}}); + } + + 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()); + + 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); + + for (String key : testResolutionKeys) { + Assert.assertEquals(getMessage(currentCase, key), expected.resolution.get(key), actual.resolution.get(key)); + } + }); + } + @Override public List recognize(TestCase currentCase) {