use of org.wikidata.wdtk.datamodel.interfaces.EntityIdValue in project OpenRefine by OpenRefine.
the class ReconEntityRewriter method rewrite.
/**
* Rewrite an edit, replacing references to all entities already
* created by their fresh identifiers. The subject id might not have been
* created already, in which case it will be left untouched. All the other
* entities need to have been created already.
*
* @param edit
* the edit to rewrite
* @return
* the rewritten update
* @throws NewEntityNotCreatedYetException
* if any non-subject entity had not been created yet
*/
public TermedStatementEntityEdit rewrite(TermedStatementEntityEdit edit) throws NewEntityNotCreatedYetException {
try {
EntityIdValue subject = (EntityIdValue) copyValue(edit.getEntityId());
Set<MonolingualTextValue> labels = edit.getLabels().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> labelsIfNew = edit.getLabelsIfNew().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> descriptions = edit.getDescriptions().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> descriptionsIfNew = edit.getDescriptionsIfNew().stream().map(l -> copy(l)).collect(Collectors.toSet());
Set<MonolingualTextValue> aliases = edit.getAliases().stream().map(l -> copy(l)).collect(Collectors.toSet());
List<StatementEdit> addedStatements = edit.getStatementEdits().stream().map(l -> copy(l)).collect(Collectors.toList());
return new TermedStatementEntityEdit(subject, addedStatements, labels, labelsIfNew, descriptions, descriptionsIfNew, aliases);
} catch (MissingEntityIdFound e) {
throw new NewEntityNotCreatedYetException(e.value);
}
}
use of org.wikidata.wdtk.datamodel.interfaces.EntityIdValue in project OpenRefine by OpenRefine.
the class RestrictedValuesScrutinizer method scrutinize.
@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
if (!added) {
return;
}
PropertyIdValue pid = snak.getPropertyId();
Value value = null;
if (snak instanceof ValueSnak) {
value = ((ValueSnak) snak).getValue();
}
List<Statement> allowedValueConstraintDefinitions = _fetcher.getConstraintsByType(pid, allowedValuesConstraintQid);
List<Statement> disallowedValueConstraintDefinitions = _fetcher.getConstraintsByType(pid, disallowedValuesConstraintQid);
Set<Value> allowedValues = null, disallowedValues = null;
if (!allowedValueConstraintDefinitions.isEmpty()) {
AllowedValueConstraint constraint = new AllowedValueConstraint(allowedValueConstraintDefinitions.get(0));
allowedValues = constraint.allowedValues;
}
if (!disallowedValueConstraintDefinitions.isEmpty()) {
DisallowedValueConstraint constraint = new DisallowedValueConstraint(disallowedValueConstraintDefinitions.get(0));
disallowedValues = constraint.disallowedValues;
}
if ((allowedValues != null && !allowedValues.contains(value)) || (disallowedValues != null && disallowedValues.contains(value))) {
QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_value_entity", value);
issue.setProperty("example_subject_entity", entityId);
addIssue(issue);
}
}
use of org.wikidata.wdtk.datamodel.interfaces.EntityIdValue in project OpenRefine by OpenRefine.
the class WbEntityDocumentExpr method evaluate.
@Override
public TermedStatementEntityEdit evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
EntityIdValue subjectId = getSubject().evaluate(ctxt);
TermedStatementEntityEditBuilder update = new TermedStatementEntityEditBuilder(subjectId);
for (WbStatementGroupExpr expr : getStatementGroups()) {
try {
StatementGroupEdit statementGroupUpdate = expr.evaluate(ctxt, subjectId);
// TODO also store statement groups in TermedStatementEntityUpdate?
for (StatementEdit s : statementGroupUpdate.getStatementEdits()) {
update.addStatement(s);
}
} catch (SkipSchemaExpressionException e) {
continue;
}
}
for (WbNameDescExpr expr : getNameDescs()) {
expr.contributeTo(update, ctxt);
}
return update.build();
}
use of org.wikidata.wdtk.datamodel.interfaces.EntityIdValue in project OpenRefine by OpenRefine.
the class ConstraintFetcher method getConstraintStatements.
/**
* Gets all the constraint statements for a given property
*
* @param pid
* the id of the property to retrieve the constraints for
* @return the list of constraint statements
*/
private List<Statement> getConstraintStatements(PropertyIdValue pid) {
PropertyDocument doc = (PropertyDocument) entityCache.get(pid);
StatementGroup group = doc.findStatementGroup(wikibaseConstraintPid);
if (group != null) {
return group.getStatements().stream().filter(s -> s.getValue() != null && s.getValue() instanceof EntityIdValue).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}
use of org.wikidata.wdtk.datamodel.interfaces.EntityIdValue in project OpenRefine by OpenRefine.
the class InverseConstraintScrutinizer method batchIsFinished.
@Override
public void batchIsFinished() {
// For each pair of inverse properties (in each direction)
for (Entry<PropertyIdValue, PropertyIdValue> propertyPair : _inverse.entrySet()) {
// Get the statements made for the first
PropertyIdValue ourProperty = propertyPair.getKey();
for (Entry<EntityIdValue, Set<EntityIdValue>> itemLinks : _statements.get(ourProperty).entrySet()) {
// For each outgoing link
for (EntityIdValue idValue : itemLinks.getValue()) {
// Check that they are in the statements made for the second
PropertyIdValue missingProperty = propertyPair.getValue();
Set<EntityIdValue> reciprocalLinks = _statements.get(missingProperty).get(idValue);
if (reciprocalLinks == null || !reciprocalLinks.contains(itemLinks.getKey())) {
QAWarning issue = new QAWarning(type, ourProperty.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("added_property_entity", ourProperty);
issue.setProperty("inverse_property_entity", missingProperty);
issue.setProperty("source_entity", itemLinks.getKey());
issue.setProperty("target_entity", idValue);
addIssue(issue);
}
}
}
}
}
Aggregations