Search in sources :

Example 1 with ReconMediaInfoIdValue

use of org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue in project OpenRefine by OpenRefine.

the class WbEntityVariableTest method testReconciledMediaInfoCell.

@Test
public void testReconciledMediaInfoCell() {
    Recon recon = Recon.makeWikidataRecon(3782378L);
    recon.judgment = Recon.Judgment.Matched;
    recon.match = new ReconCandidate("M123", "some item", null, 100.0);
    Cell cell = new Cell("some value", recon);
    evaluatesTo(new ReconMediaInfoIdValue(recon, "some value"), cell);
}
Also used : Recon(com.google.refine.model.Recon) Cell(com.google.refine.model.Cell) ReconCandidate(com.google.refine.model.ReconCandidate) ReconMediaInfoIdValue(org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue) JacksonSerializationTest(org.openrefine.wikidata.testing.JacksonSerializationTest) Test(org.testng.annotations.Test)

Example 2 with ReconMediaInfoIdValue

use of org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue in project OpenRefine by OpenRefine.

the class WbEntityVariable method fromCell.

@Override
public EntityIdValue fromCell(Cell cell, ExpressionContext ctxt) throws SkipSchemaExpressionException {
    if (cell.recon != null && (Judgment.Matched.equals(cell.recon.judgment) || Judgment.New.equals(cell.recon.judgment))) {
        if (Judgment.New.equals(cell.recon.judgment)) {
            return new ReconItemIdValue(cell.recon, cell.value.toString());
        }
        EntityIdValue entityIdValue = EntityIdValueImpl.fromId(cell.recon.match.id, cell.recon.identifierSpace);
        EntityIdValue reconEntityIdValue = null;
        String entityType = null;
        if (entityIdValue instanceof ItemIdValue) {
            reconEntityIdValue = new ReconItemIdValue(cell.recon, cell.value.toString());
            entityType = "item";
        } else if (entityIdValue instanceof MediaInfoIdValue) {
            reconEntityIdValue = new ReconMediaInfoIdValue(cell.recon, cell.value.toString());
            entityType = "mediainfo";
        } else if (entityIdValue instanceof PropertyIdValue) {
            reconEntityIdValue = new ReconPropertyIdValue(cell.recon, cell.value.toString());
            entityType = "property";
        }
        if (reconEntityIdValue == null) {
            throw new SkipSchemaExpressionException();
        }
        if (cell.recon.identifierSpace == null || !cell.recon.identifierSpace.equals(ctxt.getBaseIRIForEntityType(entityType))) {
            QAWarning warning = new QAWarning("invalid-identifier-space", null, QAWarning.Severity.INFO, 1);
            warning.setProperty("example_cell", cell.value.toString());
            warning.setProperty("expected_site_iri", ctxt.getBaseIRIForEntityType(entityType));
            ctxt.addWarning(warning);
            throw new SkipSchemaExpressionException();
        }
        return reconEntityIdValue;
    }
    throw new SkipSchemaExpressionException();
}
Also used : ReconItemIdValue(org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) ReconPropertyIdValue(org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue) ReconItemIdValue(org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue) ReconMediaInfoIdValue(org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue) MediaInfoIdValue(org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) ReconPropertyIdValue(org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue) QAWarning(org.openrefine.wikidata.qa.QAWarning) ReconMediaInfoIdValue(org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue)

Aggregations

ReconMediaInfoIdValue (org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue)2 Cell (com.google.refine.model.Cell)1 Recon (com.google.refine.model.Recon)1 ReconCandidate (com.google.refine.model.ReconCandidate)1 QAWarning (org.openrefine.wikidata.qa.QAWarning)1 ReconItemIdValue (org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue)1 ReconPropertyIdValue (org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue)1 SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)1 JacksonSerializationTest (org.openrefine.wikidata.testing.JacksonSerializationTest)1 Test (org.testng.annotations.Test)1 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)1 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)1 MediaInfoIdValue (org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue)1 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)1