use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class SnakOnlyStatementMerger method merge.
@Override
public Statement merge(Statement existing, Statement added) {
List<SnakGroup> existingQualifiers = existing.getQualifiers();
List<SnakGroup> addedQualifiers = added.getQualifiers();
// flatten snak groups
List<Snak> existingSnaks = flatten(existingQualifiers);
List<Snak> addedSnaks = flatten(addedQualifiers);
List<Snak> mergedSnaks = new ArrayList<>(existingSnaks);
for (Snak addedSnak : addedSnaks) {
boolean matchingSnakFound = mergedSnaks.stream().anyMatch(existingSnak -> match(existingSnak, addedSnak));
if (!matchingSnakFound) {
mergedSnaks.add(addedSnak);
}
}
List<SnakGroup> groupedQualifiers = WbStatementExpr.groupSnaks(mergedSnaks);
Claim newClaim = Datamodel.makeClaim(existing.getSubject(), existing.getMainSnak(), groupedQualifiers);
List<Reference> references = mergeReferences(existing.getReferences(), added.getReferences());
return Datamodel.makeStatement(newClaim, references, existing.getRank(), existing.getStatementId());
}
use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class QuickStatementsExporter method translateStatement.
protected void translateStatement(String qid, Statement statement, String pid, boolean add, Writer writer) throws IOException {
Claim claim = statement.getClaim();
Snak mainSnak = claim.getMainSnak();
String mainSnakQS = mainSnak.accept(mainSnakPrinter);
if (!add) {
// According to: https://www.wikidata.org/wiki/Help:QuickStatements#Removing_statements,
// Removing statements won't be followed by qualifiers or references.
writer.write("- ");
writer.write(qid + mainSnakQS);
writer.write("\n");
} else {
// add statements
if (statement.getReferences().isEmpty()) {
writer.write(qid + mainSnakQS);
for (SnakGroup q : claim.getQualifiers()) {
translateSnakGroup(q, false, writer);
}
writer.write("\n");
} else {
// So, to handle multiple references, we can duplicate the statement just with different references.
for (Reference r : statement.getReferences()) {
writer.write(qid + mainSnakQS);
for (SnakGroup q : claim.getQualifiers()) {
translateSnakGroup(q, false, writer);
}
for (SnakGroup g : r.getSnakGroups()) {
translateSnakGroup(g, true, writer);
}
writer.write("\n");
}
}
}
}
Aggregations