Fix rendering of integers in Wikidata extension. Closes #1775
This commit is contained in:
parent
3fb282852d
commit
e1014bfeed
@ -58,7 +58,11 @@ public class WbStringVariable extends WbVariableExpr<StringValue> {
|
||||
public StringValue fromCell(Cell cell, ExpressionContext ctxt)
|
||||
throws SkipSchemaExpressionException {
|
||||
if (!cell.value.toString().isEmpty()) {
|
||||
return Datamodel.makeStringValue(cell.value.toString());
|
||||
String stringValue = cell.value.toString();
|
||||
if (cell.value instanceof Double && ((Double)cell.value) % 1 == 0) {
|
||||
stringValue = Integer.toString(((Double)cell.value).intValue());
|
||||
}
|
||||
return Datamodel.makeStringValue(stringValue);
|
||||
}
|
||||
throw new SkipSchemaExpressionException();
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ import org.testng.annotations.Test;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
|
||||
|
||||
import com.google.refine.model.Cell;
|
||||
|
||||
public class WbStringVariableTest extends WbVariableTest<StringValue> {
|
||||
|
||||
@Override
|
||||
@ -53,6 +55,23 @@ public class WbStringVariableTest extends WbVariableTest<StringValue> {
|
||||
evaluatesTo(Datamodel.makeStringValue("dirty \t"), "dirty \t");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that integers are correctly converted to strings
|
||||
*/
|
||||
@Test
|
||||
public void testInteger() {
|
||||
evaluatesTo(Datamodel.makeStringValue("45"), new Cell(45,null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that floating point numbers with no decimal part are also converted
|
||||
*/
|
||||
@Test
|
||||
public void testDoubleInteger() {
|
||||
evaluatesTo(Datamodel.makeStringValue("45"), new Cell(45.0,null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLeadingWhitespace() {
|
||||
evaluatesTo(Datamodel.makeStringValue(" dirty"), " dirty");
|
||||
|
Loading…
Reference in New Issue
Block a user