Search in sources :

Example 6 with Reference

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);
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with Reference

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, "")));
}
Also used : Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) Test(org.testng.annotations.Test)

Example 8 with Reference

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;
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim)

Example 9 with Reference

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));
}
Also used : Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 10 with Reference

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;
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) IntStream(java.util.stream.IntStream) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Set(java.util.Set) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) OptionalInt(java.util.OptionalInt) Collectors(java.util.stream.Collectors) SomeValueSnak(org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) List(java.util.List) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) Datamodel(org.wikidata.wdtk.datamodel.helpers.Datamodel) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) Optional(java.util.Optional) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) NoValueSnak(org.wikidata.wdtk.datamodel.interfaces.NoValueSnak) Collections(java.util.Collections) Value(org.wikidata.wdtk.datamodel.interfaces.Value) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) ArrayList(java.util.ArrayList) OptionalInt(java.util.OptionalInt) HashSet(java.util.HashSet)

Aggregations

Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)12 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)7 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)6 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)6 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)5 ArrayList (java.util.ArrayList)4 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)4 HashSet (java.util.HashSet)2 QAWarning (org.openrefine.wikidata.qa.QAWarning)2 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)2 Test (org.testng.annotations.Test)2 NoValueSnak (org.wikidata.wdtk.datamodel.interfaces.NoValueSnak)2 SomeValueSnak (org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak)2 Value (org.wikidata.wdtk.datamodel.interfaces.Value)2 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1