Move exceptions to own package
This commit is contained in:
parent
5d9aa9cae5
commit
bf7000e601
@ -1,6 +0,0 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
|
||||||
|
|
||||||
|
|
||||||
public class SkipStatementException extends Exception {
|
|
||||||
static final long serialVersionUID = 738592057L;
|
|
||||||
}
|
|
@ -7,6 +7,7 @@ import java.util.Map.Entry;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
|
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
|
||||||
|
|
||||||
@ -38,9 +39,9 @@ public class WbDateConstant extends WbDateExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TimeValue evaluate(ExpressionContext ctxt)
|
public TimeValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
|
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
|
||||||
|
|
||||||
public abstract class WbDateExpr extends WbValueExpr {
|
public abstract class WbDateExpr extends WbValueExpr {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract TimeValue evaluate(ExpressionContext ctxt)
|
public abstract TimeValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException;
|
throws SkipSchemaExpressionException;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
|
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
@ -22,7 +23,7 @@ public class WbDateVariable extends WbDateExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TimeValue evaluate(ExpressionContext ctxt)
|
public TimeValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
Cell cell = ctxt.getCellByName(columnName);
|
Cell cell = ctxt.getCellByName(columnName);
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
try {
|
try {
|
||||||
@ -31,7 +32,7 @@ public class WbDateVariable extends WbDateExpr {
|
|||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnName() {
|
public String getColumnName() {
|
||||||
|
@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||||
@ -26,7 +27,7 @@ public class WbItemDocumentExpr extends JacksonJsonizable {
|
|||||||
this.statementGroups = statementGroupExprs;
|
this.statementGroups = statementGroupExprs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemUpdate evaluate(ExpressionContext ctxt) throws SkipStatementException {
|
public ItemUpdate evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||||
ItemIdValue subjectId = getSubject().evaluate(ctxt);
|
ItemIdValue subjectId = getSubject().evaluate(ctxt);
|
||||||
ItemUpdate update = new ItemUpdate(subjectId);
|
ItemUpdate update = new ItemUpdate(subjectId);
|
||||||
for(WbStatementGroupExpr expr : getStatementGroups()) {
|
for(WbStatementGroupExpr expr : getStatementGroups()) {
|
||||||
|
@ -2,9 +2,10 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import org.openrefine.wikidata.schema.ExpressionContext;
|
import org.openrefine.wikidata.schema.ExpressionContext;
|
||||||
import org.openrefine.wikidata.schema.WbValueExpr;
|
import org.openrefine.wikidata.schema.WbValueExpr;
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
|
|
||||||
|
|
||||||
public abstract class WbItemExpr extends WbValueExpr {
|
public abstract class WbItemExpr extends WbValueExpr {
|
||||||
public abstract ItemIdValue evaluate(ExpressionContext ctxt) throws SkipStatementException;
|
public abstract ItemIdValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import org.openrefine.wikidata.schema.entityvalues.NewEntityIdValue;
|
import org.openrefine.wikidata.schema.entityvalues.NewEntityIdValue;
|
||||||
import org.openrefine.wikidata.schema.entityvalues.TermedItemIdValue;
|
import org.openrefine.wikidata.schema.entityvalues.TermedItemIdValue;
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ public class WbItemVariable extends WbItemExpr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemIdValue evaluate(ExpressionContext ctxt) throws SkipStatementException {
|
public ItemIdValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||||
Cell cell = ctxt.getCellByName(getColumnName());
|
Cell cell = ctxt.getCellByName(getColumnName());
|
||||||
if (cell != null && cell.recon != null) {
|
if (cell != null && cell.recon != null) {
|
||||||
Recon recon = cell.recon;
|
Recon recon = cell.recon;
|
||||||
@ -48,7 +49,7 @@ public class WbItemVariable extends WbItemExpr {
|
|||||||
rowId, columnId, siteIRI, label);
|
rowId, columnId, siteIRI, label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnName() {
|
public String getColumnName() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
@ -18,7 +20,7 @@ public class WbLanguageConstant extends WbLanguageExpr {
|
|||||||
_langLabel = langLabel;
|
_langLabel = langLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String evaluate(ExpressionContext ctxt) throws SkipStatementException {
|
public String evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||||
return _langId;
|
return _langId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
@ -19,7 +20,7 @@ public abstract class WbLanguageExpr extends JacksonJsonizable {
|
|||||||
*
|
*
|
||||||
* @param ctxt the evaluation context
|
* @param ctxt the evaluation context
|
||||||
* @return a Wikimedia language code
|
* @return a Wikimedia language code
|
||||||
* @throws SkipStatementException when the code is invalid
|
* @throws SkipSchemaExpressionException when the code is invalid
|
||||||
*/
|
*/
|
||||||
public abstract String evaluate(ExpressionContext ctxt) throws SkipStatementException;
|
public abstract String evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
@ -18,13 +20,13 @@ public class WbLanguageVariable extends WbLanguageExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String evaluate(ExpressionContext ctxt)
|
public String evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
Cell cell = ctxt.getCellByName(getColumnName());
|
Cell cell = ctxt.getCellByName(getColumnName());
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
// TODO some validation here?
|
// TODO some validation here?
|
||||||
return cell.value.toString();
|
return cell.value.toString();
|
||||||
}
|
}
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnName() {
|
public String getColumnName() {
|
||||||
|
@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
|
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
|
||||||
|
|
||||||
@ -48,9 +49,9 @@ public class WbLocationConstant extends WbLocationExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
|
public GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
if (parsed == null)
|
if (parsed == null)
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
|
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
|
||||||
|
|
||||||
public abstract class WbLocationExpr extends WbValueExpr {
|
public abstract class WbLocationExpr extends WbValueExpr {
|
||||||
@Override
|
@Override
|
||||||
public abstract GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
|
public abstract GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException;
|
throws SkipSchemaExpressionException;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
|
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
@ -22,7 +23,7 @@ public class WbLocationVariable extends WbLocationExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
|
public GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
Cell cell = ctxt.getCellByName(getColumnName());
|
Cell cell = ctxt.getCellByName(getColumnName());
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
String expr = cell.value.toString();
|
String expr = cell.value.toString();
|
||||||
@ -31,7 +32,7 @@ public class WbLocationVariable extends WbLocationExpr {
|
|||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnName() {
|
public String getColumnName() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ public class WbMonolingualExpr extends WbValueExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MonolingualTextValue evaluate(ExpressionContext ctxt)
|
public MonolingualTextValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
return Datamodel.makeMonolingualTextValue(
|
return Datamodel.makeMonolingualTextValue(
|
||||||
getValueExpr().evaluate(ctxt).getString(),
|
getValueExpr().evaluate(ctxt).getString(),
|
||||||
getLanguageExpr().evaluate(ctxt));
|
getLanguageExpr().evaluate(ctxt));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ public class WbNameDescExpr extends JacksonJsonizable {
|
|||||||
item.addAlias(val);
|
item.addAlias(val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (SkipStatementException e) {
|
} catch (SkipSchemaExpressionException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
||||||
@ -22,7 +23,7 @@ public class WbReferenceExpr extends JacksonJsonizable {
|
|||||||
this.snakExprs = snakExprs;
|
this.snakExprs = snakExprs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reference evaluate(ExpressionContext ctxt) throws SkipStatementException {
|
public Reference evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||||
List<SnakGroup> snakGroups = new ArrayList<SnakGroup>();
|
List<SnakGroup> snakGroups = new ArrayList<SnakGroup>();
|
||||||
for (WbSnakExpr expr : getSnaks()) {
|
for (WbSnakExpr expr : getSnaks()) {
|
||||||
List<Snak> snakList = new ArrayList<Snak>(1);
|
List<Snak> snakList = new ArrayList<Snak>(1);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||||
@ -23,7 +24,7 @@ public class WbSnakExpr extends JacksonJsonizable {
|
|||||||
this.value = valueExpr;
|
this.value = valueExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Snak evaluate(ExpressionContext ctxt) throws SkipStatementException {
|
public Snak evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
|
||||||
PropertyIdValue propertyId = getProp().evaluate(ctxt);
|
PropertyIdValue propertyId = getProp().evaluate(ctxt);
|
||||||
Value evaluatedValue = value.evaluate(ctxt);
|
Value evaluatedValue = value.evaluate(ctxt);
|
||||||
return Datamodel.makeValueSnak(propertyId, evaluatedValue);
|
return Datamodel.makeValueSnak(propertyId, evaluatedValue);
|
||||||
|
@ -10,6 +10,7 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Claim;
|
import org.wikidata.wdtk.datamodel.interfaces.Claim;
|
||||||
@ -52,7 +53,7 @@ public class WbStatementExpr extends JacksonJsonizable {
|
|||||||
return snakGroups;
|
return snakGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId) throws SkipStatementException {
|
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId) throws SkipSchemaExpressionException {
|
||||||
Value mainSnakValue = getMainsnak().evaluate(ctxt);
|
Value mainSnakValue = getMainsnak().evaluate(ctxt);
|
||||||
Snak mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
|
Snak mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
@ -27,7 +28,7 @@ public class WbStatementGroupExpr extends JacksonJsonizable {
|
|||||||
this.statementExprs = claimExprs;
|
this.statementExprs = claimExprs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatementGroup evaluate(ExpressionContext ctxt, ItemIdValue subject) throws SkipStatementException {
|
public StatementGroup evaluate(ExpressionContext ctxt, ItemIdValue subject) throws SkipSchemaExpressionException {
|
||||||
PropertyIdValue propertyId = propertyExpr.evaluate(ctxt);
|
PropertyIdValue propertyId = propertyExpr.evaluate(ctxt);
|
||||||
List<Statement> statements = new ArrayList<Statement>(statementExprs.size());
|
List<Statement> statements = new ArrayList<Statement>(statementExprs.size());
|
||||||
for(WbStatementExpr expr : statementExprs) {
|
for(WbStatementExpr expr : statementExprs) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
|
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
|
||||||
|
|
||||||
public abstract class WbStringExpr extends WbValueExpr {
|
public abstract class WbStringExpr extends WbValueExpr {
|
||||||
public abstract StringValue evaluate(ExpressionContext ctxt) throws SkipStatementException;
|
public abstract StringValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
|
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
|
||||||
|
|
||||||
@ -21,12 +22,12 @@ public class WbStringVariable extends WbStringExpr {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StringValue evaluate(ExpressionContext ctxt)
|
public StringValue evaluate(ExpressionContext ctxt)
|
||||||
throws SkipStatementException {
|
throws SkipSchemaExpressionException {
|
||||||
Cell cell = ctxt.getCellByName(columnName);
|
Cell cell = ctxt.getCellByName(columnName);
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
return Datamodel.makeStringValue(cell.value.toString());
|
return Datamodel.makeStringValue(cell.value.toString());
|
||||||
}
|
}
|
||||||
throw new SkipStatementException();
|
throw new SkipSchemaExpressionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnName() {
|
public String getColumnName() {
|
||||||
|
@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
@ -36,7 +37,7 @@ public abstract class WbValueExpr extends JacksonJsonizable {
|
|||||||
* Evaluates the value expression in a given context,
|
* Evaluates the value expression in a given context,
|
||||||
* returns a wikibase value suitable to be the target of a claim.
|
* returns a wikibase value suitable to be the target of a claim.
|
||||||
*/
|
*/
|
||||||
public abstract Value evaluate(ExpressionContext ctxt) throws SkipStatementException;
|
public abstract Value evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
|
||||||
|
|
||||||
public static WbValueExpr fromJSON(JSONObject obj) throws JSONException {
|
public static WbValueExpr fromJSON(JSONObject obj) throws JSONException {
|
||||||
return fromJSONClass(obj, WbValueExpr.class);
|
return fromJSONClass(obj, WbValueExpr.class);
|
||||||
|
@ -25,6 +25,7 @@ import com.google.refine.model.OverlayModel;
|
|||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
import com.google.refine.model.Row;
|
import com.google.refine.model.Row;
|
||||||
import org.openrefine.wikidata.schema.WbItemDocumentExpr;
|
import org.openrefine.wikidata.schema.WbItemDocumentExpr;
|
||||||
|
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
|
||||||
import org.openrefine.wikidata.schema.ExpressionContext;
|
import org.openrefine.wikidata.schema.ExpressionContext;
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ public class WikibaseSchema implements OverlayModel {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
result.add(expr.evaluate(ctxt));
|
result.add(expr.evaluate(ctxt));
|
||||||
} catch (SkipStatementException e) {
|
} catch (SkipSchemaExpressionException e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema.exceptions;
|
||||||
|
|
||||||
|
|
||||||
public class InvalidSchemaException extends Exception {
|
public class InvalidSchemaException extends Exception {
|
@ -0,0 +1,6 @@
|
|||||||
|
package org.openrefine.wikidata.schema.exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
public class SkipSchemaExpressionException extends Exception {
|
||||||
|
static final long serialVersionUID = 738592057L;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user