Introduce custom EntityIdValues to store localized labels
This commit is contained in:
parent
1ea1377734
commit
c844742395
@ -3,6 +3,9 @@ package org.openrefine.wikidata.editing;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import org.openrefine.wikidata.schema.entityvalues.NewEntityIdValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.google.refine.model.Project;
|
||||
@ -12,8 +15,6 @@ import com.google.refine.model.Recon;
|
||||
import com.google.refine.model.ReconCandidate;
|
||||
import com.google.refine.model.ReconStats;
|
||||
|
||||
import org.openrefine.wikidata.schema.NewEntityIdValue;
|
||||
|
||||
/**
|
||||
* This keeps track of the new items that we
|
||||
* have created for each cell that was marked
|
||||
|
@ -18,8 +18,8 @@ import org.openrefine.wikidata.editing.NewItemLibrary;
|
||||
import org.openrefine.wikidata.editing.CellCoordinates;
|
||||
import org.openrefine.wikidata.editing.CellCoordinatesKeyDeserializer;
|
||||
import org.openrefine.wikidata.schema.ItemUpdate;
|
||||
import org.openrefine.wikidata.schema.NewEntityIdValue;
|
||||
import org.openrefine.wikidata.schema.WikibaseSchema;
|
||||
import org.openrefine.wikidata.schema.entityvalues.NewEntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.implementation.DataObjectFactoryImpl;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.DataObjectFactory;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
|
||||
import org.openrefine.wikidata.schema.entityvalues.NewEntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
|
||||
@ -31,8 +32,12 @@ public class WbItemVariable extends WbItemExpr {
|
||||
ReconCandidate match = cell.recon.match;
|
||||
return Datamodel.makeItemIdValue(match.id, ctxt.getBaseIRI());
|
||||
} else if (recon.judgment == Recon.Judgment.New) {
|
||||
return new NewEntityIdValue(ctxt.getRowId(),
|
||||
ctxt.getCellIndexByName(getColumnName()));
|
||||
int rowId = ctxt.getRowId();
|
||||
int columnId = ctxt.getCellIndexByName(getColumnName());
|
||||
String siteIRI = ctxt.getBaseIRI();
|
||||
String label = ctxt.getCellByName(getColumnName()).value.toString();
|
||||
return new NewEntityIdValue(
|
||||
rowId, columnId, siteIRI, label);
|
||||
}
|
||||
}
|
||||
throw new SkipStatementException();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.schema.entityvalues.TermedPropertyIdValue;
|
||||
import org.wikidata.wdtk.datamodel.implementation.PropertyIdValueImpl;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
|
||||
@ -26,7 +27,7 @@ public class WbPropConstant extends WbPropExpr {
|
||||
|
||||
@Override
|
||||
public PropertyIdValue evaluate(ExpressionContext ctxt) {
|
||||
return PropertyIdValueImpl.create(pid, ctxt.getBaseIRI());
|
||||
return new TermedPropertyIdValue(pid, ctxt.getBaseIRI(), label);
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
package org.openrefine.wikidata.schema.entityvalues;
|
||||
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
@ -12,7 +12,7 @@ import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
||||
*
|
||||
* @author antonin
|
||||
*/
|
||||
public class NewEntityIdValue implements ItemIdValue {
|
||||
public class NewEntityIdValue extends TermedItemIdValue {
|
||||
|
||||
private final int rowId;
|
||||
private final int colId;
|
||||
@ -25,8 +25,11 @@ public class NewEntityIdValue implements ItemIdValue {
|
||||
* the index of the row for the cell
|
||||
* @param colId
|
||||
* the index of the column for the cell
|
||||
* @param label
|
||||
* the value of the cell
|
||||
*/
|
||||
public NewEntityIdValue(int rowId, int colId) {
|
||||
public NewEntityIdValue(int rowId, int colId, String siteIRI, String label) {
|
||||
super("Q0", siteIRI, label);
|
||||
this.rowId = rowId;
|
||||
this.colId = colId;
|
||||
}
|
||||
@ -61,30 +64,4 @@ public class NewEntityIdValue implements ItemIdValue {
|
||||
hash = 41*hash + colId;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIri() {
|
||||
return getSiteIri() + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ValueVisitor<T> valueVisitor) {
|
||||
return valueVisitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType() {
|
||||
return ET_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "Q0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSiteIri() {
|
||||
return EntityIdValue.SITE_LOCAL;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package org.openrefine.wikidata.schema.entityvalues;
|
||||
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
||||
|
||||
/**
|
||||
* An EntityIdValue that holds not just the id but also
|
||||
* the label as fetched by either the reconciliation interface
|
||||
* or the suggester.
|
||||
*
|
||||
* This label will be localized depending on the language chosen
|
||||
* by the user for OpenRefine's interface. Storing it lets us
|
||||
* reuse it later on without having to re-fetch it.
|
||||
* @author antonin
|
||||
*
|
||||
*/
|
||||
public abstract class TermedEntityIdValue implements EntityIdValue {
|
||||
|
||||
private String _id;
|
||||
private String _siteIRI;
|
||||
private String _label;
|
||||
|
||||
public TermedEntityIdValue(String id, String siteIRI, String label) {
|
||||
_id = id;
|
||||
_siteIRI = siteIRI;
|
||||
_label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String getEntityType();
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSiteIri() {
|
||||
return _siteIRI;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return _label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIri() {
|
||||
return getSiteIri() + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ValueVisitor<T> valueVisitor) {
|
||||
return valueVisitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.openrefine.wikidata.schema.entityvalues;
|
||||
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
|
||||
public class TermedItemIdValue extends TermedEntityIdValue implements ItemIdValue {
|
||||
|
||||
public TermedItemIdValue(String id, String siteIRI, String label) {
|
||||
super(id, siteIRI, label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType() {
|
||||
return ET_ITEM;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.openrefine.wikidata.schema.entityvalues;
|
||||
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
|
||||
public class TermedPropertyIdValue extends TermedEntityIdValue implements PropertyIdValue {
|
||||
|
||||
public TermedPropertyIdValue(String id, String siteIRI, String label) {
|
||||
super(id, siteIRI, label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityType() {
|
||||
return ET_PROPERTY;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user