Search in sources :

Example 11 with SnakGroup

use of org.wikidata.wdtk.datamodel.interfaces.SnakGroup in project OpenRefine by OpenRefine.

the class RestrictedPositionScrutinizerTest method testNoProblem.

@Test
public void testNoProblem() {
    ItemIdValue idA = TestingData.existingId;
    Snak mainSnak = Datamodel.makeSomeValueSnak(propertyIdValue);
    Statement statement = new StatementImpl("P22", mainSnak, idA);
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(idA).addStatement(add(statement)).build();
    Snak qualifierSnak = Datamodel.makeValueSnak(propertyScopeParameter, asMainSnak);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(qualifierSnak);
    List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(propertyIdValue, SCOPE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(update);
    assertNoWarningRaised();
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) StatementImpl(org.wikidata.wdtk.datamodel.implementation.StatementImpl) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Test(org.testng.annotations.Test)

Example 12 with SnakGroup

use of org.wikidata.wdtk.datamodel.interfaces.SnakGroup in project OpenRefine by OpenRefine.

the class RestrictedPositionScrutinizerTest method testTriggerMainSnak.

@Test
public void testTriggerMainSnak() {
    ItemIdValue idA = TestingData.existingId;
    Snak mainSnak = Datamodel.makeSomeValueSnak(propertyIdValue);
    Statement statement = new StatementImpl("P22", mainSnak, idA);
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(idA).addStatement(add(statement)).build();
    Snak qualifierSnak = Datamodel.makeValueSnak(propertyScopeParameter, asQualifier);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(qualifierSnak);
    List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(propertyIdValue, SCOPE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(update);
    assertWarningsRaised("property-found-in-mainsnak");
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) StatementImpl(org.wikidata.wdtk.datamodel.implementation.StatementImpl) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Test(org.testng.annotations.Test)

Example 13 with SnakGroup

use of org.wikidata.wdtk.datamodel.interfaces.SnakGroup in project OpenRefine by OpenRefine.

the class RestrictedPositionScrutinizerTest method testTriggerReference.

@Test
public void testTriggerReference() {
    ItemIdValue idA = TestingData.existingId;
    Snak snak = Datamodel.makeValueSnak(propertyIdValue, idA);
    List<SnakGroup> snakGroups = Collections.singletonList(Datamodel.makeSnakGroup(Collections.singletonList(snak)));
    Statement statement = Datamodel.makeStatement(TestingData.generateStatement(idA, propertyIdValue, idA).getClaim(), Collections.singletonList(Datamodel.makeReference(snakGroups)), StatementRank.NORMAL, "");
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(idA).addStatement(add(statement)).build();
    Snak qualifierSnak = Datamodel.makeValueSnak(propertyScopeParameter, asMainSnak);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(qualifierSnak);
    List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(propertyIdValue, SCOPE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(update);
    assertWarningsRaised("property-found-in-reference");
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Test(org.testng.annotations.Test)

Example 14 with SnakGroup

use of org.wikidata.wdtk.datamodel.interfaces.SnakGroup in project OpenRefine by OpenRefine.

the class UseAsQualifierScrutinizerTest method testNoIssue.

@Test
public void testNoIssue() {
    ItemIdValue id = TestingData.existingId;
    Snak statementQualifier = Datamodel.makeValueSnak(qualifierPropertyValue, qualifierAllowedValue);
    List<SnakGroup> qualifierList = makeSnakGroupList(statementQualifier);
    List<Statement> statementList = constraintParameterStatementList(useAsQualifierEntityId, qualifierList);
    Statement statement = statementList.get(0);
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(id).addStatement(add(statement)).build();
    Snak qualifierSnak1 = Datamodel.makeValueSnak(qualifierPID, qualifierPropertyValue);
    Snak qualifierSnak2 = Datamodel.makeValueSnak(itemParameterPID, qualifierAllowedValue);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(qualifierSnak1, qualifierSnak2);
    List<Statement> constraintDefinitions = constraintParameterStatementList(useAsQualifierEntityId, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(any(), eq(ONE_OF_QUALIFIER_VALUE_PROPERTY_QID))).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(update);
    assertNoWarningRaised();
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Test(org.testng.annotations.Test)

Example 15 with SnakGroup

use of org.wikidata.wdtk.datamodel.interfaces.SnakGroup in project OpenRefine by OpenRefine.

the class UseAsQualifierScrutinizerTest method testNoQualifier.

@Test
public void testNoQualifier() {
    ItemIdValue id = TestingData.existingId;
    List<Statement> statementList = constraintParameterStatementList(useAsQualifierEntityId, new ArrayList<>());
    Statement statement = statementList.get(0);
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(id).addStatement(add(statement)).build();
    Snak qualifierSnak1 = Datamodel.makeValueSnak(qualifierPID, qualifierPropertyValue);
    Snak qualifierSnak2 = Datamodel.makeValueSnak(itemParameterPID, qualifierAllowedValue);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(qualifierSnak1, qualifierSnak2);
    List<Statement> constraintDefinitions = constraintParameterStatementList(useAsQualifierEntityId, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(any(), eq(ONE_OF_QUALIFIER_VALUE_PROPERTY_QID))).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(update);
    assertNoWarningRaised();
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Test(org.testng.annotations.Test)

Aggregations

SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)49 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)48 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)41 Test (org.testng.annotations.Test)38 ConstraintFetcher (org.openrefine.wikidata.qa.ConstraintFetcher)36 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)34 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)34 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)32 StatementImpl (org.wikidata.wdtk.datamodel.implementation.StatementImpl)28 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)17 ArrayList (java.util.ArrayList)10 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)8 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)7 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)7 NoValueSnak (org.wikidata.wdtk.datamodel.interfaces.NoValueSnak)6 List (java.util.List)5 HashMap (java.util.HashMap)4 QAWarning (org.openrefine.wikidata.qa.QAWarning)4 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)4 Value (org.wikidata.wdtk.datamodel.interfaces.Value)4