Schema editing cleanup

This commit is contained in:
Antonin Delpeuch 2018-03-03 19:34:56 +00:00
parent 6cb4386e64
commit 15ba7fbdde
12 changed files with 107 additions and 15 deletions

View File

@ -15,10 +15,15 @@ WarningsRenderer._renderEntity = function(entity) {
fullLabel = entity.label + ' (' + id + ')';
}
var url = entity.iri;
if (!url && entity.value) {
url = 'http://www.wikidata.org/entity/'+entity.value.id;
}
if (is_new) {
return '<span class="wb-preview-new-entity">'+fullLabel+'</span>';
} else {
return '<a href="'+entity.iri+'" class="wb-preview-entity" target="_blank">'+fullLabel+'</a>';
return '<a href="'+url+'" class="wb-preview-entity" target="_blank">'+fullLabel+'</a>';
}
}

View File

@ -74,6 +74,7 @@ public class EditInspector {
// so that all newly created entities appear in the batch
WikibaseAPIUpdateScheduler scheduler = new WikibaseAPIUpdateScheduler();
editBatch = scheduler.schedule(editBatch);
Map<EntityIdValue, ItemUpdate> updates = ItemUpdate.groupBySubject(editBatch);
List<ItemUpdate> mergedUpdates = updates.values().stream().collect(Collectors.toList());
for(EditScrutinizer scrutinizer : scrutinizers.values()) {

View File

@ -1,9 +1,11 @@
package org.openrefine.wikidata.schema;
import org.apache.commons.lang.Validate;
import org.openrefine.wikidata.qa.QAWarning;
import org.openrefine.wikidata.qa.QAWarningStore;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
import com.google.refine.model.ColumnModel;
import com.google.refine.model.Row;
@ -11,7 +13,7 @@ import com.google.refine.model.Row;
* A class holding all the necessary information about
* the context in which a schema expression is evaluated.
*
* @author antonin
* @author Antonin Delpeuch
*
*/
public class ExpressionContext {
@ -23,12 +25,17 @@ public class ExpressionContext {
/**
* Builds an expression context to evaluate a schema on a row
* @param baseIRI: the siteIRI of the schema
* @param rowId: the id of the row currently visited
* @param row: the row itself
* @param columnModel: lets us access cells by column name
* @param warningStore: where to store the issues encountered when
* evaluating (can be set to null if these issues should be ignored)
* @param baseIRI
* the siteIRI of the schema
* @param rowId
* the id of the row currently visited
* @param row
* the row itself
* @param columnModel
* lets us access cells by column name
* @param warningStore
* where to store the issues encountered when
* evaluating (can be set to null if these issues should be ignored)
*/
public ExpressionContext(
String baseIRI,
@ -36,9 +43,12 @@ public class ExpressionContext {
Row row,
ColumnModel columnModel,
QAWarningStore warningStore) {
Validate.notNull(baseIRI);
this.baseIRI = baseIRI;
this.rowId = rowId;
Validate.notNull(row);
this.row = row;
Validate.notNull(columnModel);
this.columnModel = columnModel;
this.warningStore = warningStore;
}
@ -46,14 +56,23 @@ public class ExpressionContext {
public String getBaseIRI() {
return baseIRI;
}
public int getCellIndexByName(String name) {
return columnModel.getColumnByName(name).getCellIndex();
}
/**
* Retrieves a cell in the current row, by column name.
* If the column does not exist, null is returned.
*
* @param name
* the name of the column to retrieve the cell from
* @return
* the cell
*/
public Cell getCellByName(String name) {
int idx = getCellIndexByName(name);
return row.getCell(idx);
Column column = columnModel.getColumnByName(name);
if (column != null) {
int idx = column.getCellIndex();
return row.getCell(idx);
} else {
return null;
}
}
public int getRowId() {

View File

@ -1,7 +1,9 @@
package org.openrefine.wikidata.schema;
import java.util.Collections;
import java.util.List;
import org.jsoup.helper.Validate;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.updates.ItemUpdate;
import org.openrefine.wikidata.updates.ItemUpdateBuilder;
@ -34,8 +36,15 @@ public class WbItemDocumentExpr extends JacksonJsonizable implements WbExpressio
@JsonProperty("subject") WbExpression<? extends ItemIdValue> subjectExpr,
@JsonProperty("nameDescs") List<WbNameDescExpr> nameDescExprs,
@JsonProperty("statementGroups") List<WbStatementGroupExpr> statementGroupExprs) {
Validate.notNull(subjectExpr);
this.subject = subjectExpr;
if(nameDescExprs == null) {
nameDescExprs = Collections.emptyList();
}
this.nameDescs = nameDescExprs;
if(statementGroupExprs == null) {
statementGroupExprs = Collections.emptyList();
}
this.statementGroups = statementGroupExprs;
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.apache.commons.lang.Validate;
import org.openrefine.wikidata.qa.QAWarning;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
@ -19,7 +20,9 @@ public class WbMonolingualExpr implements WbExpression<MonolingualTextValue> {
public WbMonolingualExpr(
@JsonProperty("language") WbExpression<? extends String> languageExpr,
@JsonProperty("value") WbExpression<? extends StringValue> valueExpr) {
Validate.notNull(languageExpr);
this.languageExpr = languageExpr;
Validate.notNull(valueExpr);
this.valueExpr = valueExpr;
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.jsoup.helper.Validate;
import org.openrefine.wikidata.schema.entityvalues.SuggestedPropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
@ -23,7 +24,9 @@ public class WbPropConstant implements WbExpression<PropertyIdValue> {
@JsonProperty("pid") String pid,
@JsonProperty("label") String label,
@JsonProperty("datatype") String datatype) {
Validate.notNull(pid);
this.pid = pid;
Validate.notNull(label);
this.label = label;
this.datatype = datatype;
}

View File

@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.Reference;
@ -28,6 +29,7 @@ public class WbReferenceExpr implements WbExpression<Reference> {
@JsonCreator
public WbReferenceExpr(
@JsonProperty("snaks") List<WbSnakExpr> snakExprs) {
Validate.notNull(snakExprs);
this.snakExprs = snakExprs;
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.jsoup.helper.Validate;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
@ -28,7 +29,9 @@ public class WbSnakExpr implements WbExpression<Snak> {
public WbSnakExpr(
@JsonProperty("prop") WbExpression<? extends PropertyIdValue> propExpr,
@JsonProperty("value") WbExpression<? extends Value> valueExpr) {
Validate.notNull(propExpr);
this.prop = propExpr;
Validate.notNull(valueExpr);
this.value = valueExpr;
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.apache.commons.lang.Validate;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
@ -13,6 +14,7 @@ public class WbStringConstant implements WbExpression<StringValue> {
@JsonCreator
public WbStringConstant(@JsonProperty("value") String value) {
Validate.notNull(value);
this.value = value;
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.wikidata.wdtk.datamodel.helpers.Hash;
import org.wikidata.wdtk.datamodel.helpers.ToString;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
@ -70,4 +71,5 @@ public abstract class SuggestedEntityIdValue implements PrefetchedEntityIdValue
public int hashCode() {
return Hash.hashCode(this);
}
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema.entityvalues;
import org.wikidata.wdtk.datamodel.helpers.ToString;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
public class SuggestedPropertyIdValue extends SuggestedEntityIdValue implements PropertyIdValue {
@ -13,4 +14,8 @@ public class SuggestedPropertyIdValue extends SuggestedEntityIdValue implements
return ET_PROPERTY;
}
@Override
public String toString() {
return "suggested "+ToString.toString(this)+" (\""+getLabel()+"\")";
}
}

View File

@ -0,0 +1,38 @@
package org.openrefine.wikidata.schema;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.model.Project;
import com.google.refine.tests.RefineTest;
public class ExpressionContextTest extends RefineTest {
Project project = null;
@BeforeMethod
public void setUp() {
project = createCSVProject("a,b\nc\nd,e");
}
@Test
public void testGetCellByColumnName() {
ExpressionContext ctxt = new ExpressionContext("foo:", 1, project.rows.get(1), project.columnModel, null);
assertEquals("e", ctxt.getCellByName("b").value);
}
@Test
public void testNonExistentColumn() {
ExpressionContext ctxt = new ExpressionContext("foo:", 1, project.rows.get(1), project.columnModel, null);
assertNull(ctxt.getCellByName("auie"));
}
@Test
public void testGetRowId() {
ExpressionContext ctxt = new ExpressionContext("foo:", 1, project.rows.get(1), project.columnModel, null);
assertEquals(1, ctxt.getRowId());
}
}