Search in sources :

Example 1 with TimeValueImpl

use of org.wikidata.wdtk.datamodel.implementation.TimeValueImpl in project OpenRefine by OpenRefine.

the class DifferenceWithinScrutinizerTest method testTrigger.

@Test
public void testTrigger() {
    ItemIdValue idA = TestingData.existingId;
    TimeValue lowerYear = new TimeValueImpl(1800, (byte) 10, (byte) 15, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, TimeValue.CM_GREGORIAN_PRO);
    TimeValue upperYear = new TimeValueImpl(2020, (byte) 10, (byte) 15, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, TimeValue.CM_GREGORIAN_PRO);
    ValueSnak value1 = Datamodel.makeValueSnak(lowerBoundPid, lowerYear);
    ValueSnak value2 = Datamodel.makeValueSnak(upperBoundPid, upperYear);
    Statement statement1 = new StatementImpl("P569", value1, idA);
    Statement statement2 = new StatementImpl("P570", value2, idA);
    TermedStatementEntityEdit updateA = new TermedStatementEntityEditBuilder(idA).addStatement(add(statement1)).addStatement(add(statement2)).build();
    Snak propertyQualifier = Datamodel.makeValueSnak(propertyParameterPID, lowerBoundPid);
    Snak minValueQualifier = Datamodel.makeValueSnak(minimumValuePID, minValue);
    Snak maxValueQualifier = Datamodel.makeValueSnak(maximumValuePID, maxValue);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(propertyQualifier, minValueQualifier, maxValueQualifier);
    List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(upperBoundPid, DIFFERENCE_WITHIN_RANGE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(updateA);
    assertWarningsRaised(DifferenceWithinRangeScrutinizer.type);
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) StatementImpl(org.wikidata.wdtk.datamodel.implementation.StatementImpl) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TimeValueImpl(org.wikidata.wdtk.datamodel.implementation.TimeValueImpl) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) TimeValue(org.wikidata.wdtk.datamodel.interfaces.TimeValue) Test(org.testng.annotations.Test)

Example 2 with TimeValueImpl

use of org.wikidata.wdtk.datamodel.implementation.TimeValueImpl in project OpenRefine by OpenRefine.

the class DifferenceWithinScrutinizerTest method testNoIssue.

@Test
public void testNoIssue() {
    ItemIdValue idA = TestingData.existingId;
    TimeValue lowerYear = new TimeValueImpl(2000, (byte) 10, (byte) 15, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, TimeValue.CM_GREGORIAN_PRO);
    TimeValue upperYear = new TimeValueImpl(2020, (byte) 10, (byte) 15, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, TimeValue.CM_GREGORIAN_PRO);
    ValueSnak value1 = Datamodel.makeValueSnak(lowerBoundPid, lowerYear);
    ValueSnak value2 = Datamodel.makeValueSnak(upperBoundPid, upperYear);
    Statement statement1 = new StatementImpl("P569", value1, idA);
    Statement statement2 = new StatementImpl("P570", value2, idA);
    TermedStatementEntityEdit updateA = new TermedStatementEntityEditBuilder(idA).addStatement(add(statement1)).addStatement(add(statement2)).build();
    Snak propertyQualifier = Datamodel.makeValueSnak(propertyParameterPID, lowerBoundPid);
    Snak minValueQualifier = Datamodel.makeValueSnak(minimumValuePID, minValue);
    Snak maxValueQualifier = Datamodel.makeValueSnak(maximumValuePID, maxValue);
    List<SnakGroup> constraintQualifiers = makeSnakGroupList(propertyQualifier, minValueQualifier, maxValueQualifier);
    List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
    ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
    when(fetcher.getConstraintsByType(upperBoundPid, DIFFERENCE_WITHIN_RANGE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
    setFetcher(fetcher);
    scrutinize(updateA);
    assertNoWarningRaised();
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) ConstraintFetcher(org.openrefine.wikidata.qa.ConstraintFetcher) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) StatementImpl(org.wikidata.wdtk.datamodel.implementation.StatementImpl) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TimeValueImpl(org.wikidata.wdtk.datamodel.implementation.TimeValueImpl) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) TimeValue(org.wikidata.wdtk.datamodel.interfaces.TimeValue) Test(org.testng.annotations.Test)

Aggregations

ConstraintFetcher (org.openrefine.wikidata.qa.ConstraintFetcher)2 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)2 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)2 Test (org.testng.annotations.Test)2 StatementImpl (org.wikidata.wdtk.datamodel.implementation.StatementImpl)2 TimeValueImpl (org.wikidata.wdtk.datamodel.implementation.TimeValueImpl)2 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)2 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)2 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)2 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)2 TimeValue (org.wikidata.wdtk.datamodel.interfaces.TimeValue)2 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)2