use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class SnakUtils method groupSnaks.
/**
* Groups snaks into a list of snak groups.
* The order of the first snaks in each group is preserved.
*
* @param snaks
* @return
*/
public static List<SnakGroup> groupSnaks(List<Snak> snaks) {
Map<PropertyIdValue, List<Snak>> snakGroups = new HashMap<>();
List<PropertyIdValue> propertyOrder = new ArrayList<PropertyIdValue>();
for (Snak snak : snaks) {
List<Snak> existingSnaks = snakGroups.get(snak.getPropertyId());
if (existingSnaks == null) {
existingSnaks = new ArrayList<Snak>();
snakGroups.put(snak.getPropertyId(), existingSnaks);
propertyOrder.add(snak.getPropertyId());
}
if (!existingSnaks.contains(snak)) {
existingSnaks.add(snak);
}
}
return propertyOrder.stream().map(pid -> Datamodel.makeSnakGroup(snakGroups.get(pid))).collect(Collectors.toList());
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class SchemaPropertyExtractorTest method makePropertySet.
public Set<PropertyIdValue> makePropertySet(String... pids) {
Set<PropertyIdValue> propertyIdValues = new HashSet<>();
for (String pid : pids) {
PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue(pid);
propertyIdValues.add(propertyIdValue);
}
return propertyIdValues;
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class WbStatementExpr method groupSnaks.
public static List<SnakGroup> groupSnaks(List<Snak> snaks) {
Map<PropertyIdValue, List<Snak>> snakGroups = new HashMap<>();
List<PropertyIdValue> propertyOrder = new ArrayList<PropertyIdValue>();
for (Snak snak : snaks) {
List<Snak> existingSnaks = snakGroups.get(snak.getPropertyId());
if (existingSnaks == null) {
existingSnaks = new ArrayList<Snak>();
snakGroups.put(snak.getPropertyId(), existingSnaks);
propertyOrder.add(snak.getPropertyId());
}
if (!existingSnaks.contains(snak)) {
existingSnaks.add(snak);
}
}
return propertyOrder.stream().map(pid -> Datamodel.makeSnakGroup(snakGroups.get(pid))).collect(Collectors.toList());
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class ConflictsWithScrutinizer method scrutinize.
@Override
public void scrutinize(TermedStatementEntityEdit update) {
Map<PropertyIdValue, Set<Value>> propertyIdValueValueMap = new HashMap<>();
for (Statement statement : update.getAddedStatements()) {
PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
Value value = null;
Snak mainSnak = statement.getClaim().getMainSnak();
if (mainSnak instanceof ValueSnak) {
value = ((ValueSnak) mainSnak).getValue();
}
Set<Value> values;
if (value != null) {
if (propertyIdValueValueMap.containsKey(pid)) {
values = propertyIdValueValueMap.get(pid);
} else {
values = new HashSet<>();
}
values.add(value);
propertyIdValueValueMap.put(pid, values);
}
}
for (PropertyIdValue propertyId : propertyIdValueValueMap.keySet()) {
List<Statement> statementList = _fetcher.getConstraintsByType(propertyId, conflictsWithConstraintQid);
for (Statement statement : statementList) {
ConflictsWithConstraint constraint = new ConflictsWithConstraint(statement);
PropertyIdValue conflictingPid = constraint.conflictingPid;
List<Value> itemList = constraint.itemList;
if (propertyIdValueValueMap.containsKey(conflictingPid) && raiseWarning(propertyIdValueValueMap, conflictingPid, itemList)) {
QAWarning issue = new QAWarning(type, propertyId.getId() + conflictingPid.getId(), QAWarning.Severity.WARNING, 1);
issue.setProperty("property_entity", propertyId);
issue.setProperty("added_property_entity", conflictingPid);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
}
}
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class EntityTypeScrutinizer method scrutinize.
@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
if (!added) {
return;
}
PropertyIdValue pid = snak.getPropertyId();
List<Statement> statementList = _fetcher.getConstraintsByType(pid, allowedEntityTypesQid);
if (!statementList.isEmpty()) {
List<SnakGroup> constraint = statementList.get(0).getClaim().getQualifiers();
boolean isUsable = true;
if (constraint != null) {
isUsable = findValues(constraint, itemOfPropertyConstraint).contains(Datamodel.makeWikidataItemIdValue(wikibaseItemQid));
}
if (!isUsable) {
QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_entity", entityId);
addIssue(issue);
}
}
}
Aggregations