use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class ConstraintTest method setUp.
@BeforeMethod
public void setUp() {
Snak qualifierSnak1 = Datamodel.makeValueSnak(constraintException, exceptionValue);
List<Snak> qualifierSnakList1 = Collections.singletonList(qualifierSnak1);
Snak qualifierSnak2 = Datamodel.makeValueSnak(constraintStatus, statusValue);
List<Snak> qualifierSnakList2 = Collections.singletonList(qualifierSnak2);
SnakGroup qualifier1 = Datamodel.makeSnakGroup(qualifierSnakList1);
SnakGroup qualifier2 = Datamodel.makeSnakGroup(qualifierSnakList2);
List<SnakGroup> snakGroupList = Arrays.asList(qualifier1, qualifier2);
PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2302");
Snak mainSnak = Datamodel.makeValueSnak(propertyIdValue, itemIdValue);
Claim claim = Datamodel.makeClaim(itemIdValue, mainSnak, snakGroupList);
Reference reference = Datamodel.makeReference(snakGroupList);
List<Reference> referenceList = Collections.singletonList(reference);
statement = Datamodel.makeStatement(claim, referenceList, StatementRank.NORMAL, "P2302$77BD7FE4-C051-4776-855C-543F0CE697D0");
constraint = new Constraint(statement);
}
use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class PointerExtractorTest method testStatement.
@Test
public void testStatement() {
assertEmpty(e.extractPointers(Datamodel.makeStatement(claimNewSubject, Collections.emptyList(), StatementRank.NORMAL, "")));
assertEquals(Collections.singleton(TestingData.newIdA), e.extractPointers(Datamodel.makeStatement(claimWithNew, Collections.emptyList(), StatementRank.NORMAL, "")));
assertEquals(Collections.singleton(TestingData.newIdA), e.extractPointers(Datamodel.makeStatement(claimNewQualifier, Collections.emptyList(), StatementRank.NORMAL, "")));
Reference reference = Datamodel.makeReference(Collections.singletonList(snakGroupWithNew));
assertEquals(Collections.singleton(TestingData.newIdA), e.extractPointers(Datamodel.makeStatement(claimNewSubject, Collections.singletonList(reference), StatementRank.NORMAL, "")));
}
use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class ScrutinizerTest method constraintParameterStatementList.
public List<Statement> constraintParameterStatementList(ItemIdValue itemIdValue, List<SnakGroup> listSnakGroup) {
PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2302");
Snak snakValue = Datamodel.makeValueSnak(propertyIdValue, itemIdValue);
Claim claim = Datamodel.makeClaim(itemIdValue, snakValue, listSnakGroup);
Reference reference = Datamodel.makeReference(listSnakGroup);
List<Reference> referenceList = Collections.singletonList(reference);
Statement statement = Datamodel.makeStatement(claim, referenceList, StatementRank.NORMAL, "P2302$77BD7FE4-C051-4776-855C-543F0CE697D0");
List<Statement> statements = Collections.singletonList(statement);
return statements;
}
use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testReferences.
/**
* issue #2320
*
* A statement with different references should be duplicated, but each with a different reference.
*/
@Test
public void testReferences() throws IOException {
Statement baseStatement = TestingData.generateStatement(qid1, qid2);
Statement otherStatement = TestingData.generateStatement(qid2, qid1);
Snak snak1 = baseStatement.getClaim().getMainSnak();
Snak snak2 = otherStatement.getClaim().getMainSnak();
SnakGroup group1 = Datamodel.makeSnakGroup(Collections.singletonList(snak1));
SnakGroup group2 = Datamodel.makeSnakGroup(Collections.singletonList(snak2));
Claim claim = Datamodel.makeClaim(qid1, baseStatement.getClaim().getMainSnak(), Collections.singletonList(group2));
Reference reference1 = Datamodel.makeReference(Collections.singletonList(group1));
Reference reference2 = Datamodel.makeReference(Collections.singletonList(group2));
Statement statement = Datamodel.makeStatement(claim, Arrays.asList(reference1, reference2), 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\tP38\tQ865528\tP38\tQ1377\tS38\tQ865528\n" + "Q1377\tP38\tQ865528\tP38\tQ1377\tS38\tQ1377\n", export(update));
}
use of org.wikidata.wdtk.datamodel.interfaces.Reference in project OpenRefine by OpenRefine.
the class QualifiersStatementMerger method merge.
@Override
public Statement merge(Statement existing, Statement added) {
List<SnakGroup> finalQualifiers = new ArrayList<>(existing.getQualifiers());
for (SnakGroup addedSnakGroup : added.getQualifiers()) {
PropertyIdValue pid = addedSnakGroup.getProperty();
// otherwise:
if (!pids.contains(pid.getId())) {
OptionalInt index = IntStream.range(0, finalQualifiers.size()).filter(i -> finalQualifiers.get(i).getProperty().getId().equals(pid.getId())).findFirst();
if (index.isEmpty()) {
finalQualifiers.add(addedSnakGroup);
} else {
finalQualifiers.set(index.getAsInt(), mergeSnakGroups(finalQualifiers.get(index.getAsInt()), addedSnakGroup));
}
}
}
List<Reference> allReferences = new ArrayList<>(existing.getReferences());
Set<Reference> seenReferences = new HashSet<>(existing.getReferences());
for (Reference reference : added.getReferences()) {
if (!seenReferences.contains(reference)) {
seenReferences.add(reference);
allReferences.add(reference);
}
}
Statement merged = Datamodel.makeStatement(Datamodel.makeClaim(existing.getSubject(), existing.getMainSnak(), finalQualifiers), allReferences, existing.getRank(), existing.getStatementId());
return merged;
}
Aggregations