Check for language code validity in WbLanguageVariable
This commit is contained in:
parent
75b1863c1c
commit
708ff44f2f
@ -1,6 +1,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.WikimediaLanguageCodes;
|
||||||
|
|
||||||
import com.google.refine.model.Cell;
|
import com.google.refine.model.Cell;
|
||||||
|
|
||||||
@ -13,8 +14,14 @@ public class WbLanguageVariable extends WbVariableExpr<String> {
|
|||||||
public String fromCell(Cell cell, ExpressionContext ctxt)
|
public String fromCell(Cell cell, ExpressionContext ctxt)
|
||||||
throws SkipSchemaExpressionException {
|
throws SkipSchemaExpressionException {
|
||||||
if (cell.value != null && !cell.value.toString().isEmpty()) {
|
if (cell.value != null && !cell.value.toString().isEmpty()) {
|
||||||
// TODO some validation here?
|
String code = cell.value.toString().trim();
|
||||||
|
try {
|
||||||
|
// this just checks that the language code is known
|
||||||
|
WikimediaLanguageCodes.getLanguageCode(code);
|
||||||
return cell.value.toString();
|
return cell.value.toString();
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new SkipSchemaExpressionException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
|
|
||||||
public class WbLocationConstant implements WbExpression<GlobeCoordinatesValue> {
|
public class WbLocationConstant implements WbExpression<GlobeCoordinatesValue> {
|
||||||
|
|
||||||
|
public static final double defaultPrecision = GlobeCoordinatesValue.PREC_TEN_MICRO_DEGREE;
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
private GlobeCoordinatesValue parsed;
|
private GlobeCoordinatesValue parsed;
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ public class WbLocationConstant implements WbExpression<GlobeCoordinatesValue> {
|
|||||||
public static GlobeCoordinatesValue parse(String expr) throws ParseException {
|
public static GlobeCoordinatesValue parse(String expr) throws ParseException {
|
||||||
double lat = 0;
|
double lat = 0;
|
||||||
double lng = 0;
|
double lng = 0;
|
||||||
double precision = GlobeCoordinatesValue.PREC_TEN_MICRO_DEGREE;
|
double precision = defaultPrecision;
|
||||||
String[] parts = expr.split("[,/]");
|
String[] parts = expr.split("[,/]");
|
||||||
if (parts.length >= 2 && parts.length <= 3) {
|
if (parts.length >= 2 && parts.length <= 3) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user