Add warning for monolingual exprs without language
This commit is contained in:
parent
69bfad6a47
commit
93883fd777
@ -112,6 +112,10 @@
|
||||
"ignored-references": {
|
||||
"title": "Some references were ignored.",
|
||||
"body": "None of their statements could be parsed, so no reference was added."
|
||||
},
|
||||
"monolingual-text-without-language": {
|
||||
"title": "No language provided for monolingual text.",
|
||||
"body": "Some label, description, alias or monolingual text value have been skipped because no language was provided. Example value: <span class=\"wb-issue-preformat\">{example_text}</span>."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.qa.QAWarning;
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
||||
@ -24,15 +25,31 @@ public class WbMonolingualExpr extends WbValueExpr {
|
||||
@Override
|
||||
public MonolingualTextValue evaluate(ExpressionContext ctxt)
|
||||
throws SkipSchemaExpressionException {
|
||||
return Datamodel.makeMonolingualTextValue(
|
||||
getValueExpr().evaluate(ctxt).getString(),
|
||||
getLanguageExpr().evaluate(ctxt));
|
||||
String text = getValueExpr().evaluate(ctxt).getString();
|
||||
if (text.isEmpty())
|
||||
throw new SkipSchemaExpressionException();
|
||||
String lang = getLanguageExpr().evaluate(ctxt);
|
||||
if (lang.isEmpty()) {
|
||||
QAWarning warning = new QAWarning(
|
||||
"monolingual-text-without-language",
|
||||
null,
|
||||
QAWarning.Severity.WARNING,
|
||||
1);
|
||||
warning.setProperty("example_text", text);
|
||||
ctxt.addWarning(warning);
|
||||
throw new SkipSchemaExpressionException();
|
||||
}
|
||||
|
||||
return Datamodel.makeMonolingualTextValue(text, lang);
|
||||
|
||||
}
|
||||
|
||||
@JsonProperty("language")
|
||||
public WbLanguageExpr getLanguageExpr() {
|
||||
return languageExpr;
|
||||
}
|
||||
|
||||
@JsonProperty("value")
|
||||
public WbStringExpr getValueExpr() {
|
||||
return valueExpr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user