Add issue details on inverses and qualifier checks

This commit is contained in:
Antonin Delpeuch 2018-01-10 16:16:05 +00:00
parent e920c0f421
commit 45bc328675
5 changed files with 50 additions and 17 deletions

View File

@ -46,8 +46,8 @@
"body": "If these statements currently exist on Wikidata, this will solve constraint violations." "body": "If these statements currently exist on Wikidata, this will solve constraint violations."
}, },
"missing-inverse-statements": { "missing-inverse-statements": {
"title": "Missing inverse statements.", "title": "Inverse statements missing for {added_property_entity}.",
"body": "Some of the properties that you are using require inverse statements. You should add them in your schema." "body": "Any {added_property_entity} statement such as the one from {source_entity} to {target_entity} should also be added in reverse with {inverse_property_entity}: in this case, {target_entity} {inverse_property_entity} {source_entity}."
}, },
"self-referential-statements": { "self-referential-statements": {
"title": "Self-referential statements.", "title": "Self-referential statements.",
@ -82,12 +82,12 @@
"body": "You are using in a reference a property that was designed to be used as a statement only." "body": "You are using in a reference a property that was designed to be used as a statement only."
}, },
"missing-mandatory-qualifiers": { "missing-mandatory-qualifiers": {
"title": "Missing mandatory qualifiers.", "title": "{statement_property_entity} is missing a {missing_property_entity} qualifier.",
"body": "Your statements are missing qualifiers, it would be good to add them." "body": "Statements using {statement_property_entity} such as the one on {example_item_entity} are missing a mandatory {missing_property_entity} qualifier."
}, },
"disallowed-qualifiers": { "disallowed-qualifiers": {
"title": "Disallowed qualifiers.", "title": "Qualifier {disallowed_property_entity} is incompatible with {statement_property_entity}.",
"body": "Some of your qualifiers are incompatible with the statements that they qualify. Please check your schema." "body": "Statements using {statement_property_entity} such as the one on {example_item_entity} should not have a {disallowed_property_entity} qualifier as they are incompatible."
}, },
"single-valued-property-added-more-than-once": { "single-valued-property-added-more-than-once": {
"title": "Single valued property added more than once.", "title": "Single valued property added more than once.",

View File

@ -702,7 +702,6 @@ SchemaAlignmentDialog._initField = function(inputContainer, mode, initialValue,
} }
var propagateValue = function() { var propagateValue = function() {
console.log('propagateValue in monolingualtext')
inputContainer.data("jsonValue", { inputContainer.data("jsonValue", {
type: "wbmonolingualexpr", type: "wbmonolingualexpr",
language: inputContainerLanguage.data("jsonValue"), language: inputContainerLanguage.data("jsonValue"),
@ -848,7 +847,11 @@ SchemaAlignmentDialog.preview = function(initial) {
$(self._previewPanes[0]).text(data.quickstatements); $(self._previewPanes[0]).text(data.quickstatements);
} }
if (data.warnings) {
self._updateWarnings(data.warnings); self._updateWarnings(data.warnings);
} else {
self._updateWarnings([]);
}
if ("code" in data && data.code === "error") { if ("code" in data && data.code === "error") {
$('.invalid-schema-warning').show(); $('.invalid-schema-warning').show();
@ -864,6 +867,9 @@ SchemaAlignmentDialog.preview = function(initial) {
// renders a Wikibase entity into a link // renders a Wikibase entity into a link
SchemaAlignmentDialog._renderEntity = function(entity) { SchemaAlignmentDialog._renderEntity = function(entity) {
if (!entity.id && entity.value) {
entity.id = entity.value.id;
}
var id = entity.id; var id = entity.id;
var is_new = id == "Q0"; var is_new = id == "Q0";
if (is_new) { if (is_new) {
@ -893,7 +899,7 @@ SchemaAlignmentDialog._replaceIssueProperties = function(template, properties) {
if (key.endsWith('_entity')) { if (key.endsWith('_entity')) {
rendered = SchemaAlignmentDialog._renderEntity(properties[key]); rendered = SchemaAlignmentDialog._renderEntity(properties[key]);
} }
expanded = expanded.replace('{'+key+'}', rendered); expanded = expanded.replace(new RegExp('{'+key+'}', 'g'), rendered);
} }
} }
return expanded; return expanded;

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.openrefine.wikidata.qa.QAWarning;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
@ -74,13 +75,23 @@ public class InverseConstraintScrutinizer extends StatementScrutinizer {
// For each pair of inverse properties (in each direction) // For each pair of inverse properties (in each direction)
for(Entry<PropertyIdValue,PropertyIdValue> propertyPair : _inverse.entrySet()) { for(Entry<PropertyIdValue,PropertyIdValue> propertyPair : _inverse.entrySet()) {
// Get the statements made for the first // Get the statements made for the first
for(Entry<EntityIdValue, Set<EntityIdValue>> itemLinks : _statements.get(propertyPair.getKey()).entrySet()) { PropertyIdValue ourProperty = propertyPair.getKey();
for(Entry<EntityIdValue, Set<EntityIdValue>> itemLinks : _statements.get(ourProperty).entrySet()) {
// For each outgoing link // For each outgoing link
for(EntityIdValue idValue : itemLinks.getValue()) { for(EntityIdValue idValue : itemLinks.getValue()) {
// Check that they are in the statements made for the second // Check that they are in the statements made for the second
Set<EntityIdValue> reciprocalLinks = _statements.get(propertyPair.getValue()).get(idValue); PropertyIdValue missingProperty = propertyPair.getValue();
Set<EntityIdValue> reciprocalLinks = _statements.get(missingProperty).get(idValue);
if (reciprocalLinks == null || !reciprocalLinks.contains(itemLinks.getKey())) { if (reciprocalLinks == null || !reciprocalLinks.contains(itemLinks.getKey())) {
important("missing-inverse-statements"); QAWarning issue = new QAWarning("missing-inverse-statements",
ourProperty.getId(),
QAWarning.Severity.IMPORTANT,
1);
issue.setProperty("added_property_entity", ourProperty);
issue.setProperty("inverse_property_entity", missingProperty);
issue.setProperty("source_entity", idValue);
issue.setProperty("target_entity", itemLinks.getKey());
addIssue(issue);
} }
} }
} }

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.openrefine.wikidata.qa.QAWarning;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
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.Statement;
@ -62,11 +63,27 @@ public class QualifierCompatibilityScrutinizer extends StatementScrutinizer {
Set<PropertyIdValue> disallowedQualifiers = qualifiers Set<PropertyIdValue> disallowedQualifiers = qualifiers
.stream().filter(p -> !qualifierIsAllowed(statementProperty, p)).collect(Collectors.toSet()); .stream().filter(p -> !qualifierIsAllowed(statementProperty, p)).collect(Collectors.toSet());
if( !missingQualifiers.isEmpty()) { for (PropertyIdValue missing : missingQualifiers) {
warning("missing-mandatory-qualifiers"); QAWarning issue = new QAWarning(
"missing-mandatory-qualifiers",
statementProperty.getId()+"-"+missing.getId(),
QAWarning.Severity.WARNING,
1);
issue.setProperty("statement_property_entity", statementProperty);
issue.setProperty("missing_property_entity", missing);
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
} }
if (!disallowedQualifiers.isEmpty()) { for (PropertyIdValue disallowed : disallowedQualifiers) {
warning("disallowed-qualifiers"); QAWarning issue = new QAWarning(
"disallowed-qualifiers",
statementProperty.getId()+"-"+disallowed.getId(),
QAWarning.Severity.WARNING,
1);
issue.setProperty("statement_property_entity", statementProperty);
issue.setProperty("disallowed_property_entity", disallowed);
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
} }
} }

View File

@ -23,7 +23,6 @@ public class EntityCache {
ApiConnection connection = ApiConnection.getWikidataApiConnection(); ApiConnection connection = ApiConnection.getWikidataApiConnection();
_fetcher = new WikibaseDataFetcher(connection, Datamodel.SITE_WIKIDATA); _fetcher = new WikibaseDataFetcher(connection, Datamodel.SITE_WIKIDATA);
System.out.println("Creating fresh cache");
_cache = CacheBuilder.newBuilder() _cache = CacheBuilder.newBuilder()
.maximumSize(4096) .maximumSize(4096)
.expireAfterWrite(1, TimeUnit.HOURS) .expireAfterWrite(1, TimeUnit.HOURS)