Add properties to format scrutinizer
This commit is contained in:
parent
abc51235c6
commit
63d488d74f
@ -13,6 +13,9 @@
|
||||
"save-button": "Save",
|
||||
"close-button": "Close"
|
||||
},
|
||||
"wikidata-preview": {
|
||||
"new-id": "new item"
|
||||
},
|
||||
"warnings-messages": {
|
||||
"new-item-created": {
|
||||
"title": "This batch will create new Wikidata items.",
|
||||
@ -35,8 +38,8 @@
|
||||
"body": "You should provide an \"instance of\" (P31) or \"subclass of\" (P279) statement for each item that you create."
|
||||
},
|
||||
"add-statements-with-invalid-format": {
|
||||
"title": "Text statements with invalid format.",
|
||||
"body": "Please consult the documentation of the properties to find out the correct format for their values."
|
||||
"title": "{property_entity} statements with invalid format.",
|
||||
"body": "Values for this property are expected to match the regular expression <span class=\"wb-issue-preformat\">{regex}</span>, which is not the case for <span class=\"wb-issue-preformat\">{example_value}</span> added on {example_item_entity}."
|
||||
},
|
||||
"remove-statements-with-invalid-format": {
|
||||
"title": "Removed statements with invalid format.",
|
||||
|
@ -862,13 +862,50 @@ SchemaAlignmentDialog.preview = function(initial) {
|
||||
* WARNINGS RENDERING *
|
||||
*************************/
|
||||
|
||||
// renders a Wikibase entity into a link
|
||||
SchemaAlignmentDialog._renderEntity = function(entity) {
|
||||
var id = entity.id;
|
||||
var is_new = id == "Q0";
|
||||
if (is_new) {
|
||||
id = $.i18n._('wikidata-preview')['new-id'];
|
||||
}
|
||||
var fullLabel = id;
|
||||
if (entity.label) {
|
||||
fullLabel = entity.label + ' (' + id + ')';
|
||||
}
|
||||
|
||||
if (is_new) {
|
||||
return '<span class="wb-preview-new-entity">'+fullLabel+'</span>';
|
||||
} else {
|
||||
return '<a href="'+entity.iri+'" class="wb-preview-entity" target="_blank">'+fullLabel+'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
// replaces the issue properties in localization template
|
||||
SchemaAlignmentDialog._replaceIssueProperties = function(template, properties) {
|
||||
if (!properties) {
|
||||
return template;
|
||||
}
|
||||
var expanded = template;
|
||||
for (var key in properties) {
|
||||
if (properties.hasOwnProperty(key)) {
|
||||
var rendered = properties[key];
|
||||
if (key.endsWith('_entity')) {
|
||||
rendered = SchemaAlignmentDialog._renderEntity(properties[key]);
|
||||
}
|
||||
expanded = expanded.replace('{'+key+'}', rendered);
|
||||
}
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
|
||||
SchemaAlignmentDialog._renderWarning = function(warning) {
|
||||
var localized = $.i18n._('warnings-messages')[warning.type];
|
||||
var title = warning.type;
|
||||
var body = "";
|
||||
if (localized) {
|
||||
title = localized.title;
|
||||
body = localized.body;
|
||||
title = SchemaAlignmentDialog._replaceIssueProperties(localized.title, warning.properties);
|
||||
body = SchemaAlignmentDialog._replaceIssueProperties(localized.body, warning.properties);
|
||||
}
|
||||
var tr = $('<tr></tr>').addClass('wb-warning');
|
||||
var severityTd = $('<td></td>')
|
||||
@ -879,10 +916,10 @@ SchemaAlignmentDialog._renderWarning = function(warning) {
|
||||
.addClass('wb-warning-body')
|
||||
.appendTo(tr);
|
||||
var h1 = $('<h1></h1>')
|
||||
.text(title)
|
||||
.html(title)
|
||||
.appendTo(bodyTd);
|
||||
var p = $('<p></p>')
|
||||
.text(body)
|
||||
.html(body)
|
||||
.appendTo(bodyTd);
|
||||
var countTd = $('<td></td>')
|
||||
.addClass('wb-warning-count')
|
||||
|
@ -282,6 +282,18 @@ div.schema-alignment-dialog-warnings {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.wb-issue-preformat {
|
||||
border: 1px solid #eaecf0;
|
||||
background-color: #f8f9fa;
|
||||
padding: 1px 3px;
|
||||
border-radius: 2px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.wb-preview-new-entity {
|
||||
color: #11c;
|
||||
}
|
||||
|
||||
/*** QuickStatements Preview ***/
|
||||
|
||||
div.schema-alignment-dialog-preview {
|
||||
|
@ -2,8 +2,10 @@ package org.openrefine.wikidata.qa.scrutinizers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.openrefine.wikidata.qa.QAWarning;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
||||
@ -53,7 +55,16 @@ public class FormatConstraintScrutinizer extends SnakScrutinizer {
|
||||
Pattern pattern = getPattern(pid);
|
||||
if (!pattern.matcher(value).matches()) {
|
||||
if (added) {
|
||||
important("add-statements-with-invalid-format");
|
||||
QAWarning issue = new QAWarning(
|
||||
"add-statements-with-invalid-format",
|
||||
pid.getId(),
|
||||
QAWarning.Severity.IMPORTANT,
|
||||
1);
|
||||
issue.setProperty("property_entity", pid);
|
||||
issue.setProperty("regex", pattern.toString());
|
||||
issue.setProperty("example_value", value);
|
||||
issue.setProperty("example_item_entity", entityId);
|
||||
addIssue(issue);
|
||||
} else {
|
||||
info("remove-statements-with-invalid-format");
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.openrefine.wikidata.schema;
|
||||
|
||||
import org.openrefine.wikidata.schema.entityvalues.TermedItemIdValue;
|
||||
import org.wikidata.wdtk.datamodel.implementation.ItemIdValueImpl;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
||||
|
||||
@ -24,7 +25,10 @@ public class WbItemConstant extends WbItemExpr {
|
||||
|
||||
@Override
|
||||
public ItemIdValue evaluate(ExpressionContext ctxt) {
|
||||
return ItemIdValueImpl.create(qid, ctxt.getBaseIRI());
|
||||
return new TermedItemIdValue(
|
||||
qid,
|
||||
ctxt.getBaseIRI(),
|
||||
label);
|
||||
}
|
||||
|
||||
public String getQid() {
|
||||
|
Loading…
Reference in New Issue
Block a user