diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbQuantityExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbQuantityExpr.java index 597a2dc98..237c7152c 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbQuantityExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbQuantityExpr.java @@ -66,6 +66,7 @@ public class WbQuantityExpr implements WbExpression { BigDecimal parsedAmount = null; try { parsedAmount = new BigDecimal(amount.getString()); + parsedAmount = new BigDecimal(parsedAmount.toPlainString()); } catch (NumberFormatException e) { throw new SkipSchemaExpressionException(); } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommandTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommandTest.java index f042f2c48..d1026a28c 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommandTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommandTest.java @@ -59,7 +59,7 @@ public class PreviewWikibaseSchemaCommandTest extends SchemaCommandTest { JSONObject response = ParsingUtilities.evaluateJsonStringToObject(writer.toString()); JSONArray edits = response.getJSONArray("edits_preview"); - assertEquals(4, edits.length()); + assertEquals(3, edits.length()); } } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java index 43fde338b..5515c5d8f 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java @@ -23,6 +23,8 @@ ******************************************************************************/ package org.openrefine.wikidata.schema; +import static org.junit.Assert.assertEquals; + import java.math.BigDecimal; import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; @@ -30,6 +32,9 @@ import org.testng.annotations.Test; import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + public class WbQuantityExprTest extends WbExpressionTest { private WbQuantityExpr exprWithUnit = new WbQuantityExpr(new WbStringVariable("column A"), @@ -43,6 +48,7 @@ public class WbQuantityExprTest extends WbExpressionTest { evaluatesTo(Datamodel.makeQuantityValue(new BigDecimal("4.00"), null, null, "1"), exprWithoutUnit); } + @Test public void testInvalidAmountWithoutUnit() { setRow("hello"); isSkipped(exprWithoutUnit); @@ -57,16 +63,26 @@ public class WbQuantityExprTest extends WbExpressionTest { exprWithUnit); } + @Test public void testInvalidAmountWithUnit() throws SkipSchemaExpressionException { setRow("invalid", recon("Q42")); isSkipped(exprWithUnit); } + @Test public void testInvalidUnitWithAmount() throws SkipSchemaExpressionException { setRow("56.094", "not reconciled"); isSkipped(exprWithUnit); } + + // for issue #341: https://github.com/Wikidata/Wikidata-Toolkit/issues/341 + @Test + public void testExponent() throws SkipSchemaExpressionException, JsonProcessingException { + setRow("38.4E+3", recon("Q42")); + QuantityValue val = exprWithUnit.evaluate(ctxt); + assertEquals("38400", val.getNumericValue().toString()); + } }