Add workaround for issue in QuantityValue serialization.

https://github.com/Wikidata/Wikidata-Toolkit/issues/341
This commit is contained in:
Antonin Delpeuch 2018-03-20 16:52:36 +00:00
parent 81a18777cb
commit ec6d0eec64
3 changed files with 18 additions and 1 deletions

View File

@ -66,6 +66,7 @@ public class WbQuantityExpr implements WbExpression<QuantityValue> {
BigDecimal parsedAmount = null;
try {
parsedAmount = new BigDecimal(amount.getString());
parsedAmount = new BigDecimal(parsedAmount.toPlainString());
} catch (NumberFormatException e) {
throw new SkipSchemaExpressionException();
}

View File

@ -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());
}
}

View File

@ -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<QuantityValue> {
private WbQuantityExpr exprWithUnit = new WbQuantityExpr(new WbStringVariable("column A"),
@ -43,6 +48,7 @@ public class WbQuantityExprTest extends WbExpressionTest<QuantityValue> {
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<QuantityValue> {
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());
}
}