Check for language code validity in WbLanguageVariable

This commit is contained in:
Antonin Delpeuch 2018-02-01 09:03:12 +00:00
parent 75b1863c1c
commit 708ff44f2f
2 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.WikimediaLanguageCodes;
import com.google.refine.model.Cell;
@ -13,8 +14,14 @@ public class WbLanguageVariable extends WbVariableExpr<String> {
public String fromCell(Cell cell, ExpressionContext ctxt)
throws SkipSchemaExpressionException {
if (cell.value != null && !cell.value.toString().isEmpty()) {
// TODO some validation here?
return cell.value.toString();
String code = cell.value.toString().trim();
try {
// this just checks that the language code is known
WikimediaLanguageCodes.getLanguageCode(code);
return cell.value.toString();
} catch(IllegalArgumentException e) {
;
}
}
throw new SkipSchemaExpressionException();
}

View File

@ -12,6 +12,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class WbLocationConstant implements WbExpression<GlobeCoordinatesValue> {
public static final double defaultPrecision = GlobeCoordinatesValue.PREC_TEN_MICRO_DEGREE;
private String value;
private GlobeCoordinatesValue parsed;
@ -29,7 +31,7 @@ public class WbLocationConstant implements WbExpression<GlobeCoordinatesValue> {
public static GlobeCoordinatesValue parse(String expr) throws ParseException {
double lat = 0;
double lng = 0;
double precision = GlobeCoordinatesValue.PREC_TEN_MICRO_DEGREE;
double precision = defaultPrecision;
String[] parts = expr.split("[,/]");
if (parts.length >= 2 && parts.length <= 3) {
try {