Cleanup JSON serialization and rename WbValueExpr to WbExpression
This commit is contained in:
parent
b99b72b071
commit
c845105a39
@ -17,7 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
|
||||
public class WbDateConstant implements WbValueExpr<TimeValue> {
|
||||
public class WbDateConstant implements WbExpression<TimeValue> {
|
||||
|
||||
public static Map<SimpleDateFormat,Integer> acceptedFormats = ImmutableMap.<SimpleDateFormat,Integer>builder()
|
||||
.put(new SimpleDateFormat("yyyy"), 9)
|
||||
|
@ -1,10 +1,6 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
@ -33,7 +29,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
||||
@Type(value = WbLanguageConstant.class, name = "wblanguageconstant"),
|
||||
@Type(value = WbLanguageVariable.class, name = "wblanguagevariable"),
|
||||
})
|
||||
public interface WbValueExpr<T> {
|
||||
public interface WbExpression<T> {
|
||||
|
||||
/**
|
||||
* Evaluates the value expression in a given context,
|
@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* Represents an item that does not vary,
|
||||
* it is independent of the row.
|
||||
*/
|
||||
public class WbItemConstant implements WbValueExpr<ItemIdValue> {
|
||||
public class WbItemConstant implements WbExpression<ItemIdValue> {
|
||||
|
||||
private String qid;
|
||||
private String label;
|
||||
|
@ -19,13 +19,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
*/
|
||||
public class WbItemDocumentExpr extends JacksonJsonizable {
|
||||
|
||||
private WbValueExpr<? extends ItemIdValue> subject;
|
||||
private WbExpression<? extends ItemIdValue> subject;
|
||||
private List<WbNameDescExpr> nameDescs;
|
||||
private List<WbStatementGroupExpr> statementGroups;
|
||||
|
||||
@JsonCreator
|
||||
public WbItemDocumentExpr(
|
||||
@JsonProperty("subject") WbValueExpr<? extends ItemIdValue> subjectExpr,
|
||||
@JsonProperty("subject") WbExpression<? extends ItemIdValue> subjectExpr,
|
||||
@JsonProperty("nameDescs") List<WbNameDescExpr> nameDescExprs,
|
||||
@JsonProperty("statementGroups") List<WbStatementGroupExpr> statementGroupExprs) {
|
||||
this.subject = subjectExpr;
|
||||
@ -52,7 +52,7 @@ public class WbItemDocumentExpr extends JacksonJsonizable {
|
||||
}
|
||||
|
||||
@JsonProperty("subject")
|
||||
public WbValueExpr<? extends ItemIdValue> getSubject() {
|
||||
public WbExpression<? extends ItemIdValue> getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* @author antonin
|
||||
*
|
||||
*/
|
||||
public class WbLanguageConstant implements WbValueExpr<String> {
|
||||
public class WbLanguageConstant implements WbExpression<String> {
|
||||
|
||||
protected String _langId;
|
||||
protected String _langLabel;
|
||||
|
@ -2,9 +2,6 @@ package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.model.Cell;
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbLocationConstant implements WbValueExpr<GlobeCoordinatesValue> {
|
||||
public class WbLocationConstant implements WbExpression<GlobeCoordinatesValue> {
|
||||
|
||||
private String value;
|
||||
private GlobeCoordinatesValue parsed;
|
||||
|
@ -10,15 +10,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbMonolingualExpr implements WbValueExpr<MonolingualTextValue> {
|
||||
public class WbMonolingualExpr implements WbExpression<MonolingualTextValue> {
|
||||
|
||||
private WbValueExpr<? extends String> languageExpr;
|
||||
private WbValueExpr<? extends StringValue> valueExpr;
|
||||
private WbExpression<? extends String> languageExpr;
|
||||
private WbExpression<? extends StringValue> valueExpr;
|
||||
|
||||
@JsonCreator
|
||||
public WbMonolingualExpr(
|
||||
@JsonProperty("language") WbValueExpr<? extends String> languageExpr,
|
||||
@JsonProperty("value") WbValueExpr<? extends StringValue> valueExpr) {
|
||||
@JsonProperty("language") WbExpression<? extends String> languageExpr,
|
||||
@JsonProperty("value") WbExpression<? extends StringValue> valueExpr) {
|
||||
this.languageExpr = languageExpr;
|
||||
this.valueExpr = valueExpr;
|
||||
}
|
||||
@ -46,12 +46,12 @@ public class WbMonolingualExpr implements WbValueExpr<MonolingualTextValue> {
|
||||
}
|
||||
|
||||
@JsonProperty("language")
|
||||
public WbValueExpr<? extends String> getLanguageExpr() {
|
||||
public WbExpression<? extends String> getLanguageExpr() {
|
||||
return languageExpr;
|
||||
}
|
||||
|
||||
@JsonProperty("value")
|
||||
public WbValueExpr<? extends StringValue> getValueExpr() {
|
||||
public WbExpression<? extends StringValue> getValueExpr() {
|
||||
return valueExpr;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbNameDescExpr extends JacksonJsonizable {
|
||||
public class WbNameDescExpr {
|
||||
|
||||
enum NameDescrType {
|
||||
LABEL,
|
||||
|
@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* @author antonin
|
||||
*
|
||||
*/
|
||||
public class WbPropConstant implements WbValueExpr<PropertyIdValue> {
|
||||
public class WbPropConstant implements WbExpression<PropertyIdValue> {
|
||||
|
||||
private String pid;
|
||||
private String label;
|
||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
||||
@ -14,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbReferenceExpr extends JacksonJsonizable {
|
||||
public class WbReferenceExpr implements WbExpression<Reference> {
|
||||
private List<WbSnakExpr> snakExprs;
|
||||
|
||||
@JsonCreator
|
||||
@ -23,6 +22,7 @@ public class WbReferenceExpr extends JacksonJsonizable {
|
||||
this.snakExprs = snakExprs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reference evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||
List<SnakGroup> snakGroups = new ArrayList<SnakGroup>();
|
||||
for (WbSnakExpr expr : getSnaks()) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
||||
@ -11,19 +10,20 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbSnakExpr extends JacksonJsonizable {
|
||||
public class WbSnakExpr implements WbExpression<Snak> {
|
||||
|
||||
private WbValueExpr<? extends PropertyIdValue> prop;
|
||||
private WbValueExpr<? extends Value> value;
|
||||
private WbExpression<? extends PropertyIdValue> prop;
|
||||
private WbExpression<? extends Value> value;
|
||||
|
||||
@JsonCreator
|
||||
public WbSnakExpr(
|
||||
@JsonProperty("prop") WbValueExpr<? extends PropertyIdValue> propExpr,
|
||||
@JsonProperty("value") WbValueExpr<? extends Value> valueExpr) {
|
||||
@JsonProperty("prop") WbExpression<? extends PropertyIdValue> propExpr,
|
||||
@JsonProperty("value") WbExpression<? extends Value> valueExpr) {
|
||||
this.prop = propExpr;
|
||||
this.value = valueExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Snak evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||
PropertyIdValue propertyId = getProp().evaluate(ctxt);
|
||||
Value evaluatedValue = value.evaluate(ctxt);
|
||||
@ -31,12 +31,12 @@ public class WbSnakExpr extends JacksonJsonizable {
|
||||
}
|
||||
|
||||
@JsonProperty("prop")
|
||||
public WbValueExpr<? extends PropertyIdValue> getProp() {
|
||||
public WbExpression<? extends PropertyIdValue> getProp() {
|
||||
return prop;
|
||||
}
|
||||
|
||||
@JsonProperty("value")
|
||||
public WbValueExpr<? extends Value> getValue() {
|
||||
public WbExpression<? extends Value> getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,10 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
import org.openrefine.wikidata.qa.QAWarning;
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Claim;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
@ -28,15 +20,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbStatementExpr extends JacksonJsonizable {
|
||||
public class WbStatementExpr {
|
||||
|
||||
private WbValueExpr<? extends Value> mainSnakValueExpr;
|
||||
private WbExpression<? extends Value> mainSnakValueExpr;
|
||||
private List<WbSnakExpr> qualifierExprs;
|
||||
private List<WbReferenceExpr> referenceExprs;
|
||||
|
||||
@JsonCreator
|
||||
public WbStatementExpr(
|
||||
@JsonProperty("value") WbValueExpr<? extends Value> mainSnakValueExpr,
|
||||
@JsonProperty("value") WbExpression<? extends Value> mainSnakValueExpr,
|
||||
@JsonProperty("qualifiers") List<WbSnakExpr> qualifierExprs,
|
||||
@JsonProperty("references") List<WbReferenceExpr> referenceExprs) {
|
||||
this.mainSnakValueExpr = mainSnakValueExpr;
|
||||
@ -54,7 +46,8 @@ public class WbStatementExpr extends JacksonJsonizable {
|
||||
return snakGroups;
|
||||
}
|
||||
|
||||
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId) throws SkipSchemaExpressionException {
|
||||
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId)
|
||||
throws SkipSchemaExpressionException {
|
||||
Value mainSnakValue = getMainsnak().evaluate(ctxt);
|
||||
Snak mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
|
||||
|
||||
@ -99,7 +92,7 @@ public class WbStatementExpr extends JacksonJsonizable {
|
||||
}
|
||||
|
||||
@JsonProperty("value")
|
||||
public WbValueExpr<? extends Value> getMainsnak() {
|
||||
public WbExpression<? extends Value> getMainsnak() {
|
||||
return mainSnakValueExpr;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
@ -15,14 +14,14 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbStatementGroupExpr extends JacksonJsonizable {
|
||||
public class WbStatementGroupExpr {
|
||||
|
||||
private WbValueExpr<? extends PropertyIdValue> propertyExpr;
|
||||
private WbExpression<? extends PropertyIdValue> propertyExpr;
|
||||
private List<WbStatementExpr> statementExprs;
|
||||
|
||||
@JsonCreator
|
||||
public WbStatementGroupExpr(
|
||||
@JsonProperty("property") WbValueExpr<? extends PropertyIdValue> propertyExpr,
|
||||
@JsonProperty("property") WbExpression<? extends PropertyIdValue> propertyExpr,
|
||||
@JsonProperty("statements") List<WbStatementExpr> claimExprs) {
|
||||
this.propertyExpr = propertyExpr;
|
||||
this.statementExprs = claimExprs;
|
||||
@ -46,7 +45,7 @@ public class WbStatementGroupExpr extends JacksonJsonizable {
|
||||
}
|
||||
|
||||
@JsonProperty("property")
|
||||
public WbValueExpr<? extends PropertyIdValue> getProperty() {
|
||||
public WbExpression<? extends PropertyIdValue> getProperty() {
|
||||
return propertyExpr;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
|
||||
public class WbStringConstant implements WbValueExpr<StringValue> {
|
||||
public class WbStringConstant implements WbExpression<StringValue> {
|
||||
|
||||
private String value;
|
||||
|
||||
|
@ -4,9 +4,6 @@ import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.model.Cell;
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
@ -17,7 +16,7 @@ import com.google.refine.model.Cell;
|
||||
* @param <T>
|
||||
* the type of Wikibase value returned by the expression.
|
||||
*/
|
||||
public abstract class WbVariableExpr<T> implements WbValueExpr<T> {
|
||||
public abstract class WbVariableExpr<T> implements WbExpression<T> {
|
||||
|
||||
private String columnName;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
@ -11,12 +10,6 @@ import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.FilteredRows;
|
||||
|
Loading…
Reference in New Issue
Block a user