Add support for Wikidata single best value constraint

This commit is contained in:
Antonin Delpeuch 2018-06-10 08:14:24 +01:00
parent ddbe4fe2a2
commit e2ae09f5be
4 changed files with 20 additions and 1 deletions

View File

@ -105,6 +105,11 @@ public interface ConstraintFetcher {
*/
boolean hasSingleValue(PropertyIdValue pid);
/**
* Is this property expected to have a single best value only?
*/
boolean hasSingleBestValue(PropertyIdValue pid);
/**
* Is this property expected to have distinct values?
*/

View File

@ -79,6 +79,7 @@ public class WikidataConstraintFetcher implements ConstraintFetcher {
public static String DISALLOWED_VALUES_CONSTRAINT_PID = "P2305";
public static String SINGLE_VALUE_CONSTRAINT_QID = "Q19474404";
public static String SINGLE_BEST_VALUE_CONSTRAINT_QID = "Q52060874";
public static String DISTINCT_VALUES_CONSTRAINT_QID = "Q21502410";
public static String NO_BOUNDS_CONSTRAINT_QID = "Q51723761";
@ -165,6 +166,11 @@ public class WikidataConstraintFetcher implements ConstraintFetcher {
return getSingleConstraint(pid, SINGLE_VALUE_CONSTRAINT_QID) != null;
}
@Override
public boolean hasSingleBestValue(PropertyIdValue pid) {
return getSingleConstraint(pid, SINGLE_BEST_VALUE_CONSTRAINT_QID) != null;
}
@Override
public boolean hasDistinctValues(PropertyIdValue pid) {
return getSingleConstraint(pid, DISTINCT_VALUES_CONSTRAINT_QID) != null;

View File

@ -35,6 +35,9 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement;
* For now this scrutinizer only checks for uniqueness at the item level (it
* ignores qualifiers and references).
*
* Given that all ranks are currently set to Normal, this also checks for
* single best values.
*
* @author Antonin Delpeuch
*
*/
@ -54,7 +57,7 @@ public class SingleValueScrutinizer extends EditScrutinizer {
issue.setProperty("property_entity", pid);
issue.setProperty("example_entity", update.getItemId());
addIssue(issue);
} else if (_fetcher.hasSingleValue(pid)) {
} else if (_fetcher.hasSingleValue(pid) || _fetcher.hasSingleBestValue(pid)) {
seenSingleProperties.add(pid);
}
}

View File

@ -104,6 +104,11 @@ public class MockConstraintFetcher implements ConstraintFetcher {
return true;
}
@Override
public boolean hasSingleBestValue(PropertyIdValue pid) {
return false;
}
@Override
public boolean hasDistinctValues(PropertyIdValue pid) {
return true;