Refuse reconciled cells with invalid space

This commit is contained in:
Antonin Delpeuch 2018-04-13 18:51:45 +02:00
parent d6232efd95
commit 0c21d6d171
3 changed files with 22 additions and 0 deletions

View File

@ -193,6 +193,10 @@
"non-printable-characters": {
"title": "Non-printable characters in strings.",
"body": "Strings such as <span class=\"wb-issue-preformat\">{example_string}</span> contain non-printable characters."
},
"invalid-identifier-space": {
"title": "Invalid identifier space for reconciled cells.",
"body": "Some reconciled cells such as <span class=\"wb-issue-preformat\">{example_cell}</span> were ignored because they are not reconciled to Wikidata."
}
}
}

View File

@ -23,8 +23,10 @@
******************************************************************************/
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.qa.QAWarning;
import org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import com.fasterxml.jackson.annotation.JsonCreator;
@ -61,6 +63,12 @@ public class WbItemVariable extends WbVariableExpr<ItemIdValue> {
throws SkipSchemaExpressionException {
if (cell.recon != null
&& (Judgment.Matched.equals(cell.recon.judgment) || Judgment.New.equals(cell.recon.judgment))) {
if (!cell.recon.identifierSpace.equals(Datamodel.SITE_WIKIDATA)) {
QAWarning warning = new QAWarning("invalid-identifier-space", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_cell", cell.value.toString());
ctxt.addWarning(warning);
throw new SkipSchemaExpressionException();
}
return new ReconItemIdValue(cell.recon, cell.value.toString());
}
throw new SkipSchemaExpressionException();

View File

@ -67,6 +67,16 @@ public class WbItemVariableTest extends WbVariableTest<ItemIdValue> {
Cell cell = new Cell("some value", recon);
isSkipped(cell);
}
@Test
public void testInvalidSpace() {
Recon recon = Recon.makeWikidataRecon(34989L);
recon.identifierSpace = "http://my.own.wikiba.se/";
recon.candidates = Collections.singletonList(new ReconCandidate("Q123", "some item", null, 100.0));
recon.judgment = Recon.Judgment.Matched;
Cell cell = new Cell("some value", recon);
isSkipped(cell);
}
@Test
public void testUnreconciledCell() {