From c845105a39d79a71a8002ea1b8dba4153d6d3121 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 24 Jan 2018 19:01:09 +0000 Subject: [PATCH] Cleanup JSON serialization and rename WbValueExpr to WbExpression --- .../wikidata/schema/WbDateConstant.java | 2 +- .../{WbValueExpr.java => WbExpression.java} | 6 +----- .../wikidata/schema/WbItemConstant.java | 2 +- .../wikidata/schema/WbItemDocumentExpr.java | 6 +++--- .../wikidata/schema/WbLanguageConstant.java | 2 +- .../wikidata/schema/WbLanguageVariable.java | 3 --- .../wikidata/schema/WbLocationConstant.java | 2 +- .../wikidata/schema/WbMonolingualExpr.java | 14 +++++++------- .../wikidata/schema/WbNameDescExpr.java | 3 +-- .../wikidata/schema/WbPropConstant.java | 2 +- .../wikidata/schema/WbReferenceExpr.java | 4 ++-- .../wikidata/schema/WbSnakExpr.java | 16 ++++++++-------- .../wikidata/schema/WbStatementExpr.java | 19 ++++++------------- .../wikidata/schema/WbStatementGroupExpr.java | 9 ++++----- .../wikidata/schema/WbStringConstant.java | 2 +- .../wikidata/schema/WbStringVariable.java | 3 --- .../wikidata/schema/WbVariableExpr.java | 3 +-- .../wikidata/schema/WikibaseSchema.java | 7 ------- 18 files changed, 39 insertions(+), 66 deletions(-) rename extensions/wikidata/src/org/openrefine/wikidata/schema/{WbValueExpr.java => WbExpression.java} (89%) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java index bafc42a2c..90f1c02aa 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; -public class WbDateConstant implements WbValueExpr { +public class WbDateConstant implements WbExpression { public static Map acceptedFormats = ImmutableMap.builder() .put(new SimpleDateFormat("yyyy"), 9) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbValueExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbExpression.java similarity index 89% rename from extensions/wikidata/src/org/openrefine/wikidata/schema/WbValueExpr.java rename to extensions/wikidata/src/org/openrefine/wikidata/schema/WbExpression.java index 40dfbd94e..e412e1ed1 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbValueExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbExpression.java @@ -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 { +public interface WbExpression { /** * Evaluates the value expression in a given context, diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemConstant.java index b317cdea1..3ccb75f65 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemConstant.java @@ -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 { +public class WbItemConstant implements WbExpression { private String qid; private String label; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java index a79bc2a61..7b9d2419d 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java @@ -19,13 +19,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; */ public class WbItemDocumentExpr extends JacksonJsonizable { - private WbValueExpr subject; + private WbExpression subject; private List nameDescs; private List statementGroups; @JsonCreator public WbItemDocumentExpr( - @JsonProperty("subject") WbValueExpr subjectExpr, + @JsonProperty("subject") WbExpression subjectExpr, @JsonProperty("nameDescs") List nameDescExprs, @JsonProperty("statementGroups") List statementGroupExprs) { this.subject = subjectExpr; @@ -52,7 +52,7 @@ public class WbItemDocumentExpr extends JacksonJsonizable { } @JsonProperty("subject") - public WbValueExpr getSubject() { + public WbExpression getSubject() { return subject; } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageConstant.java index f63cb5630..1edd81012 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageConstant.java @@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @author antonin * */ -public class WbLanguageConstant implements WbValueExpr { +public class WbLanguageConstant implements WbExpression { protected String _langId; protected String _langLabel; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageVariable.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageVariable.java index 869b0524a..081019e5b 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageVariable.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLanguageVariable.java @@ -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; /** diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLocationConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLocationConstant.java index 133e3931b..e8e4476fd 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLocationConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbLocationConstant.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -public class WbLocationConstant implements WbValueExpr { +public class WbLocationConstant implements WbExpression { private String value; private GlobeCoordinatesValue parsed; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbMonolingualExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbMonolingualExpr.java index 6d7c7aa72..1ec09972f 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbMonolingualExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbMonolingualExpr.java @@ -10,15 +10,15 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -public class WbMonolingualExpr implements WbValueExpr { +public class WbMonolingualExpr implements WbExpression { - private WbValueExpr languageExpr; - private WbValueExpr valueExpr; + private WbExpression languageExpr; + private WbExpression valueExpr; @JsonCreator public WbMonolingualExpr( - @JsonProperty("language") WbValueExpr languageExpr, - @JsonProperty("value") WbValueExpr valueExpr) { + @JsonProperty("language") WbExpression languageExpr, + @JsonProperty("value") WbExpression valueExpr) { this.languageExpr = languageExpr; this.valueExpr = valueExpr; } @@ -46,12 +46,12 @@ public class WbMonolingualExpr implements WbValueExpr { } @JsonProperty("language") - public WbValueExpr getLanguageExpr() { + public WbExpression getLanguageExpr() { return languageExpr; } @JsonProperty("value") - public WbValueExpr getValueExpr() { + public WbExpression getValueExpr() { return valueExpr; } } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbNameDescExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbNameDescExpr.java index 10e689b43..82af0e5dc 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbNameDescExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbNameDescExpr.java @@ -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, diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbPropConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbPropConstant.java index 33bc13406..2dbace15f 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbPropConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbPropConstant.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @author antonin * */ -public class WbPropConstant implements WbValueExpr { +public class WbPropConstant implements WbExpression { private String pid; private String label; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java index 646da1b20..995632ffa 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbReferenceExpr.java @@ -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 { private List snakExprs; @JsonCreator @@ -23,6 +22,7 @@ public class WbReferenceExpr extends JacksonJsonizable { this.snakExprs = snakExprs; } + @Override public Reference evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException { List snakGroups = new ArrayList(); for (WbSnakExpr expr : getSnaks()) { diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java index 32c4a30c3..e3de1b4f6 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java @@ -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 { - private WbValueExpr prop; - private WbValueExpr value; + private WbExpression prop; + private WbExpression value; @JsonCreator public WbSnakExpr( - @JsonProperty("prop") WbValueExpr propExpr, - @JsonProperty("value") WbValueExpr valueExpr) { + @JsonProperty("prop") WbExpression propExpr, + @JsonProperty("value") WbExpression 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 getProp() { + public WbExpression getProp() { return prop; } @JsonProperty("value") - public WbValueExpr getValue() { + public WbExpression getValue() { return value; } } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java index 7dd744572..29e619cbb 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementExpr.java @@ -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 mainSnakValueExpr; + private WbExpression mainSnakValueExpr; private List qualifierExprs; private List referenceExprs; @JsonCreator public WbStatementExpr( - @JsonProperty("value") WbValueExpr mainSnakValueExpr, + @JsonProperty("value") WbExpression mainSnakValueExpr, @JsonProperty("qualifiers") List qualifierExprs, @JsonProperty("references") List 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 getMainsnak() { + public WbExpression getMainsnak() { return mainSnakValueExpr; } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java index b8e80a639..bb05d3174 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStatementGroupExpr.java @@ -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 propertyExpr; + private WbExpression propertyExpr; private List statementExprs; @JsonCreator public WbStatementGroupExpr( - @JsonProperty("property") WbValueExpr propertyExpr, + @JsonProperty("property") WbExpression propertyExpr, @JsonProperty("statements") List claimExprs) { this.propertyExpr = propertyExpr; this.statementExprs = claimExprs; @@ -46,7 +45,7 @@ public class WbStatementGroupExpr extends JacksonJsonizable { } @JsonProperty("property") - public WbValueExpr getProperty() { + public WbExpression getProperty() { return propertyExpr; } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringConstant.java index e3d9a247a..67d17f016 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringConstant.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -public class WbStringConstant implements WbValueExpr { +public class WbStringConstant implements WbExpression { private String value; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringVariable.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringVariable.java index 8697f2027..a23c03ad2 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringVariable.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbStringVariable.java @@ -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; /** diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbVariableExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbVariableExpr.java index 2d14a673d..363808a2a 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbVariableExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbVariableExpr.java @@ -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 * the type of Wikibase value returned by the expression. */ -public abstract class WbVariableExpr implements WbValueExpr { +public abstract class WbVariableExpr implements WbExpression { private String columnName; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java index 607f62abc..b578f8dfa 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java @@ -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;