Synchronize schema storage and UI behaviour.
This commit is contained in:
parent
3fd71965fa
commit
decef38f85
@ -171,19 +171,18 @@ SchemaAlignmentDialog.launch = function(onDone) {
|
|||||||
this._hasUnsavedChanges = false;
|
this._hasUnsavedChanges = false;
|
||||||
|
|
||||||
this._createDialog();
|
this._createDialog();
|
||||||
// this._reset(schema, true);
|
this._reset(theProject.overlayModels.wikibaseSchema, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaAlignmentDialog._reset = function(protograph, initial) {
|
SchemaAlignment
|
||||||
this._originalProtograph = protograph || { rootNodes: [] };
|
|
||||||
this._protograph = cloneDeep(this._originalProtograph); // this is what can be munched on
|
|
||||||
|
|
||||||
if (!this._protograph.rootNodes.length) {
|
SchemaAlignmentDialog._reset = function(schema, initial) {
|
||||||
this._protograph.rootNodes.push(SchemaAlignment.createNewRootNode());
|
this._originalSchema = schema || { changes: [] };
|
||||||
}
|
this._schema = cloneDeep(this._originalSchema); // this is what can be munched on
|
||||||
|
|
||||||
$(this._nodeTable).empty();
|
$('#schema-alignment-statements-container').empty();
|
||||||
|
|
||||||
|
/*
|
||||||
this._nodeUIs = [];
|
this._nodeUIs = [];
|
||||||
for (var i = 0; i < this._protograph.rootNodes.length; i++) {
|
for (var i = 0; i < this._protograph.rootNodes.length; i++) {
|
||||||
this._nodeUIs.push(new SchemaAlignmentDialog.UINode(
|
this._nodeUIs.push(new SchemaAlignmentDialog.UINode(
|
||||||
@ -195,9 +194,13 @@ SchemaAlignmentDialog._reset = function(protograph, initial) {
|
|||||||
mustBeCellTopic: true
|
mustBeCellTopic: true
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}*/
|
||||||
|
// TODO
|
||||||
|
|
||||||
this.preview(initial);
|
if (!this._schema.changes.length) {
|
||||||
|
// this._addItem();
|
||||||
|
}
|
||||||
|
// this.preview(initial);
|
||||||
};
|
};
|
||||||
|
|
||||||
SchemaAlignmentDialog._save = function(onDone) {
|
SchemaAlignmentDialog._save = function(onDone) {
|
||||||
@ -312,8 +315,8 @@ SchemaAlignmentDialog._itemToJSON = function (item) {
|
|||||||
lst.push(SchemaAlignmentDialog._statementGroupToJSON($(this)));
|
lst.push(SchemaAlignmentDialog._statementGroupToJSON($(this)));
|
||||||
});
|
});
|
||||||
var inputContainer = item.find(".wbs-item-input").first();
|
var inputContainer = item.find(".wbs-item-input").first();
|
||||||
return {item: SchemaAlignmentDialog._inputContainerToJSON(inputContainer),
|
return {subject: SchemaAlignmentDialog._inputContainerToJSON(inputContainer),
|
||||||
values: lst};
|
statementGroups: lst};
|
||||||
};
|
};
|
||||||
|
|
||||||
SchemaAlignmentDialog._addStatementGroup = function(item) {
|
SchemaAlignmentDialog._addStatementGroup = function(item) {
|
||||||
@ -337,8 +340,8 @@ SchemaAlignmentDialog._statementGroupToJSON = function (statementGroup) {
|
|||||||
lst.push(SchemaAlignmentDialog._statementToJSON($(this)));
|
lst.push(SchemaAlignmentDialog._statementToJSON($(this)));
|
||||||
});
|
});
|
||||||
var inputContainer = statementGroup.find(".wbs-prop-input").first();
|
var inputContainer = statementGroup.find(".wbs-prop-input").first();
|
||||||
return {prop: SchemaAlignmentDialog._inputContainerToJSON(inputContainer),
|
return {property: SchemaAlignmentDialog._inputContainerToJSON(inputContainer),
|
||||||
values: lst};
|
statements: lst};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -360,7 +363,10 @@ SchemaAlignmentDialog._addStatement = function(statementGroup) {
|
|||||||
|
|
||||||
SchemaAlignmentDialog._statementToJSON = function (statement) {
|
SchemaAlignmentDialog._statementToJSON = function (statement) {
|
||||||
var inputContainer = statement.find(".wbs-target-input").first();
|
var inputContainer = statement.find(".wbs-target-input").first();
|
||||||
return SchemaAlignmentDialog._inputContainerToJSON(inputContainer);
|
return {
|
||||||
|
value:SchemaAlignmentDialog._inputContainerToJSON(inputContainer),
|
||||||
|
qualifiers:[],
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
SchemaAlignmentDialog._initField = function(inputContainer, mode) {
|
SchemaAlignmentDialog._initField = function(inputContainer, mode) {
|
||||||
@ -370,19 +376,28 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode) {
|
|||||||
var endpoint = null;
|
var endpoint = null;
|
||||||
if (mode === "item" || mode === "target") {
|
if (mode === "item" || mode === "target") {
|
||||||
endpoint = this._reconService.suggest.entity;
|
endpoint = this._reconService.suggest.entity;
|
||||||
} else if (mode == "property") {
|
} else if (mode === "property") {
|
||||||
endpoint = this._reconService.suggest.property;
|
endpoint = this._reconService.suggest.property;
|
||||||
}
|
}
|
||||||
var suggestConfig = $.extend({}, endpoint);
|
var suggestConfig = $.extend({}, endpoint);
|
||||||
suggestConfig.key = null;
|
suggestConfig.key = null;
|
||||||
suggestConfig.query_param_name = "prefix";
|
suggestConfig.query_param_name = "prefix";
|
||||||
|
|
||||||
|
|
||||||
input.suggestP(suggestConfig).bind("fb-select", function(evt, data) {
|
input.suggestP(suggestConfig).bind("fb-select", function(evt, data) {
|
||||||
|
if (mode === "item") {
|
||||||
inputContainer.data("jsonValue", {
|
inputContainer.data("jsonValue", {
|
||||||
type : "wbitemconstant",
|
type : "wbitemconstant",
|
||||||
id : data.id,
|
qid : data.id,
|
||||||
name: data.name,
|
label: data.name,
|
||||||
});
|
});
|
||||||
|
} else if (mode === "property") {
|
||||||
|
inputContainer.data("jsonValue", {
|
||||||
|
type : "wbpropconstant",
|
||||||
|
pid : data.id,
|
||||||
|
label: data.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +422,7 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode) {
|
|||||||
});
|
});
|
||||||
inputContainer.data("jsonValue", {
|
inputContainer.data("jsonValue", {
|
||||||
type : "wbitemvariable",
|
type : "wbitemvariable",
|
||||||
name: ui.draggable.text(),
|
columnName: ui.draggable.text(),
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}).on("dropactivate", function(evt, ui) {
|
}).on("dropactivate", function(evt, ui) {
|
||||||
@ -448,7 +463,7 @@ SchemaAlignmentDialog.getJSON = function() {
|
|||||||
list.push(SchemaAlignmentDialog._itemToJSON($(this)));
|
list.push(SchemaAlignmentDialog._itemToJSON($(this)));
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
'items': list,
|
'changes': list,
|
||||||
'wikibasePrefix': this._wikibasePrefix,
|
'wikibasePrefix': this._wikibasePrefix,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,7 @@ public class SaveWikibaseSchemaOperation extends AbstractOperation {
|
|||||||
writer.key("op");
|
writer.key("op");
|
||||||
writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description");
|
writer.key("description");
|
||||||
writer.value("Save RDF schema skeleton");
|
writer.value("Save Wikibase schema skeleton");
|
||||||
writer.key("schema");
|
writer.key("schema");
|
||||||
_schema.write(writer, options);
|
_schema.write(writer, options);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
|
@ -10,8 +10,9 @@ import com.google.refine.Jsonizable;
|
|||||||
|
|
||||||
public abstract class BiJsonizable implements Jsonizable {
|
public abstract class BiJsonizable implements Jsonizable {
|
||||||
|
|
||||||
public static String jsonType;
|
// public static String jsonType;
|
||||||
public static final String jsonTypeKey = "@type";
|
public static String jsonType = null;
|
||||||
|
public static final String jsonTypeKey = "type";
|
||||||
|
|
||||||
public abstract void writeFields(JSONWriter writer, Properties options)
|
public abstract void writeFields(JSONWriter writer, Properties options)
|
||||||
throws JSONException;
|
throws JSONException;
|
||||||
@ -20,9 +21,10 @@ public abstract class BiJsonizable implements Jsonizable {
|
|||||||
public void write(JSONWriter writer, Properties options) throws JSONException {
|
public void write(JSONWriter writer, Properties options) throws JSONException {
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key(jsonTypeKey);
|
writer.key(jsonTypeKey);
|
||||||
writer.value(jsonType);
|
writer.value(getJsonType());
|
||||||
writeFields(writer, options);
|
writeFields(writer, options);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract String getJsonType();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ public class WbItemConstant extends WbItemExpr {
|
|||||||
/* Represents an item that does not vary,
|
/* Represents an item that does not vary,
|
||||||
* it is independent of the row. */
|
* it is independent of the row. */
|
||||||
|
|
||||||
|
public static final String jsonType = "wbitemconstant";
|
||||||
|
|
||||||
private String qid;
|
private String qid;
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
@ -39,4 +41,7 @@ public class WbItemConstant extends WbItemExpr {
|
|||||||
return ItemIdValueImpl.create(qid, ctxt.getBaseIRI());
|
return ItemIdValueImpl.create(qid, ctxt.getBaseIRI());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@ public abstract class WbItemExpr extends WbValueExpr {
|
|||||||
return WbItemConstant.fromJSON(obj);
|
return WbItemConstant.fromJSON(obj);
|
||||||
} else if (WbItemVariable.jsonType.equals(type)) {
|
} else if (WbItemVariable.jsonType.equals(type)) {
|
||||||
return WbItemVariable.fromJSON(obj);
|
return WbItemVariable.fromJSON(obj);
|
||||||
|
} else {
|
||||||
|
throw new JSONException("unknown type for WbItemExpr");
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.StatementGroup;
|
||||||
|
|
||||||
|
|
||||||
|
public class WbItemStatementsExpr extends WbChangeExpr {
|
||||||
|
|
||||||
|
public static final String jsonType = "wbitemstatements";
|
||||||
|
|
||||||
|
private WbItemExpr subjectExpr;
|
||||||
|
private List<WbStatementGroupExpr> statementGroupExprs;
|
||||||
|
|
||||||
|
public WbItemStatementsExpr(WbItemExpr subjectExpr, List<WbStatementGroupExpr> statementGroupExprs) {
|
||||||
|
this.subjectExpr = subjectExpr;
|
||||||
|
this.statementGroupExprs = statementGroupExprs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeFields(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
writer.key("subject");
|
||||||
|
subjectExpr.write(writer, options);
|
||||||
|
writer.key("statementGroups");
|
||||||
|
writer.array();
|
||||||
|
for(WbStatementGroupExpr expr : statementGroupExprs) {
|
||||||
|
expr.write(writer, options);
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WbItemStatementsExpr fromJSON(JSONObject obj) throws JSONException {
|
||||||
|
JSONObject subjectObj = obj.getJSONObject("subject");
|
||||||
|
JSONArray statementsArr = obj.getJSONArray("statementGroups");
|
||||||
|
List<WbStatementGroupExpr> statementExprs = new ArrayList<WbStatementGroupExpr>();
|
||||||
|
for (int i = 0; i != statementsArr.length(); i++) {
|
||||||
|
statementExprs.add(WbStatementGroupExpr.fromJSON(statementsArr.getJSONObject(i)));
|
||||||
|
}
|
||||||
|
return new WbItemStatementsExpr(
|
||||||
|
WbItemExpr.fromJSON(subjectObj),
|
||||||
|
statementExprs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<StatementGroup> evaluate(ExpressionContext ctxt) {
|
||||||
|
List<StatementGroup> results = new ArrayList<StatementGroup>(statementGroupExprs.size());
|
||||||
|
ItemIdValue subjectId = subjectExpr.evaluate(ctxt);
|
||||||
|
for(WbStatementGroupExpr expr : statementGroupExprs) {
|
||||||
|
results.add(expr.evaluate(ctxt, subjectId));
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,8 @@ import com.google.refine.model.ReconCandidate;
|
|||||||
public class WbItemVariable extends WbItemExpr {
|
public class WbItemVariable extends WbItemExpr {
|
||||||
/* An item that depends on a reconciled value in a column */
|
/* An item that depends on a reconciled value in a column */
|
||||||
|
|
||||||
|
public static final String jsonType = "wbitemvariable";
|
||||||
|
|
||||||
private String columnName;
|
private String columnName;
|
||||||
|
|
||||||
public WbItemVariable(String columnName) {
|
public WbItemVariable(String columnName) {
|
||||||
@ -41,4 +43,7 @@ public class WbItemVariable extends WbItemExpr {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,11 @@ public class WbPropConstant extends WbPropExpr {
|
|||||||
public static final String jsonType = "wbpropconstant";
|
public static final String jsonType = "wbpropconstant";
|
||||||
|
|
||||||
private String pid;
|
private String pid;
|
||||||
|
private String label;
|
||||||
|
|
||||||
public WbPropConstant(String pid) {
|
public WbPropConstant(String pid, String label) {
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -25,14 +27,20 @@ public class WbPropConstant extends WbPropExpr {
|
|||||||
throws JSONException {
|
throws JSONException {
|
||||||
writer.key("pid");
|
writer.key("pid");
|
||||||
writer.value(pid);
|
writer.value(pid);
|
||||||
|
writer.key("label");
|
||||||
|
writer.value(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WbPropConstant fromJSON(JSONObject obj) throws JSONException {
|
public static WbPropConstant fromJSON(JSONObject obj) throws JSONException {
|
||||||
return new WbPropConstant(obj.getString("pid"));
|
return new WbPropConstant(obj.getString("pid"), obj.getString("label"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PropertyIdValue evaluate(ExpressionContext ctxt) {
|
public PropertyIdValue evaluate(ExpressionContext ctxt) {
|
||||||
return PropertyIdValueImpl.create(pid, ctxt.getBaseIRI());
|
return PropertyIdValueImpl.create(pid, ctxt.getBaseIRI());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||||
|
|
||||||
|
|
||||||
@ -7,4 +9,9 @@ public abstract class WbPropExpr extends WbValueExpr {
|
|||||||
/* An expression that represents a property */
|
/* An expression that represents a property */
|
||||||
|
|
||||||
public abstract PropertyIdValue evaluate(ExpressionContext ctxt);
|
public abstract PropertyIdValue evaluate(ExpressionContext ctxt);
|
||||||
|
|
||||||
|
public static WbPropExpr fromJSON(JSONObject obj) throws JSONException {
|
||||||
|
return WbPropConstant.fromJSON(obj);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,17 +38,7 @@ public class WbSnakExpr implements Jsonizable {
|
|||||||
JSONObject propObj = obj.getJSONObject("prop");
|
JSONObject propObj = obj.getJSONObject("prop");
|
||||||
WbPropExpr propExpr = WbPropConstant.fromJSON(propObj);
|
WbPropExpr propExpr = WbPropConstant.fromJSON(propObj);
|
||||||
JSONObject valueObj = obj.getJSONObject("value");
|
JSONObject valueObj = obj.getJSONObject("value");
|
||||||
String type = valueObj.getString(WbValueExpr.jsonTypeKey);
|
WbValueExpr valueExpr = WbValueExpr.fromJSON(valueObj);
|
||||||
WbValueExpr valueExpr = null;
|
|
||||||
if (WbPropConstant.jsonType.equals(type)) {
|
|
||||||
valueExpr = WbPropConstant.fromJSON(valueObj);
|
|
||||||
} else if (WbItemConstant.jsonType.equals(type)) {
|
|
||||||
valueExpr = WbItemConstant.fromJSON(valueObj);
|
|
||||||
} else if (WbItemVariable.jsonType.equals(type)) {
|
|
||||||
valueExpr = WbItemVariable.fromJSON(valueObj);
|
|
||||||
} else if (WbStringConstant.jsonType.equals(type)) {
|
|
||||||
valueExpr = WbStringConstant.fromJSON(valueObj);
|
|
||||||
}
|
|
||||||
return new WbSnakExpr(propExpr, valueExpr);
|
return new WbSnakExpr(propExpr, valueExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,35 +13,34 @@ import org.json.JSONWriter;
|
|||||||
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;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
|
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.StatementRank;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||||
|
|
||||||
|
|
||||||
public class WbClaimExpr extends WbChangeExpr {
|
public class WbStatementExpr extends BiJsonizable {
|
||||||
|
|
||||||
public static String jsonType = "wbclaimexpr";
|
public static final String jsonType = "wbstatementexpr";
|
||||||
|
|
||||||
private WbItemExpr subjectExpr;
|
private WbValueExpr mainSnakValueExpr;
|
||||||
private WbSnakExpr mainSnakExpr;
|
|
||||||
private List<WbSnakExpr> qualifierExprs;
|
private List<WbSnakExpr> qualifierExprs;
|
||||||
// TODO: references
|
// TODO: references
|
||||||
|
|
||||||
public WbClaimExpr(WbItemExpr subjectExpr,
|
public WbStatementExpr(WbValueExpr mainSnakValueExpr,
|
||||||
WbSnakExpr mainSnakExpr,
|
|
||||||
List<WbSnakExpr> qualifierExprs) {
|
List<WbSnakExpr> qualifierExprs) {
|
||||||
this.subjectExpr = subjectExpr;
|
this.mainSnakValueExpr = mainSnakValueExpr;
|
||||||
this.mainSnakExpr = mainSnakExpr;
|
|
||||||
this.qualifierExprs = qualifierExprs;
|
this.qualifierExprs = qualifierExprs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeFields(JSONWriter writer, Properties options)
|
public void writeFields(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
writer.key("subject");
|
writer.key("value");
|
||||||
subjectExpr.write(writer, options);
|
mainSnakValueExpr.write(writer, options);
|
||||||
writer.key("mainsnak");
|
|
||||||
mainSnakExpr.write(writer, options);
|
|
||||||
writer.key("qualifiers");
|
writer.key("qualifiers");
|
||||||
writer.array();
|
writer.array();
|
||||||
for (WbSnakExpr expr : qualifierExprs) {
|
for (WbSnakExpr expr : qualifierExprs) {
|
||||||
@ -50,17 +49,15 @@ public class WbClaimExpr extends WbChangeExpr {
|
|||||||
writer.endArray();
|
writer.endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WbClaimExpr fromJSON(JSONObject obj) throws JSONException {
|
public static WbStatementExpr fromJSON(JSONObject obj) throws JSONException {
|
||||||
JSONObject subjObj = obj.getJSONObject("subject");
|
JSONObject mainSnakObj = obj.getJSONObject("value");
|
||||||
JSONObject mainSnakObj = obj.getJSONObject("mainsnak");
|
|
||||||
JSONArray qualifiersArr = obj.getJSONArray("qualifiers");
|
JSONArray qualifiersArr = obj.getJSONArray("qualifiers");
|
||||||
List<WbSnakExpr> qualifierExprs = new ArrayList<WbSnakExpr>();
|
List<WbSnakExpr> qualifierExprs = new ArrayList<WbSnakExpr>();
|
||||||
for (int i = 0; i != qualifiersArr.length(); i++) {
|
for (int i = 0; i != qualifiersArr.length(); i++) {
|
||||||
qualifierExprs.add(WbSnakExpr.fromJSON(qualifiersArr.getJSONObject(i)));
|
qualifierExprs.add(WbSnakExpr.fromJSON(qualifiersArr.getJSONObject(i)));
|
||||||
}
|
}
|
||||||
return new WbClaimExpr(
|
return new WbStatementExpr(
|
||||||
WbItemExpr.fromJSON(subjObj),
|
WbValueExpr.fromJSON(mainSnakObj),
|
||||||
WbSnakExpr.fromJSON(mainSnakObj),
|
|
||||||
qualifierExprs);
|
qualifierExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,12 +77,18 @@ public class WbClaimExpr extends WbChangeExpr {
|
|||||||
return snakGroups;
|
return snakGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Claim evaluate(ExpressionContext ctxt) {
|
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId) {
|
||||||
ItemIdValue subject = subjectExpr.evaluate(ctxt);
|
Value mainSnakValue = mainSnakValueExpr.evaluate(ctxt);
|
||||||
Snak mainSnak = mainSnakExpr.evaluate(ctxt);
|
Snak mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
|
||||||
List<Snak> qualifiers = new ArrayList<Snak>(qualifierExprs.size());
|
List<Snak> qualifiers = new ArrayList<Snak>(qualifierExprs.size());
|
||||||
List<SnakGroup> groupedQualifiers = groupSnaks(qualifiers);
|
List<SnakGroup> groupedQualifiers = groupSnaks(qualifiers);
|
||||||
return Datamodel.makeClaim(subject, mainSnak, groupedQualifiers);
|
Claim claim = Datamodel.makeClaim(subject, mainSnak, groupedQualifiers);
|
||||||
|
List<Reference> references = new ArrayList<Reference>();
|
||||||
|
StatementRank rank = StatementRank.NORMAL;
|
||||||
|
return Datamodel.makeStatement(claim, references, rank, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Claim;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.StatementGroup;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||||
|
|
||||||
|
|
||||||
|
public class WbStatementGroupExpr extends BiJsonizable {
|
||||||
|
public static final String jsonType = "wbstatementgroupexpr";
|
||||||
|
|
||||||
|
private WbPropExpr propertyExpr;
|
||||||
|
private List<WbStatementExpr> claimExprs;
|
||||||
|
|
||||||
|
public WbStatementGroupExpr(WbPropExpr propertyExpr, List<WbStatementExpr> claimExprs) {
|
||||||
|
this.propertyExpr = propertyExpr;
|
||||||
|
this.claimExprs = claimExprs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeFields(JSONWriter writer, Properties options)
|
||||||
|
throws JSONException {
|
||||||
|
|
||||||
|
writer.key("property");
|
||||||
|
propertyExpr.write(writer, options);
|
||||||
|
writer.key("statements");
|
||||||
|
writer.array();
|
||||||
|
for(WbStatementExpr expr : claimExprs) {
|
||||||
|
expr.write(writer, options);
|
||||||
|
}
|
||||||
|
writer.endArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WbStatementGroupExpr fromJSON(JSONObject obj) throws JSONException {
|
||||||
|
JSONObject propertyObj = obj.getJSONObject("property");
|
||||||
|
JSONArray claimsArr = obj.getJSONArray("statements");
|
||||||
|
List<WbStatementExpr> claimExprs = new ArrayList<WbStatementExpr>();
|
||||||
|
for (int i = 0; i != claimsArr.length(); i++) {
|
||||||
|
claimExprs.add(WbStatementExpr.fromJSON(claimsArr.getJSONObject(i)));
|
||||||
|
}
|
||||||
|
return new WbStatementGroupExpr(
|
||||||
|
WbPropExpr.fromJSON(propertyObj),
|
||||||
|
claimExprs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatementGroup evaluate(ExpressionContext ctxt, ItemIdValue subject) {
|
||||||
|
PropertyIdValue propertyId = propertyExpr.evaluate(ctxt);
|
||||||
|
List<Statement> statements = new ArrayList<Statement>(claimExprs.size());
|
||||||
|
for(WbStatementExpr expr : claimExprs) {
|
||||||
|
statements.add(expr.evaluate(ctxt, subject, propertyId));
|
||||||
|
}
|
||||||
|
// List<SnakGroup> groupedQualifiers = groupSnaks(qualifiers);
|
||||||
|
return Datamodel.makeStatementGroup(statements);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
|
}
|
@ -35,4 +35,7 @@ public class WbStringConstant extends WbValueExpr {
|
|||||||
return Datamodel.makeStringValue(value);
|
return Datamodel.makeStringValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getJsonType() {
|
||||||
|
return jsonType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.openrefine.wikidata.schema;
|
package org.openrefine.wikidata.schema;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
import org.wikidata.wdtk.datamodel.interfaces.Value;
|
||||||
|
|
||||||
|
|
||||||
@ -15,4 +17,21 @@ public abstract class WbValueExpr extends BiJsonizable {
|
|||||||
* 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);
|
public abstract Value evaluate(ExpressionContext ctxt);
|
||||||
|
|
||||||
|
public static WbValueExpr fromJSON(JSONObject obj) throws JSONException {
|
||||||
|
String type = obj.getString(WbValueExpr.jsonTypeKey);
|
||||||
|
WbValueExpr valueExpr = null;
|
||||||
|
if (WbPropConstant.jsonType.equals(type)) {
|
||||||
|
valueExpr = WbPropConstant.fromJSON(obj);
|
||||||
|
} else if (WbItemConstant.jsonType.equals(type)) {
|
||||||
|
valueExpr = WbItemConstant.fromJSON(obj);
|
||||||
|
} else if (WbItemVariable.jsonType.equals(type)) {
|
||||||
|
valueExpr = WbItemVariable.fromJSON(obj);
|
||||||
|
} else if (WbStringConstant.jsonType.equals(type)) {
|
||||||
|
valueExpr = WbStringConstant.fromJSON(obj);
|
||||||
|
} else {
|
||||||
|
throw new JSONException("unknown type for WbValueExpr");
|
||||||
|
}
|
||||||
|
return valueExpr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/*
|
|
||||||
import org.deri.grefine.rdf.ResourceNode.RdfType;
|
|
||||||
import org.deri.grefine.rdf.app.ApplicationContext;
|
|
||||||
import org.deri.grefine.rdf.vocab.PrefixExistException;
|
|
||||||
import org.deri.grefine.rdf.vocab.Vocabulary;
|
|
||||||
import org.deri.grefine.rdf.vocab.VocabularyIndexException; */
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -62,7 +56,7 @@ public class WikibaseSchema implements OverlayModel {
|
|||||||
JSONArray changeArr = o.getJSONArray("changes");
|
JSONArray changeArr = o.getJSONArray("changes");
|
||||||
WikibaseSchema schema = new WikibaseSchema();
|
WikibaseSchema schema = new WikibaseSchema();
|
||||||
for (int i = 0; i != changeArr.length(); i++) {
|
for (int i = 0; i != changeArr.length(); i++) {
|
||||||
WbChangeExpr changeExpr = WbClaimExpr.fromJSON(changeArr.getJSONObject(i));
|
WbChangeExpr changeExpr = WbItemStatementsExpr.fromJSON(changeArr.getJSONObject(i));
|
||||||
schema.changeExprs.add(changeExpr);
|
schema.changeExprs.add(changeExpr);
|
||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
@ -71,11 +65,14 @@ public class WikibaseSchema implements OverlayModel {
|
|||||||
@Override
|
@Override
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
writer.object();
|
||||||
|
writer.key("changes");
|
||||||
writer.array();
|
writer.array();
|
||||||
for (WbChangeExpr changeExpr : changeExprs) {
|
for (WbChangeExpr changeExpr : changeExprs) {
|
||||||
changeExpr.write(writer, options);
|
changeExpr.write(writer, options);
|
||||||
}
|
}
|
||||||
writer.endArray();
|
writer.endArray();
|
||||||
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public WikibaseSchema load(Project project, JSONObject obj) throws Exception {
|
static public WikibaseSchema load(Project project, JSONObject obj) throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user