Add warning for monolingual exprs without language
This commit is contained in:
parent
69bfad6a47
commit
93883fd777
@ -112,6 +112,10 @@
|
|||||||
"ignored-references": {
|
"ignored-references": {
|
||||||
"title": "Some references were ignored.",
|
"title": "Some references were ignored.",
|
||||||
"body": "None of their statements could be parsed, so no reference was added."
|
"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;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.qa.QAWarning;
|
||||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
||||||
@ -24,15 +25,31 @@ public class WbMonolingualExpr extends WbValueExpr {
|
|||||||
@Override
|
@Override
|
||||||
public MonolingualTextValue evaluate(ExpressionContext ctxt)
|
public MonolingualTextValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipSchemaExpressionException {
|
throws SkipSchemaExpressionException {
|
||||||
return Datamodel.makeMonolingualTextValue(
|
String text = getValueExpr().evaluate(ctxt).getString();
|
||||||
getValueExpr().evaluate(ctxt).getString(),
|
if (text.isEmpty())
|
||||||
getLanguageExpr().evaluate(ctxt));
|
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() {
|
public WbLanguageExpr getLanguageExpr() {
|
||||||
return languageExpr;
|
return languageExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("value")
|
||||||
public WbStringExpr getValueExpr() {
|
public WbStringExpr getValueExpr() {
|
||||||
return valueExpr;
|
return valueExpr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user