use of org.openrefine.wikidata.updates.StatementEdit 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.openrefine.wikidata.updates.StatementEdit 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.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class WbStatementExpr method evaluate.
public StatementEdit evaluate(ExpressionContext ctxt, EntityIdValue subject, PropertyIdValue propertyId) throws SkipSchemaExpressionException {
Snak mainSnak = null;
if (mainSnakValueExpr != null) {
Value mainSnakValue = mainSnakValueExpr.evaluate(ctxt);
mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
} else {
// hack to make sure we have a non-null snak
mainSnak = Datamodel.makeNoValueSnak(propertyId);
}
// evaluate qualifiers
List<Snak> qualifiers = new ArrayList<Snak>(getQualifiers().size());
for (WbSnakExpr qExpr : getQualifiers()) {
try {
qualifiers.add(qExpr.evaluate(ctxt));
} catch (SkipSchemaExpressionException e) {
QAWarning warning = new QAWarning("ignored-qualifiers", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_entity", subject);
warning.setProperty("example_property_entity", mainSnak.getPropertyId());
ctxt.addWarning(warning);
}
}
List<SnakGroup> groupedQualifiers = groupSnaks(qualifiers);
Claim claim = Datamodel.makeClaim(subject, mainSnak, groupedQualifiers);
// evaluate references
List<Reference> references = new ArrayList<Reference>();
for (WbReferenceExpr rExpr : getReferences()) {
try {
references.add(rExpr.evaluate(ctxt));
} catch (SkipSchemaExpressionException e) {
QAWarning warning = new QAWarning("ignored-references", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_entity", subject);
warning.setProperty("example_property_entity", mainSnak.getPropertyId());
ctxt.addWarning(warning);
}
}
StatementRank rank = StatementRank.NORMAL;
return new StatementEdit(Datamodel.makeStatement(claim, references, rank, ""), merger, mode);
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testNoValue.
@Test
public void testNoValue() throws IOException {
PropertyIdValue pid = Datamodel.makeWikidataPropertyIdValue("P123");
Claim claim = Datamodel.makeClaim(qid1, Datamodel.makeNoValueSnak(pid), Collections.emptyList());
Statement statement = Datamodel.makeStatement(claim, Collections.emptyList(), StatementRank.NORMAL, "");
StatementEdit statementUpdate = new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE);
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(statementUpdate).build();
assertEquals("Q1377\tP123\tnovalue\n", export(update));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testSomeValue.
@Test
public void testSomeValue() throws IOException {
PropertyIdValue pid = Datamodel.makeWikidataPropertyIdValue("P123");
Claim claim = Datamodel.makeClaim(qid1, Datamodel.makeSomeValueSnak(pid), Collections.emptyList());
Statement statement = Datamodel.makeStatement(claim, Collections.emptyList(), StatementRank.NORMAL, "");
StatementEdit statementUpdate = new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE);
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(statementUpdate).build();
assertEquals("Q1377\tP123\tsomevalue\n", export(update));
}
Aggregations